summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVitiko <[email protected]>2023-06-18 17:18:49 -0400
committerVitiko <[email protected]>2023-06-18 17:18:49 -0400
commit4921c55bf05189f68bdd6279b957eaffd00e7cf0 (patch)
treecc44ae944534c1c8c0600c26be487b95de72d9fe
parent374e4bec87c4581c4bb07e7fe528123ffa6998d4 (diff)
downloadbazarr-4921c55bf05189f68bdd6279b957eaffd00e7cf0.tar.gz
bazarr-4921c55bf05189f68bdd6279b957eaffd00e7cf0.zip
Subf2m provider: improve episode matchingv1.2.2-beta.21
-rw-r--r--libs/subliminal_patch/providers/subf2m.py20
-rw-r--r--tests/subliminal_patch/test_subf2m.py25
2 files changed, 37 insertions, 8 deletions
diff --git a/libs/subliminal_patch/providers/subf2m.py b/libs/subliminal_patch/providers/subf2m.py
index ac0daafc2..6b3a59129 100644
--- a/libs/subliminal_patch/providers/subf2m.py
+++ b/libs/subliminal_patch/providers/subf2m.py
@@ -136,6 +136,7 @@ class Subf2mProvider(Provider):
_tv_show_title_regex = re.compile(
r"^(.+?) [-\(]\s?(.*?) (season|series)\)?( \((\d{4})\))?$"
)
+ _tv_show_title_alt_regex = re.compile(r"(.+)\s(\d{1,2})(?:\s|$)")
_supported_languages = {}
_supported_languages["brazillian-portuguese"] = Language("por", "BR")
@@ -188,7 +189,7 @@ class Subf2mProvider(Provider):
# Sometimes subf2m will return 404 or 503. This error usually disappears
# retrying the query
if req.status_code in (404, 503):
- logger.debug("503 returned. Trying again [%d] in 3 seconds", n + 1)
+ logger.debug("503/404 returned. Trying again [%d] in 3 seconds", n + 1)
time.sleep(3)
continue
else:
@@ -246,7 +247,7 @@ class Subf2mProvider(Provider):
def _search_tv_show_season(self, title, season, year=None, return_len=3):
try:
- season_str = _SEASONS[season - 1].lower()
+ season_strs = (_SEASONS[season - 1].lower(), str(season))
except IndexError:
logger.debug("Season number not supported: %s", season)
return None
@@ -257,16 +258,17 @@ class Subf2mProvider(Provider):
match = self._tv_show_title_regex.match(text)
if not match:
+ match = self._tv_show_title_alt_regex.match(text)
+
+ if not match:
logger.debug("Series title not matched: %s", text)
continue
- else:
- logger.debug("Series title matched: %s", text)
- match_title = match.group(1)
- match_season = match.group(2)
+ match_title = match.group(1).strip()
+ match_season = match.group(2).strip().lower()
- # Match "complete series" titles as they usually contain season packs
- if season_str == match_season or "complete" in match_season:
+ if match_season in season_strs or "complete" in match_season:
+ logger.debug("OK: '%s' IN %s|complete", match_season, season_strs)
plus = 0.1 if year and str(year) in text else 0
results.append(
{
@@ -275,6 +277,8 @@ class Subf2mProvider(Provider):
+ plus,
}
)
+ else:
+ logger.debug("Invalid: '%s' IN %s|complete", match_season, season_strs)
if results:
results.sort(key=lambda x: x["similarity"], reverse=True)
diff --git a/tests/subliminal_patch/test_subf2m.py b/tests/subliminal_patch/test_subf2m.py
index 2df17af2d..e8369d2fa 100644
--- a/tests/subliminal_patch/test_subf2m.py
+++ b/tests/subliminal_patch/test_subf2m.py
@@ -1,4 +1,5 @@
import pytest
+from subliminal_patch.core import Episode
from subliminal_patch.providers import subf2m
from subliminal_patch.providers.subf2m import ConfigurationError
from subliminal_patch.providers.subf2m import Subf2mProvider
@@ -208,3 +209,27 @@ def test_get_episode_from_release_return_none():
def test_get_episode_from_release_w_empty_match_return_none():
assert subf2m._get_episode_from_release("Vinland Saga - 02") is None
+
+
+def test_complex_episode_name(provider):
+ episode = Episode(
+ **{
+ "name": "Dr.Romantic.S03E16.SBS.x265.1080p-thon.mkv",
+ "source": "HDTV",
+ "release_group": "thon",
+ "resolution": "1080p",
+ "video_codec": "H.265",
+ "audio_codec": "AAC",
+ "subtitle_languages": set(),
+ "original_name": "Dr. Romantic - S03E16.mkv",
+ "other": None,
+ "series": "Dr. Romantic",
+ "season": 3,
+ "episode": 16,
+ "title": "Dreamers",
+ "year": 2016,
+ "series_imdb_id": "tt6157190",
+ "alternative_series": ["Romantic Doctor Teacher Kim"],
+ }
+ )
+ assert provider.list_subtitles(episode, {Language.fromietf("en")})