def setUp(self):
        test_content = StringIO(u"""1
00:00:03,490 --> 00:00:07,430
FISHER: All right. So, let's begin.
This session is: Going Social

00:00:07,430 --> 00:00:11,600
with the YouTube APIs. I am
Jeff Fisher,

2
00:00:11,600 --> 00:00:14,009
and this is Johann Hartmann,
we're presenting today.

3
00:00:14,009 --> 00:00:15,889
[pause]
""")
        self.reader = Reader(test_content)
        self.writer = Writer(StringIO())
class TestSRTWriter(unittest.TestCase):
    def setUp(self):
        test_content = StringIO(u"""1
00:00:03,490 --> 00:00:07,430
FISHER: All right. So, let's begin.
This session is: Going Social

00:00:07,430 --> 00:00:11,600
with the YouTube APIs. I am
Jeff Fisher,

2
00:00:11,600 --> 00:00:14,009
and this is Johann Hartmann,
we're presenting today.

3
00:00:14,009 --> 00:00:15,889
[pause]
""")
        self.reader = Reader(test_content)
        self.writer = Writer(StringIO())

    def test_transformtext(self):
        captions = self.reader.read()
        self.writer.captions = captions
        text = self.writer.captions_to_text()
        should_be = u"""0\n00:00:03,490 --> 00:00:07,430\nFISHER: All right. So, let's begin.\nThis session is: Going Social"""
        self.assertTrue(text.startswith(should_be),
                        "%s !startswith %s" % (text, should_be))

    def test_format_time(self):
        caption = core.Caption()
        caption.start = core.get_date(second=3, millisecond=490)
        caption.end = core.get_date(second=7, millisecond=430)
        time_info = self.writer.format_time(caption)
        self.assertEqual(time_info['start'], '00:00:03,490')
        self.assertEqual(time_info['end'], '00:00:07,430')
class TestSRTWriter(unittest.TestCase):
    def setUp(self):
        test_content = StringIO(u"""1
00:00:03,490 --> 00:00:07,430
FISHER: All right. So, let's begin.
This session is: Going Social

00:00:07,430 --> 00:00:11,600
with the YouTube APIs. I am
Jeff Fisher,

2
00:00:11,600 --> 00:00:14,009
and this is Johann Hartmann,
we're presenting today.

3
00:00:14,009 --> 00:00:15,889
[pause]
""")
        self.reader = Reader(test_content)
        self.writer = Writer(StringIO())

    def test_transformtext(self):
        captions = self.reader.read()
        self.writer.captions = captions
        text = self.writer.captions_to_text()
        should_be = u"""0\n00:00:03,490 --> 00:00:07,430\nFISHER: All right. So, let's begin.\nThis session is: Going Social"""
        self.assertTrue(text.startswith(should_be),
                        "%s !startswith %s" % (text, should_be))

    def test_format_time(self):
        caption = core.Caption()
        caption.start = core.get_date(second=3, millisecond=490)
        caption.end = core.get_date(second=7, millisecond=430)
        time_info = self.writer.format_time(caption)
        self.assertEqual(time_info['start'], '00:00:03,490')
        self.assertEqual(time_info['end'], '00:00:07,430')
    def setUp(self):
        test_content = StringIO(u"""1
00:00:03,490 --> 00:00:07,430
FISHER: All right. So, let's begin.
This session is: Going Social

00:00:07,430 --> 00:00:11,600
with the YouTube APIs. I am
Jeff Fisher,

2
00:00:11,600 --> 00:00:14,009
and this is Johann Hartmann,
we're presenting today.

3
00:00:14,009 --> 00:00:15,889
[pause]
""")
        self.reader = Reader(test_content)
        self.writer = Writer(StringIO())
Exemple #5
0
		counter = 1
		of = f'{of[:-4]}-{counter}{of[-4:]}'
		while os.path.isfile(of):
			of = f'{of[:(-5-len(str(counter - 1)))]}-{counter}{of[-4:]}'
			counter += 1

	# Convert sbv to srt to add them
	if os.path.splitext(sf)[1] == '.sbv':
		from captionstransformer.sbv import Reader
		from captionstransformer.srt import Writer

		with open(sf) as r:
			reader = Reader(r)

			with open(f'{os.path.splitext(sf)[0]}.srt', 'w') as w:
				writer = Writer(w)
				writer.set_captions(reader.read())
				writer.write()
				writer.close()

	print(f'Adding subtitles to {vf}...')

	if not args.soft_embed:
		subprocess.call(f'ffmpeg -hide_banner -loglevel warning -i "{vf}" -vf "subtitles=\'{sf}\':force_style=\'Fontsize={args.size},PrimaryColour=&H{args.color}&,BorderStyle={args.border_style}{args.additional_formatting}\'" -c:v {codec_string} -c:a copy "{of}"', cwd = os.getcwd(), shell = True)
	else:
		subprocess.call(f'ffmpeg -hide_banner -loglevel warning -i "{vf}" -i "{sf}" -c:v {codec_string} -c:a copy -c:s mov_text -disposition:s:0 default "{of}"', cwd = os.getcwd(), shell = True)

	# If the subtitle started off as sbv, try to delete the temporarily needed srt file
	# This isn't hugely important, so just pass if it fails
	if os.path.splitext(sf)[1] == '.sbv':
		try: