From 0e1120e037febedacb7a051871e9bd4660a8a0c8 Mon Sep 17 00:00:00 2001 From: Vitiko Date: Fri, 20 May 2022 15:03:03 -0400 Subject: [PATCH] Subdivx provider: improve movie searches --- libs/subliminal_patch/providers/subdivx.py | 9 +++++---- tests/subliminal_patch/test_subdivx.py | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/subliminal_patch/providers/subdivx.py b/libs/subliminal_patch/providers/subdivx.py index bc902363e..11beeb722 100644 --- a/libs/subliminal_patch/providers/subdivx.py +++ b/libs/subliminal_patch/providers/subdivx.py @@ -109,10 +109,11 @@ class SubdivxSubtitlesProvider(Provider): ): subtitles += self._handle_multi_page_search(query, video) else: - # Subdvix has problems searching foreign movies if the year is - # appended. A proper solution would be filtering results with the - # year in self._parse_subtitles_page. - subtitles += self._handle_multi_page_search(video.title, video) + for query in (video.title, f"{video.title} ({video.year})"): + subtitles += self._handle_multi_page_search(query, video) + # Second query is a fallback + if subtitles: + break return subtitles diff --git a/tests/subliminal_patch/test_subdivx.py b/tests/subliminal_patch/test_subdivx.py index 7ce4980ce..7dc77941f 100644 --- a/tests/subliminal_patch/test_subdivx.py +++ b/tests/subliminal_patch/test_subdivx.py @@ -17,6 +17,15 @@ def test_list_subtitles_movie(movies): assert len(subtitles) >= 9 +def test_list_subtitles_movie_with_year_fallback(movies): + item = list(movies.values())[0] + item.title = "Everything Everywhere All at Once" + item.year = 2022 + + with SubdivxSubtitlesProvider() as provider: + assert provider.list_subtitles(item, {Language("spa", "MX")}) + + @pytest.mark.parametrize( "episode_key,expected", [("breaking_bad_s01e01", 15), ("inexistent", 0)] )