summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVitiko <[email protected]>2022-11-09 03:38:50 -0400
committerVitiko <[email protected]>2022-11-09 03:38:50 -0400
commit69e4a9c52657083bdc5c892ce9d0ecb930ef2486 (patch)
tree41d9e98465b7fa87558b96eeb86376cfcbd77aab
parent0c92a1686af29b041abb1e43dc99e8b807dc5b6d (diff)
downloadbazarr-69e4a9c52657083bdc5c892ce9d0ecb930ef2486.tar.gz
bazarr-69e4a9c52657083bdc5c892ce9d0ecb930ef2486.zip
Subdivx Provider: improve series matching
-rw-r--r--libs/subliminal_patch/providers/subdivx.py23
-rw-r--r--tests/subliminal_patch/test_subdivx.py13
2 files changed, 31 insertions, 5 deletions
diff --git a/libs/subliminal_patch/providers/subdivx.py b/libs/subliminal_patch/providers/subdivx.py
index a1e3669fb..f64e77525 100644
--- a/libs/subliminal_patch/providers/subdivx.py
+++ b/libs/subliminal_patch/providers/subdivx.py
@@ -1,22 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
+
import logging
import re
import time
-from subzero.language import Language
from requests import Session
-
+from six.moves import range
from subliminal import __short_version__
from subliminal.providers import ParserBeautifulSoup
-from subliminal.video import Episode, Movie
+from subliminal.video import Episode
+from subliminal.video import Movie
from subliminal_patch.exceptions import APIThrottled
-from six.moves import range
-from subliminal_patch.subtitle import Subtitle
from subliminal_patch.providers import Provider
from subliminal_patch.providers.utils import get_archive_from_bytes
from subliminal_patch.providers.utils import get_subtitle_from_archive
from subliminal_patch.providers.utils import update_matches
+from subliminal_patch.subtitle import Subtitle
+from subzero.language import Language
_SERVER_URL = "https://www.subdivx.com"
@@ -28,6 +29,8 @@ _CLEAN_TITLE_RES = [
_SPANISH_RE = re.compile(r"españa|ib[eé]rico|castellano|gallego|castilla")
_YEAR_RE = re.compile(r"(\(\d{4}\))")
+
+
_SERIES_RE = re.compile(
r"\(?\d{4}\)?|(s\d{1,2}(e\d{1,2})?|(season|temporada)\s\d{1,2}).*?$",
flags=re.IGNORECASE,
@@ -36,6 +39,7 @@ _EPISODE_NUM_RE = re.compile(r"[eE](?P<x>\d{1,2})")
_SEASON_NUM_RE = re.compile(
r"(s|(season|temporada)\s)(?P<x>\d{1,2})", flags=re.IGNORECASE
)
+_EPISODE_YEAR_RE = re.compile(r"\((?P<x>(19\d{2}|20[0-2]\d))\)")
_UNSUPPORTED_RE = re.compile(
r"(\)?\d{4}\)?|[sS]\d{1,2})\s.{,3}(extras|forzado(s)?|forced)", flags=re.IGNORECASE
)
@@ -296,6 +300,15 @@ def _get_download_url(data):
def _check_episode(video, title):
ep_num = _EPISODE_NUM_RE.search(title)
season_num = _SEASON_NUM_RE.search(title)
+ year = _EPISODE_YEAR_RE.search(title)
+
+ # Only check if both video and Subdivx's title have year metadata
+ if year is not None and video.year:
+ year = int(year.group("x"))
+ # Tolerancy of 1 year difference
+ if abs(year - (video.year or 0)) > 1:
+ logger.debug("Series year doesn't match: %s", title)
+ return False
if season_num is None:
logger.debug("Not a season/episode: %s", title)
diff --git a/tests/subliminal_patch/test_subdivx.py b/tests/subliminal_patch/test_subdivx.py
index 26afdedde..15b4fce53 100644
--- a/tests/subliminal_patch/test_subdivx.py
+++ b/tests/subliminal_patch/test_subdivx.py
@@ -44,6 +44,19 @@ def test_list_subtitles_episode(episodes, episode_key, expected):
assert len(subtitles) >= expected
+def test_list_subtitles_episode_with_year(episodes):
+ item = list(episodes.values())[0]
+
+ item.series = "The Twilight Zone"
+ item.name = "The Twilight Zone"
+ item.year = 1959
+ item.season = 1
+ item.episode = 1
+
+ with SubdivxSubtitlesProvider() as provider:
+ assert provider.list_subtitles(item, {Language.fromietf("es")})
+
+
def test_list_subtitles_castillian_spanish(episodes):
item = episodes["better_call_saul_s06e04"]
with SubdivxSubtitlesProvider() as provider: