Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process(mode,path,source,target):
fileName = path
with open(path,'rt',encoding='utf-8',errors='ignore') as f:
data = f.read()
f.close()
subs = list(srt.parse(data))
for k in tqdm(subs):
text = k.content
translation = translate(text,source,target,mode)
k.content = translation
srtTranslated = srt.compose(subs)
# write the srt file translated...
with open("%s_%s_Translated.srt"%(os.path.splitext(os.path.split(path)[-1])[0],mode),'xt',encoding='utf-8',errors='ignore') as f:
f.write(data)
f.write(srtTranslated)
f.close()
modified_subs.append(srt.Subtitle(e.index,e.start,e.end,new_subtitle,e.proprietary))
elif args.regexreplace:
replacements = [
re.match(r's\/(.+)\/(.+)\/', replace)
for replace in
args.regexreplace
]
for e in subtitles:
new_subtitle = e.content
for m in replacements:
new_subtitle = re.sub(m.group(1), m.group(2), new_subtitle)
modified_subs.append(srt.Subtitle(e.index,e.start,e.end,new_subtitle,e.proprietary))
else:
modified_subs = subtitles
with open(TMPFILE,'wb') as f:
f.write(srt.compose(modified_subs).encode(args.encoding))
try:
last_end = 0.0
for entryi,entry in enumerate(subtitles):
if not fnmatch.fnmatchcase(entry.content.lower(), match_pattern):
continue
if args.between:
name = 'between'
else:
name = clean(entry.content)
filename='clip{:04} {}{}'.format(entry.index,name,EXTENSION)
path = os.path.join(args.outdir,filename)
if args.between:
start_secs = last_end + offset
end_secs = ftime(entry.start) - offset - args.endearly
duration = end_secs - start_secs
def write_file(self, fname):
if sys.version_info[0] > 2:
with open(fname or sys.stdout.fileno(), 'w', encoding=self.encoding) as f:
return f.write(srt.compose(self))
else:
with (fname and open(fname, 'w')) or sys.stdout as f:
return f.write(srt.compose(self).encode(self.encoding))
def save_subtitles(filename, subtitles):
with open(filename, 'w', encoding='utf-8') as f:
f.write(srt.compose(subtitles))
def write_file(self, fname):
if sys.version_info[0] > 2:
with open(fname or sys.stdout.fileno(), 'w', encoding=self.encoding) as f:
return f.write(srt.compose(self))
else:
with (fname and open(fname, 'w')) or sys.stdout as f:
return f.write(srt.compose(self).encode(self.encoding))