Subdivx Provider: improve episode queries

pull/1974/head v1.1.3-beta.1
Vitiko 2 years ago
parent d7c8188f94
commit 71fe2b7a1d

@ -63,6 +63,8 @@ class SubdivxSubtitle(Subtitle):
# episode # episode
if isinstance(video, Episode): if isinstance(video, Episode):
# already matched in search query # already matched in search query
# TODO: avoid false positive with some short/common titles
matches.update(["title", "series", "season", "episode", "year"]) matches.update(["title", "series", "season", "episode", "year"])
# movie # movie
@ -106,11 +108,23 @@ class SubdivxSubtitlesProvider(Provider):
subtitles = [] subtitles = []
if isinstance(video, Episode): if isinstance(video, Episode):
# TODO: cache pack queries (TV SHOW S01 / TV SHOW 2022 S01).
# Too many redundant server calls.
for query in ( for query in (
f"{video.series} S{video.season:02}E{video.episode:02}", f"{video.series} S{video.season:02}E{video.episode:02}",
f"{video.series} S{video.season:02}", f"{video.series} S{video.season:02}",
): ):
subtitles += self._handle_multi_page_search(query, video) subtitles += self._handle_multi_page_search(query, video)
# Try with year
if len(subtitles) <= 5 and video.year:
logger.debug("Few results. Trying with year")
for query in (
f"{video.series} {video.year} S{video.season:02}E{video.episode:02}",
f"{video.series} {video.year} S{video.season:02}",
):
subtitles += self._handle_multi_page_search(query, video)
else: else:
for query in (video.title, f"{video.title} ({video.year})"): for query in (video.title, f"{video.title} ({video.year})"):
subtitles += self._handle_multi_page_search(query, video) subtitles += self._handle_multi_page_search(query, video)

@ -52,6 +52,19 @@ def test_list_subtitles_castillian_spanish(episodes):
assert provider.list_subtitles(item, {Language.fromietf("es")}) assert provider.list_subtitles(item, {Language.fromietf("es")})
def test_list_subtitles_episode_with_year(episodes):
item = list(episodes.values())[0]
item.series = "The Bear"
item.name = "The Bear"
item.season = 1
item.episode = 1
item.year = 2022
with SubdivxSubtitlesProvider() as provider:
subtitles = provider.list_subtitles(item, {Language("spa", "MX")})
assert len(subtitles) > 2
def test_download_subtitle(movies): def test_download_subtitle(movies):
subtitle = SubdivxSubtitle( subtitle = SubdivxSubtitle(
Language("spa", "MX"), Language("spa", "MX"),

Loading…
Cancel
Save