From 96f1cbb26074eeb3fd96efa85b2387e20200ec07 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Fri, 12 Jan 2024 00:30:52 +0000 Subject: [PATCH] Remove empty caption lists post-parsing in Subtitle.parse() This issue is common with Now TV where it for some reason parses into "two" languages. "en" and "eng". This results in one empty caption list, and one non empty caption list. The empty caption list tends to be first. This issue causes a multitude of snowballing problems later down the codebase like when converting to SRT it will result in "MULTI-LANGUAGE SRT" header, which most programs do not recognize, like mkvmerge, causing a mux failure. --- devine/core/tracks/subtitle.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/devine/core/tracks/subtitle.py b/devine/core/tracks/subtitle.py index e574d93..0e3fb0a 100644 --- a/devine/core/tracks/subtitle.py +++ b/devine/core/tracks/subtitle.py @@ -187,6 +187,12 @@ class Subtitle(Track): except pycaption.exceptions.CaptionReadNoCaptions: return pycaption.CaptionSet({"en": []}) + # remove empty caption lists or some code breaks, especially if it's the first list + for language in caption_set.get_languages(): + if not caption_set.get_captions(language): + # noinspection PyProtectedMember + del caption_set._captions[language] + return caption_set @staticmethod