diff options
author | Vitiko <[email protected]> | 2022-11-08 23:12:50 -0400 |
---|---|---|
committer | Vitiko <[email protected]> | 2022-11-08 23:12:50 -0400 |
commit | d6883c2c7323641035537ba7b306808524e721db (patch) | |
tree | 67ea601f712a0a605432d58a555981a1434fda54 | |
parent | 1ba94041299ecdd054e19c1ee4178dde115af076 (diff) | |
download | bazarr-d6883c2c7323641035537ba7b306808524e721db.tar.gz bazarr-d6883c2c7323641035537ba7b306808524e721db.zip |
Subf2m Provider: improve series title matches
-rw-r--r-- | libs/subliminal_patch/providers/subf2m.py | 12 | ||||
-rw-r--r-- | tests/subliminal_patch/test_subf2m.py | 25 |
2 files changed, 21 insertions, 16 deletions
diff --git a/libs/subliminal_patch/providers/subf2m.py b/libs/subliminal_patch/providers/subf2m.py index 0fab14c98..06f2c63f1 100644 --- a/libs/subliminal_patch/providers/subf2m.py +++ b/libs/subliminal_patch/providers/subf2m.py @@ -117,7 +117,9 @@ class Subf2mProvider(Provider): provider_name = "subf2m" _movie_title_regex = re.compile(r"^(.+?)( \((\d{4})\))?$") - _tv_show_title_regex = re.compile(r"^(.+?) - (.*?) (season|series)( \((\d{4})\))?$") + _tv_show_title_regex = re.compile( + r"^(.+?) [-\(]\s?(.*?) (season|series)\)?( \((\d{4})\))?$" + ) _supported_languages = {} _supported_languages["brazillian-portuguese"] = Language("por", "BR") @@ -201,7 +203,7 @@ class Subf2mProvider(Provider): logger.debug("Movie found: %s", results[0]) return found_movie - def _search_tv_show_season(self, title, season): + def _search_tv_show_season(self, title, season, year=None): try: season_str = _SEASONS[season - 1].lower() except IndexError: @@ -225,11 +227,13 @@ class Subf2mProvider(Provider): match_season = match.group(2) # Match "complete series" titles as they usually contain season packs - if season_str == match_season or match_season == "complete": + if season_str == match_season or "complete" in match_season: + plus = 0.1 if year and str(year) in text else 0 results.append( { "href": result.get("href"), - "similarity": SequenceMatcher(None, title, match_title).ratio(), + "similarity": SequenceMatcher(None, title, match_title).ratio() + + plus, } ) diff --git a/tests/subliminal_patch/test_subf2m.py b/tests/subliminal_patch/test_subf2m.py index 5846971b3..47a823bfc 100644 --- a/tests/subliminal_patch/test_subf2m.py +++ b/tests/subliminal_patch/test_subf2m.py @@ -28,22 +28,23 @@ def test_search_movie(movies, title, year, expected_url): @pytest.mark.parametrize( - "title,season,expected_url", + "series_title,season,year,expected_url", [ - ("Breaking Bad", 1, "/subtitles/breaking-bad-first-season"), - ("House Of The Dragon", 1, "/subtitles/house-of-the-dragon-first-season"), - ("The Bear", 1, "/subtitles/the-bear-first-season"), - ("Courage the Cowardly Dog", 1, "/subtitles/courage-the-cowardly-dog"), + ("Breaking Bad", 1, None, "/subtitles/breaking-bad-first-season"), + ("House Of The Dragon", 1, None, "/subtitles/house-of-the-dragon-first-season"), + ("The Bear", 1, None, "/subtitles/the-bear-first-season"), + ("Courage the Cowardly Dog", 1, None, "/subtitles/courage-the-cowardly-dog"), + ( + "The Twilight Zone", + 2, + 1959, + "/subtitles/the-twilight-zone-the-complete-original-series", + ), ], ) -def test_search_tv_show_season(episodes, title, season, expected_url): - episode = list(episodes.values())[0] - episode.name = title - episode.series = title - episode.season = season - +def test_search_tv_show_season(series_title, season, year, expected_url): with Subf2mProvider() as provider: - result = provider._search_tv_show_season(episode.series, episode.season) + result = provider._search_tv_show_season(series_title, season, year) assert result == expected_url |