mirror of
https://github.com/devine-dl/devine.git
synced 2025-04-29 17:49:44 +00:00
Replace negative size values in TTML text with 0
Negative size values are not allowed by the spec basically anywhere in the document. Some services seem to accidentally specify a negative value which puts pycaption on a fritz.
This commit is contained in:
parent
41018d4574
commit
f4a9d6c0b1
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
@ -161,6 +162,8 @@ class Subtitle(Track):
|
|||||||
return captions
|
return captions
|
||||||
if codec == Subtitle.Codec.TimedTextMarkupLang:
|
if codec == Subtitle.Codec.TimedTextMarkupLang:
|
||||||
text = data.decode("utf8").replace("tt:", "")
|
text = data.decode("utf8").replace("tt:", "")
|
||||||
|
# negative size values aren't allowed in TTML/DFXP spec, replace with 0
|
||||||
|
text = re.sub(r'"(-\d+(\.\d+)?(px|em|%|c|pt))"', '"0"', text)
|
||||||
return pycaption.DFXPReader().read(text)
|
return pycaption.DFXPReader().read(text)
|
||||||
if codec == Subtitle.Codec.fVTT:
|
if codec == Subtitle.Codec.fVTT:
|
||||||
caption_lists: dict[str, pycaption.CaptionList] = defaultdict(pycaption.CaptionList)
|
caption_lists: dict[str, pycaption.CaptionList] = defaultdict(pycaption.CaptionList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user