Comment out the correct #endif directive.
[mplayer/greg.git] / TOOLS / vobshift.py
blob180b5c486f7f68b1832be96dac8814abda712ef7
1 #!/usr/bin/env python
3 #usage:
5 # vobshift.py in.idx out.idx -8.45
7 # this will read in in.idx,shift it by 8.45 seconds back,
8 # and save it as out.idx
10 # license: i don't care ;)
13 import datetime
14 import sys
16 def tripletize(line):
17 begin = line[:11]
18 middle = line[11:23]
19 end = line[23:]
20 return (begin,middle,end)
22 def text2delta(t):
23 h = int( t[0:2] )
24 m = int( t[3:5] )
25 s = int( t[6:8] )
26 milli = int( t[9:12] )
27 return datetime.timedelta(hours=h,minutes=m,seconds=s,milliseconds=milli)
29 def delta2text(d):
30 t = str(d)
31 milli = t[8:11]
32 if len(milli) == 0: #fix for .000 seconds
33 milli = '000'
34 return '0'+t[:7]+':'+milli
36 def shift(line,seconds):
37 triplet = tripletize(line)
39 base = text2delta(triplet[1])
40 base = base + datetime.timedelta(seconds=seconds)
41 base = delta2text(base)
43 return triplet[0]+base+triplet[2]
45 INFILE =sys.argv[1]
46 OUTFILE =sys.argv[2]
47 DIFF =float(sys.argv[3])
49 o = open(OUTFILE,'wt')
52 for line in open(INFILE):
53 if line.startswith('timestamp'):
54 line = shift(line,DIFF)
56 o.write(line)
58 o.close()