def write_captions(content, options): writer_kwargs = { 'video_width': int(options.video_width) if options.video_width else None, # noqa 'video_height': int(options.video_height) if options.video_height else None # noqa } if options.sami: print( pycaption.SAMIWriter( **writer_kwargs).write(content).encode("utf-8")) # noqa if options.dfxp: print( pycaption.DFXPWriter( **writer_kwargs).write(content).encode("utf-8")) #noqa if options.srt: print( pycaption.SRTWriter( **writer_kwargs).write(content).encode("utf-8")) # noqa if options.transcript: print( pycaption.TranscriptWriter( **writer_kwargs).write(content).encode("utf-8")) # noqa if options.vtt: print( pycaption.WebVTTWriter( **writer_kwargs).write(content).encode("utf-8")) # noqa if options.unpositioned_dfxp: print( pycaption.dfxp.SinglePositioningDFXPWriter( **writer_kwargs).write(content).encode("utf-8"))
def write_captions(content, options): if options.scc: print pycaption.SCCWriter().write(content).encode("utf-8") if options.sami: print pycaption.SAMIWriter().write(content).encode("utf-8") if options.dfxp: print pycaption.DFXPWriter().write(content).encode("utf-8") if options.srt: print pycaption.SRTWriter().write(content).encode("utf-8") if options.transcript: print pycaption.TranscriptWriter().write(content).encode("utf-8")
def write_captions(content, options, lang='', filename=''): if options.sami: print pycaption.SAMIWriter().write(content).encode("utf-8") if options.dfxp: print pycaption.DFXPWriter().write(content).encode("utf-8") if options.webvtt: location = os.getcwd() f = open(location + '/captions/' + filename + '_' + lang + '.vtt', 'w') #Save vtt files into captions folder f.write(pycaption.WebVTTWriter().write(content, lang).encode("utf-8")) # print pycaption.WebVTTWriter().write(content, lang).encode("utf-8") if options.srt: print pycaption.SRTWriter().write(content).encode("utf-8") if options.transcript: print pycaption.TranscriptWriter().write(content).encode("utf-8")
def write_captions(content, options): if options.scc: print(pycaption.SCCWriter().write(content)) if options.sami: print(pycaption.SAMIWriter().write(content)) if options.dfxp: print(pycaption.DFXPWriter().write(content)) if options.srt: print(pycaption.SRTWriter().write(content)) if options.vtt: print(pycaption.WebVTTWriter().write(content)) if options.transcript: # import TranscriptWriter only if necessary, since it requires additional dependencies from pycaption.transcript import TranscriptWriter print(TranscriptWriter().write(content))
def run(self): for input_file in self.input_files: input_file_name = os.path.basename(input_file) input_type = os.path.splitext(input_file)[1].lower()[1:] output_file = os.path.join( self.output_folder, os.path.splitext(input_file_name)[0] + '.' + self.output_type) output_file_name = os.path.basename(output_file) if os.path.exists(output_file) and not self.overwrite_on: self.log_signal.emit("{}을 건너뜁니다...".format(input_file_name)) continue self.log_signal.emit("{}을 읽습니다...".format(input_file_name)) with open(output_file, 'w', encoding=self.output_encoding) as file_out: reader = None encoding = None content = None with open(input_file, 'rb') as file_in: encoding = chardet.detect(file_in.read())['encoding'] with open(input_file, 'r', encoding=encoding) as file_in: content = file_in.read() if input_type == "smi": reader = pycaption.SAMIReader().read(content) elif input_type == "srt": reader = pycaption.SRTReader().read(content) if self.output_type == "smi": file_out.write(pycaption.SAMIWriter().write(reader)) elif self.output_type == "srt": file_out.write(pycaption.SRTWriter().write(reader)) elif self.output_type == "txt": file_out.write(TextWriter().write(reader)) elif self.output_type == "ats": open(output_file, 'wb').write(AtsWriter().write(reader)) self.log_signal.emit("{}으로 변환했습니다".format(output_file_name))