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 main(argv): inputfile = '' inputType = '' outputType = '' try: opts, args = getopt.getopt(argv, "h:i:f:t:") except getopt.GetoptError: print('test.py -i <inputfile> -f <intputType> -t <outputType>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('test.py -i <inputfile> -f <intputType> -t <outputType>') sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg elif opt in ("-f", "--sfile"): inputType = arg elif opt in ("-t", "--tfile"): outputType = arg if inputType == outputType: print('Error: input type and output type are same format') sys.exit(1) with io.open(inputfile) as f: str1 = f.read() inputValue = inputType.lower() if inputValue == 'scc': c = pycaption.SCCReader().read(str1) elif inputValue == 'srt': c = pycaption.SRTReader().read(str1) elif inputValue == 'dfxp': c = pycaption.DFXPReader().read(str1) elif inputValue == 'webvtt': c = pycaption.WebVTTReader().read(str1) else: print('Error: invalid input type. <srt/scc/webvtt/dfxp> allowed') sys.exit(1) outputValue = outputType.lower() if outputValue == 'scc': print(pycaption.SCCWriter().write(c)) elif outputValue == 'srt': print(pycaption.SRTWriter().write(c)) elif outputValue == 'dfxp': print(pycaption.DFXPWriter().write(c)) elif outputValue == 'webvtt': print(pycaption.WebVTTWriter().write(c)) else: print('Error: invalid output type. <srt/scc/webvtt/dfxp> allowed') sys.exit(1)
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 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")