Embedded Subtitles provider: handle ASS errors

Fix #2168
This commit is contained in:
Vitiko 2023-06-12 18:48:46 -04:00
parent a13d69ddb2
commit 1c1caeb78b

View file

@ -14,7 +14,6 @@ from fese import FFprobeSubtitleStream
from fese import FFprobeVideoContainer
from fese import tags
from fese.exceptions import InvalidSource
from subliminal.subtitle import fix_line_ending
from subliminal_patch.core import Episode
from subliminal_patch.core import Movie
from subliminal_patch.providers import Provider
@ -187,19 +186,18 @@ class EmbeddedSubtitlesProvider(Provider):
def download_subtitle(self, subtitle: EmbeddedSubtitle):
path = self._get_subtitle_path(subtitle)
modifiers = _type_modifiers.get(subtitle.stream.codec_name)
logger.debug(
"Found modifiers for %s type: %s", subtitle.stream.codec_name, modifiers
)
modifiers = _type_modifiers.get(subtitle.stream.codec_name) or set()
logger.debug("Found modifiers for %s type: %s", subtitle.stream, modifiers)
if modifiers is not None:
for mod in modifiers:
logger.debug("Running %s modifier for %s", mod, path)
for mod in modifiers:
logger.debug("Running %s modifier for %s", mod, path)
try:
mod(path, path)
except Exception as error:
logger.debug("'%s' raised running modifier", error)
with open(path, "rb") as sub:
content = sub.read()
subtitle.content = fix_line_ending(content)
subtitle.content = sub.read()
def _get_subtitle_path(self, subtitle: EmbeddedSubtitle):
container = subtitle.container
@ -341,7 +339,7 @@ def _clean_ass_subtitles(path, output_path):
clean_lines = []
with open(path, "r") as f:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
lines = f.readlines()
for line in lines:
if _SIGNS_LINE_RE.search(line) is None: