summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorVitiko <[email protected]>2023-03-03 15:51:38 -0400
committerVitiko <[email protected]>2023-03-03 15:51:38 -0400
commitad13f79d193d479b0c674a05330b97befc8445c7 (patch)
tree0c8a4102c03dcdb4c131937d25fcee6f520368e2 /libs
parent248e49de76c4a94e9dc6db9166521b8527f476bc (diff)
downloadbazarr-ad13f79d193d479b0c674a05330b97befc8445c7.tar.gz
bazarr-ad13f79d193d479b0c674a05330b97befc8445c7.zip
Subf2m Provider: improve episode matching (#2081)
Diffstat (limited to 'libs')
-rw-r--r--libs/subliminal_patch/providers/subf2m.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/libs/subliminal_patch/providers/subf2m.py b/libs/subliminal_patch/providers/subf2m.py
index 2ee78899b..5d0ebcffd 100644
--- a/libs/subliminal_patch/providers/subf2m.py
+++ b/libs/subliminal_patch/providers/subf2m.py
@@ -5,8 +5,15 @@ import functools
import logging
import re
import time
+import ssl
import urllib.parse
+from urllib3 import poolmanager
+
+from guessit import guessit
+
+from requests import Session
+from requests.adapters import HTTPAdapter
from bs4 import BeautifulSoup as bso
from guessit import guessit
from requests import Session
@@ -113,6 +120,20 @@ _LANGUAGE_MAP = {
}
+class _Adapter(HTTPAdapter):
+ def init_poolmanager(self, connections, maxsize, block=False):
+ ctx = ssl.create_default_context()
+ ctx.set_ciphers("DEFAULT@SECLEVEL=0")
+ ctx.check_hostname = False
+ self.poolmanager = poolmanager.PoolManager(
+ num_pools=connections,
+ maxsize=maxsize,
+ block=block,
+ ssl_version=ssl.PROTOCOL_TLS,
+ ssl_context=ctx,
+ )
+
+
class Subf2mProvider(Provider):
provider_name = "subf2m"
@@ -141,6 +162,8 @@ class Subf2mProvider(Provider):
def initialize(self):
self._session = Session()
+ self._session.mount("https://", _Adapter())
+
self._session.verify = self._verify_ssl
self._session.headers.update({"user-agent": "Bazarr"})
@@ -283,8 +306,11 @@ class Subf2mProvider(Provider):
if not clean_text:
continue
- # It will return list values
- guess = _memoized_episode_guess(clean_text)
+ # First try with the special episode matches for subf2m
+ guess = _get_episode_from_release(clean_text)
+
+ if guess is None:
+ guess = _memoized_episode_guess(clean_text)
if "season" not in guess:
if "complete series" in clean_text.lower():
@@ -390,6 +416,24 @@ def _memoized_episode_guess(content):
)
+_EPISODE_SPECIAL_RE = re.compile(
+ r"(season|s)\s*?(?P<x>\d{,2})\s?[-−]\s?(?P<y>\d{,2})", flags=re.IGNORECASE
+)
+
+
+def _get_episode_from_release(release: str):
+ match = _EPISODE_SPECIAL_RE.search(release)
+ if match is None:
+ return None
+
+ try:
+ season, episode = [int(item) for item in match.group("x", "y")]
+ except (IndexError, ValueError):
+ return None
+
+ return {"season": [season], "episode": [episode]}
+
+
def _get_subtitle_from_item(item, language, episode_number=None):
release_info = [
rel.text.strip() for rel in item.find("ul", {"class": "scrolllist"})