Skip to content

Commit

Permalink
add rumble hack for verticle spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed May 20, 2023
1 parent b574f2b commit e926a5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/video_subtitles/convert_to_webvtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 3 additions & 0 deletions tests/test_srt_to_webvtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand All @@ -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__":
Expand Down

0 comments on commit e926a5e

Please sign in to comment.