How to use the pycaption.SRTWriter function in pycaption

To help you get started, we’ve selected a few pycaption 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 pbs / pycaption / tests / test_srt_conversion.py View on Github external
def test_srt_to_srt_conversion(self):
        caption_set = SRTReader().read(SAMPLE_SRT)
        results = SRTWriter().write(caption_set)
        self.assertTrue(isinstance(results, six.text_type))
        self.assertSRTEquals(SAMPLE_SRT, results)
github pbs / pycaption / tests / test_sami_conversion.py View on Github external
def test_sami_to_srt_conversion(self):
        caption_set = SAMIReader().read(SAMPLE_SAMI)
        results = SRTWriter().write(caption_set)
        self.assertTrue(isinstance(results, six.text_type))
        self.assertSRTEquals(SAMPLE_SRT, results)
github pbs / pycaption / tests / test_dfxp_conversion.py View on Github external
def test_dfxp_to_srt_conversion(self):
        caption_set = DFXPReader().read(SAMPLE_DFXP)
        results = SRTWriter().write(caption_set)
        self.assertTrue(isinstance(results, text_type))
        self.assertSRTEquals(SAMPLE_SRT, results)
github pbs / pycaption / tests / test_scc_conversion.py View on Github external
def _test_srt_to_scc_to_srt_conversion(self, srt_captions):
        captions_1 = SRTReader().read(srt_captions)
        scc_results = SCCWriter().write(captions_1)
        scc_captions = SCCReader().read(scc_results)
        srt_results = SRTWriter().write(scc_captions)
        captions_2 = SRTReader().read(srt_results)
        self.assertCaptionSetAlmostEquals(captions_1, captions_2,
                                          TOLERANCE_MICROSECONDS)
github CarlFK / veyepar / dj / scripts / enc.py View on Github external
if state==1:

                    if c.format_start() == \
                            transcription['end']['timestamp']:
                        c.nodes[0].content=\
                                transcription['end']['text']
                        state = 0

                    c.start -= offset
                    c.end -= offset
                    out_captions.append(c)

        transcript.set_captions(language, out_captions)

        # writer = pycaption.DFXPWriter()
        writer = pycaption.SRTWriter()

        open(sub_pathname, 'wt').write(writer.write(transcript))

        return
github raydouglass / media_management_scripts / media_management_scripts / convert.py View on Github external
ext = os.path.splitext(i)[1]
    if ext == '.srt':
        import shutil
        shutil.copy(i, o)
    elif ext in ('.ttml', '.xml', '.dfxp', '.tt'):
        # TTML
        from media_management_scripts.support.ttml2srt import convert_to_srt
        convert_to_srt(i, o)
    else:
        # VTT, SCC, etc

        from pycaption import detect_format, SRTWriter
        subtitle_str = _read_file(i)
        reader = detect_format(subtitle_str)
        if reader:
            subtitle_str = SRTWriter().write(reader().read(subtitle_str))
            with open(o, 'w') as file:
                file.write(subtitle_str)
        else:
            # Attempt to use FFMPEG
            from media_management_scripts.support.executables import ffmpeg
            from media_management_scripts.support.executables import execute_with_output
            args = [ffmpeg(), '-loglevel', 'fatal', '-y', '-i', i, '-c:s', 'srt', o]
            ret, output = execute_with_output(args)
            if ret != 0:
                raise Exception('Exception during subtitle conversion: {}'.format(output))