Add support for parsing SubRip (SRT) in Subtitle.parse()

This commit is contained in:
rlaphoenix 2024-01-12 00:37:22 +00:00
parent 14ebe4ee1b
commit f4d8bc8dd0
1 changed files with 4 additions and 1 deletions

View File

@ -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)