From a0b77e70bc091348827c18d18eb1e66ad6e4d828 Mon Sep 17 00:00:00 2001 From: Aaron Spaulding Date: Mon, 28 Oct 2024 16:10:43 -0400 Subject: [PATCH] Add support for the WebVTT format. The underlying pysubs2 packages supports WebVTT so all this does is allows "vtt" subs to be passed through both for reading and writing. --- ffsubsync/generic_subtitles.py | 4 ++-- ffsubsync/subtitle_parser.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ffsubsync/generic_subtitles.py b/ffsubsync/generic_subtitles.py index 3e4b1ed..2dcf433 100644 --- a/ffsubsync/generic_subtitles.py +++ b/ffsubsync/generic_subtitles.py @@ -139,7 +139,7 @@ def write_file(self, fname: str) -> None: else: out_format = os.path.splitext(fname)[-1][1:] subs = list(self.gen_raw_resolved_subs()) - if self._sub_format in ("ssa", "ass"): + if self._sub_format in ("ssa", "ass", "vtt"): ssaf = pysubs2.SSAFile() ssaf.events = subs if self._styles is not None: @@ -149,7 +149,7 @@ def write_file(self, fname: str) -> None: if self._fonts_opaque is not None: ssaf.fonts_opaque = self._fonts_opaque to_write = ssaf.to_string(out_format) - elif self._sub_format == "srt" and out_format in ("ssa", "ass"): + elif self._sub_format == "srt" and out_format in ("ssa", "ass", "vtt"): to_write = pysubs2.SSAFile.from_string(srt.compose(subs)).to_string( out_format ) diff --git a/ffsubsync/subtitle_parser.py b/ffsubsync/subtitle_parser.py index b42d9bb..677bc18 100755 --- a/ffsubsync/subtitle_parser.py +++ b/ffsubsync/subtitle_parser.py @@ -116,7 +116,7 @@ def fit(self, fname: str, *_) -> "GenericSubtitleParser": parsed_subs = srt.parse( decoded_subs, ignore_errors=not self._strict ) - elif self.sub_format in ("ass", "ssa", "sub"): + elif self.sub_format in ("ass", "ssa", "sub", "vtt"): parsed_subs = pysubs2.SSAFile.from_string(decoded_subs) else: raise NotImplementedError(