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.
This commit is contained in:
rlaphoenix 2024-01-12 00:30:52 +00:00
parent 9683c34337
commit 96f1cbb260
1 changed files with 6 additions and 0 deletions

View File

@ -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