fix(subtitle): drop the XML declaration of TTML before pycaption reads it

This commit is contained in:
imSp4rky
2026-11-30 10:17:42 -07:00
parent ac7d10abb6
commit ea073209da
3 changed files with 44 additions and 1 deletions
+2
View File
@@ -824,6 +824,7 @@ class Subtitle(Track):
@staticmethod
def parse(data: bytes, codec: Subtitle.Codec) -> pycaption.CaptionSet:
"""Parse a subtitle, without the XML declaration of a TTML file, which makes bs4 warn when pycaption reads it."""
if not isinstance(data, bytes):
raise ValueError(f"Subtitle data must be parsed as bytes data, not {type(data).__name__}")
@@ -843,6 +844,7 @@ class Subtitle(Track):
caption_set = pycaption.CaptionSet(caption_lists)
elif codec == Subtitle.Codec.TimedTextMarkupLang:
text = try_ensure_utf8(data).decode("utf8")
text = re.sub(r"(?i)^[^<]*<\?xml\s[^>]*>", "", text)
text = text.replace("tt:", "")
text = re.sub(
r"tts:(?:extent|origin|padding)=(\"[^\"]*\"|'[^']*')",