-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.py
76 lines (66 loc) · 2.56 KB
/
sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
import os
import subprocess
import sys
from pymediainfo import MediaInfo
def isVideo(file):
try:
fInfo = MediaInfo.parse(file)
except:
return False
for track in fInfo.tracks:
if track.track_type == "Video":
return True
return False
def SubExist(file):
if os.path.exists(file):
return True
return False
def GetSubFileName(dir, filename, sub_lang):
for file in dir:
if isVideo(file):
continue
if filename in file and file.endswith(sub_lang + ".srt"):
return file
if filename in file and file.endswith(sub_lang + ".hi.srt"):
return file
return filename
if __name__ == "__main__":
if len(sys.argv) != 4:
print("[-] Usage: sync.py <PATH> <subtitles_lang> <audio_lang> ")
exit()
rootdir = sys.argv[1]
sub_lang = str(sys.argv[2])
audio_lang = str(sys.argv[3])
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if not file.endswith("srt") and isVideo(os.path.join(subdir,file)):
tFileName = os.path.splitext(file)
tmp = tFileName[0]
relatedSub = GetSubFileName(files, tmp, sub_lang)
if relatedSub == tmp:
print(f"[-] No sub Found. [{tmp}]")
tmp += "." + sub_lang + ".srt"
if SubExist(os.path.join(subdir,tmp)):
print("[*] Sub Found. Syncing . . .")
cmd = ["subsync-cmd.exe",
"sync",
"--sub-lang",
sub_lang,
"--ref-lang",
audio_lang,
"--sub",
os.path.join(subdir,tmp),
"--ref" ,
os.path.join(subdir,file),
"--out", os.path.join(subdir,tmp),
"--window-size=10000",
"--effort=1",
"--overwrite"]
proc = subprocess.Popen(cmd)
proc.wait()
print(f"[+] Synced.[{tmp}][{file}]")
else:
print(f"[-] Sub NOT Found. [{tmp}]")
continue
# print(f"[{os.path.join(subdir,tmp)}] [Video]")