-
Notifications
You must be signed in to change notification settings - Fork 0
/
srt.py
37 lines (34 loc) · 1.02 KB
/
srt.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
import pysubs2
from nican import nican
from tqdm import tqdm
import re
import glob
from pathlib import Path
def main(sub_file):
subs = pysubs2.load(sub_file, encoding="utf-8")
filename = sub_file.split('.')[:-1]
filename = ".".join(filename)
extension = sub_file.split('.')[-1]
extension = 'srt'
for line in tqdm(subs):
try:
line.text = re.sub(r'\\N', '', line.text)
line.text = nican(line.text)
subs.save(f"{filename}_edited.{extension}")
except Exception as e:
print(e)
pass
if __name__ == '__main__':
regexFiles = input("Insert location of subtitle: ")
globFiles = sorted(glob.glob(regexFiles))
for file in globFiles:
print(file)
if(not file.endswith('_edited.srt')):
path = Path(file)
if(path.is_file()):
print(file)
try:
main(file)
except Exception as e:
print(e)
pass