From f4d8bc8dd09fbb240ffa072d2368f804031464bd Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Fri, 12 Jan 2024 00:37:22 +0000 Subject: [PATCH] Add support for parsing SubRip (SRT) in Subtitle.parse() --- devine/core/tracks/subtitle.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/devine/core/tracks/subtitle.py b/devine/core/tracks/subtitle.py index eac1dca..c23e0e4 100644 --- a/devine/core/tracks/subtitle.py +++ b/devine/core/tracks/subtitle.py @@ -149,7 +149,10 @@ class Subtitle(Track): raise ValueError(f"Subtitle data must be parsed as bytes data, not {type(data).__name__}") try: - if codec == Subtitle.Codec.fTTML: + if codec == Subtitle.Codec.SubRip: + text = try_ensure_utf8(data).decode("utf8") + caption_set = pycaption.SRTReader().read(text) + elif codec == Subtitle.Codec.fTTML: caption_lists: dict[str, pycaption.CaptionList] = defaultdict(pycaption.CaptionList) for segment in ( Subtitle.parse(box.data, Subtitle.Codec.TimedTextMarkupLang)