Skip to content

Commit 17778f7

Browse files
authored
Improved subf2m privider to fall back to IMDB id search when localized movie title finds nothing
1 parent d41d563 commit 17778f7

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

custom_libs/subliminal_patch/providers/subf2m.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ def list_subtitles(self, video, languages):
376376
paths = self._search_tv_show_season(video.series, video.season, video.year)
377377
else:
378378
paths = self._search_movie(video.title, video.year)
379+
if not paths and video.imdb_id:
380+
# video.title may be a localized title that subf2m doesn't index
381+
# (e.g. Radarr providing a non-English title). subf2m's
382+
# searchbytitle also accepts an IMDB id, so fall back to it.
383+
logger.debug(
384+
"No results for title %r; retrying search with IMDB id %s",
385+
video.title,
386+
video.imdb_id,
387+
)
388+
paths = self._search_movie(video.imdb_id, video.year)
379389

380390
if not paths:
381391
logger.debug("No results")

tests/subliminal_patch/test_subf2m.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from subliminal_patch.core import Episode
3+
from subliminal_patch.core import Movie
34
from subliminal_patch.providers import subf2m
45
from subliminal_patch.providers.subf2m import ConfigurationError
56
from subliminal_patch.providers.subf2m import Subf2mProvider
@@ -32,6 +33,20 @@ def test_search_movie(provider, title, year, expected_url):
3233
assert expected_url in result
3334

3435

36+
def test_list_subtitles_movie_falls_back_to_imdb_id(provider):
37+
# Radarr may provide a localized movie title that subf2m doesn't index
38+
# (here the Danish title for "The Goonies"). The provider should fall back
39+
# to searching by IMDB id rather than finding nothing. Regression for #2896.
40+
movie = Movie(
41+
"Goonierne.1985.1080p.BluRay.x264-GROUP",
42+
"Goonierne",
43+
year=1985,
44+
imdb_id="tt0089218",
45+
)
46+
subtitles = provider.list_subtitles(movie, {Language.fromalpha2("en")})
47+
assert subtitles
48+
49+
3550
def test_init_empty_user_agent_raises_configurationerror():
3651
with pytest.raises(ConfigurationError):
3752
with Subf2mProvider(user_agent=" ") as provider:

0 commit comments

Comments
 (0)