From 23d9e5df7cb28dce1064a6e3a192fd41360aa3ed Mon Sep 17 00:00:00 2001 From: Luis Zurro de Cos Date: Mon, 7 Oct 2024 00:29:33 +0200 Subject: [PATCH] feat: Add Subtitulamos provider integration - mypy fixes --- subliminal/providers/subtitulamos.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/subliminal/providers/subtitulamos.py b/subliminal/providers/subtitulamos.py index 9c7c8b05..79be2ff1 100644 --- a/subliminal/providers/subtitulamos.py +++ b/subliminal/providers/subtitulamos.py @@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, cast from babelfish import Language, language_converters # type: ignore[import-untyped] +from bs4 import Tag from guessit import guessit # type: ignore[import-untyped] from requests import Session @@ -200,9 +201,16 @@ def query( subtitles = [] for sub in soup.select('.download-button:not(unavailable)'): # read the language - language = Language.fromsubtitulamos(sub.find_previous('div', class_='language-name').get_text().strip()) + if ( + sub.parent is None + or (lang_name_element := sub.find_previous('div', class_='language-name')) is None + or (version_container := sub.find_previous('div', class_='version-container')) is None + or not isinstance(version_container, Tag) + or (release_group_element := version_container.select('.version-container .text.spaced')) is None + ): + continue - version_container = sub.find_previous('div', class_='version-container') + language = Language.fromsubtitulamos(lang_name_element.get_text().strip()) hearing_impaired = False @@ -214,7 +222,7 @@ def query( hearing_impaired = True # read the release subtitle - release_group = version_container.select('.version-container .text.spaced')[0].getText() + release_group = release_group_element[0].getText() # read the subtitle url subtitle_url = self.server_url + cast(str, sub.parent.get('href', ''))