How to use the srt.compose function in srt

To help you get started, we’ve selected a few srt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrinflated / SrtTranslate / process.py View on Github external
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()
github foone / SplitBySubs / split_by_subs.py View on Github external
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
github smacke / subsync / subsync / subtitle_parsers.py View on Github external
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))
github HackerDom / qctf-starter-2018 / tasks / youtube-subtitles / youtube_subtitles / generation.py View on Github external
def save_subtitles(filename, subtitles):
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(srt.compose(subtitles))
github smacke / subsync / subsync / subtitle_parsers.py View on Github external
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))

srt

A tiny library for parsing, modifying, and composing SRT files.

MIT
Latest version published 2 years ago

Package Health Score

52 / 100
Full package analysis

Popular srt functions

Similar packages