From e926a5eb6a44809d9a8bf5b2b3dbf61260726e0f Mon Sep 17 00:00:00 2001 From: zackees Date: Fri, 19 May 2023 23:49:33 -0700 Subject: [PATCH] add rumble hack for verticle spacing --- src/video_subtitles/convert_to_webvtt.py | 12 ++++++++++++ tests/test_srt_to_webvtt.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/video_subtitles/convert_to_webvtt.py b/src/video_subtitles/convert_to_webvtt.py index f408308..d163339 100644 --- a/src/video_subtitles/convert_to_webvtt.py +++ b/src/video_subtitles/convert_to_webvtt.py @@ -5,9 +5,21 @@ import webvtt # pylint: disable=import-error +from video_subtitles.util import read_utf8, write_utf8 + +STYLE_ELEMENT = """STYLE +::::cue { + line: 80%; +} + +""" + def convert_to_webvtt(srt_file: str, out_webvtt_file: str) -> None: """Convert to webvtt format.""" assert srt_file.endswith(".srt") assert out_webvtt_file.endswith(".vtt") webvtt.from_srt(srt_file).save(out_webvtt_file) + content = read_utf8(out_webvtt_file) + content = content.replace("WEBVTT\n\n", f"WEBVTT\n\n{STYLE_ELEMENT}") + write_utf8(out_webvtt_file, content) diff --git a/tests/test_srt_to_webvtt.py b/tests/test_srt_to_webvtt.py index 943d565..998880a 100644 --- a/tests/test_srt_to_webvtt.py +++ b/tests/test_srt_to_webvtt.py @@ -6,6 +6,7 @@ import unittest from video_subtitles.convert_to_webvtt import convert_to_webvtt +from video_subtitles.util import read_utf8 HERE = os.path.dirname(os.path.abspath(__file__)) @@ -21,6 +22,8 @@ def test_translate(self) -> None: with tempfile.TemporaryDirectory() as tmpdirname: out_file = os.path.join(tmpdirname, "out.vtt") convert_to_webvtt(TEST_SRT, out_file) + content = read_utf8(out_file) + print(content) if __name__ == "__main__":