Fix conversion of bugged VTTs with missing styles
This commit is contained in:
parent
3c8c01df95
commit
176293bb99
@ -60,6 +60,7 @@ class NebulaSubtitle(Subtitle):
|
||||
bold = "bold" in extra
|
||||
styles[name.lower()] = {"color": color, "bold": bold}
|
||||
|
||||
|
||||
count = 1
|
||||
new_subs = []
|
||||
for caption in vtt:
|
||||
@ -68,18 +69,20 @@ class NebulaSubtitle(Subtitle):
|
||||
for tag in soup.find_all("v"):
|
||||
name = " ".join(tag.attrs.keys())
|
||||
|
||||
# Work around a few broken "Abolish Everything" subtitles
|
||||
if ((name == "spectator" and "spectator" not in styles) or
|
||||
(name == "spectators" and "spectators" not in styles)):
|
||||
name = "audience"
|
||||
# Nebula subtitles sometimes contain references to non-existent style groups, just
|
||||
# remove the tag entirely in those cases
|
||||
style = styles.get(name)
|
||||
if not style:
|
||||
tag.replaceWithChildren()
|
||||
continue
|
||||
|
||||
style = styles[name]
|
||||
tag.name = "font"
|
||||
tag.attrs = {"color": style["color"]}
|
||||
|
||||
if style["bold"]:
|
||||
tag.wrap(soup.new_tag("b"))
|
||||
|
||||
|
||||
text = str(soup)
|
||||
new_subs.append(f"{count}")
|
||||
new_subs.append(f"{caption.start} --> {caption.end}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user