1+ def convertToMilliseconds (time ):
2+ milliseconds = 0
3+ hh ,mm ,ms = time .split (":" )
4+ ms = ms .strip ().replace ("," ,"" )
5+ hh = int (hh )
6+ mm = int (mm )
7+ ms = int (ms )
8+
9+ milliseconds = hh * 3600000 + mm * 60000 + ms
10+ return milliseconds
11+
12+ def synchronize (time ,shift ):
13+ return time - shift
14+
15+ def convertToTime (milliseconds ):
16+ hh = milliseconds // 3600000
17+ milliseconds = milliseconds % 3600000
18+ hh = str (hh )
19+ if len (hh ) < 2 : hh = "0" + hh
20+
21+ mm = milliseconds // 60000
22+ milliseconds = milliseconds % 60000
23+ mm = str (mm )
24+ if len (mm ) < 2 : mm = "0" + mm
25+
26+ ss = milliseconds // 1000
27+ milliseconds = milliseconds % 1000
28+ ss = str (ss )
29+ if len (ss ) < 2 : ss = "0" + ss
30+
31+ milliseconds = str (milliseconds )
32+ while len (milliseconds ) < 3 :
33+ milliseconds = "0" + milliseconds
34+
35+ return f"{ hh } :{ mm } :{ ss } ,{ milliseconds } "
36+
37+
38+ def main ():
39+ SHIFT = int (input ("Please enter the shift in milliseconds: " ))
40+ f = open ("input.txt" , "r" , errors = "ignore" )
41+ output = open ("output.txt" ,"a" )
42+ for x in f :
43+ if "-->" in x :
44+ start ,end = x .split ("-->" )
45+ start ,end = convertToMilliseconds (start ), convertToMilliseconds (end )
46+ start ,end = synchronize (start ,SHIFT ),synchronize (end ,SHIFT )
47+ start ,end = convertToTime (start ),convertToTime (end )
48+ output .write (f"{ start } --> { end } \n " )
49+ else :
50+ output .write (x )
51+
52+
53+ #Right click the subtitles file you want to synchronize and open it in a notepad
54+ #Then copy all of its content and paste it into a new file and name it as "input.txt"
55+
56+ #You must have your "input.txt" in the same folder as this program
57+
58+ #Once you run this program you will be asked to enter a shift in milliseconds.
59+
60+ #You can find the shift when you are watching the video as it is impossible to
61+ #determine that using any program since it is variable for every video.
62+
63+ #Once the program has finished running, you will have your subtitles synchronized
64+ #in a file that says "output.txt". Copy its content and paste it into your original subtitles file.
65+ main ()
0 commit comments