dotfiles

personal dotfiles
git clone anongit@rnpnr.xyz:dotfiles.git
Log | Files | Refs | Feed | Submodules

srt-adjust (717B)


      1 #!/bin/awk -f
      2 
      3 # adjusts a provided srt file by the given time in milliseconds
      4 
      5 function usage() {
      6 	printf "usage: %s [-]time(ms) [srt ...]\n", ARGV[0]
      7 	exit(1)
      8 }
      9 
     10 function tomsecs(a) {
     11 	gsub(/,/, ":", a)
     12 	split(a, t, ":")
     13 	return (t[1] * 3600 + t[2] * 60 + t[3]) * 1000 + t[4]
     14 }
     15 
     16 function ftime(a) {
     17 	ms = a % 1000
     18 	a = (a - ms) / 1000
     19 	s = a % 60
     20 	a = (a - s) / 60
     21 	m = a % 60
     22 	h = (a - m) / 60
     23 
     24 	return sprintf("%02d:%02d:%02d,%03d", h, m, s, ms)
     25 }
     26 
     27 function bump(a, time) {
     28 	return ftime(tomsecs(a) + time)
     29 }
     30 
     31 BEGIN {
     32 	if (ARGC < 2) {
     33 		usage()
     34 	}
     35 
     36 	adj = ARGV[1]
     37 	delete ARGV[1]
     38 	FS = " --> "
     39 }
     40 
     41 !/[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9]/ {
     42 	print
     43 	next
     44 }
     45 
     46 {
     47 	printf("%s --> %s\n", bump($1, adj), bump($2, adj))
     48 }