aboutsummaryrefslogtreecommitdiffhomepage
path: root/custom_libs/subliminal_patch/providers/subdivx.py
diff options
context:
space:
mode:
authorJayZed <[email protected]>2024-07-08 17:33:43 -0400
committerJayZed <[email protected]>2024-07-08 17:33:43 -0400
commit4cc6806193127f9d6d3f2dab26969471d9bbf159 (patch)
treebfc90e4b55fa0f48f83e51c4e5947c1f7d7d7a2d /custom_libs/subliminal_patch/providers/subdivx.py
parentd875dc7733c901246881325ee3a84fe5d44b10b9 (diff)
parent5886c20c9c7929bf46836a99c2d9d4eb834638bd (diff)
downloadbazarr-4cc6806193127f9d6d3f2dab26969471d9bbf159.tar.gz
bazarr-4cc6806193127f9d6d3f2dab26969471d9bbf159.zip
Merge branch 'development' of https://github.com/morpheus65535/bazarr into development
Diffstat (limited to 'custom_libs/subliminal_patch/providers/subdivx.py')
-rw-r--r--custom_libs/subliminal_patch/providers/subdivx.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/custom_libs/subliminal_patch/providers/subdivx.py b/custom_libs/subliminal_patch/providers/subdivx.py
index 4b250a2a2..a19ae1b5e 100644
--- a/custom_libs/subliminal_patch/providers/subdivx.py
+++ b/custom_libs/subliminal_patch/providers/subdivx.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
-from json import JSONDecodeError
+from requests.exceptions import JSONDecodeError
import logging
import random
import re
@@ -126,7 +126,7 @@ class SubdivxSubtitlesProvider(Provider):
titles = [video.series if episode else video.title]
try:
- titles.extend(video.alternative_titles)
+ titles.extend(video.alternative_series if episode else video.alternative_titles)
except:
pass
else:
@@ -138,6 +138,7 @@ class SubdivxSubtitlesProvider(Provider):
# TODO: cache pack queries (TV SHOW S01).
# Too many redundant server calls.
for title in titles:
+ title = _series_sanitizer(title)
for query in (
f"{title} S{video.season:02}E{video.episode:02}",
f"{title} S{video.season:02}",
@@ -297,20 +298,31 @@ def _check_episode(video, title):
) and season_num == video.season
series_title = _SERIES_RE.sub("", title).strip()
+ series_title = _series_sanitizer(series_title)
- distance = abs(len(series_title) - len(video.series))
+ for video_series_title in [video.series] + video.alternative_series:
+ video_series_title = _series_sanitizer(video_series_title)
+ distance = abs(len(series_title) - len(video_series_title))
- series_matched = distance < 4 and ep_matches
+ series_matched = (distance < 4 or video_series_title in series_title) and ep_matches
+
+ logger.debug(
+ "Series matched? %s [%s -> %s] [title distance: %d]",
+ series_matched,
+ video_series_title,
+ series_title,
+ distance,
+ )
+
+ if series_matched:
+ return True
+ return False
- logger.debug(
- "Series matched? %s [%s -> %s] [title distance: %d]",
- series_matched,
- video,
- title,
- distance,
- )
- return series_matched
+def _series_sanitizer(title):
+ title = re.sub(r"\'|\.+", '', title) # remove single quote and dot
+ title = re.sub(r"\W+", ' ', title) # replace by a space anything other than a letter, digit or underscore
+ return re.sub(r"([A-Z])\s(?=[A-Z]\b)", '', title).strip() # Marvels Agent of S.H.I.E.L.D
def _check_movie(video, title):