From 176293bb993307361993c1b32f9a86abd431e230 Mon Sep 17 00:00:00 2001 From: lambda <> Date: Mon, 11 Aug 2025 01:46:38 +0200 Subject: [PATCH] Fix conversion of bugged VTTs with missing styles --- NBLA/__init__.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/NBLA/__init__.py b/NBLA/__init__.py index ce2b564..3e685fb 100644 --- a/NBLA/__init__.py +++ b/NBLA/__init__.py @@ -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}")