forked from kenzuya/unshackle
fix(subtitle): drop the XML declaration of TTML before pycaption reads it
This commit is contained in:
@@ -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)=(\"[^\"]*\"|'[^']*')",
|
||||
|
||||
Reference in New Issue
Block a user