mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-09-20 15:35:58 +08:00
core: update to subliminal_patch:head;
This commit is contained in:
parent
8cd8177455
commit
98f456e20f
|
@ -9,7 +9,8 @@ class AssrtConverter(LanguageReverseConverter):
|
|||
u'英文': ('eng',),
|
||||
u'chs': ('zho', None, 'Hans'), u'cht': ('zho', None, 'Hant'),
|
||||
u'chn': ('zho', None, 'Hans'), u'twn': ('zho', None, 'Hant')}
|
||||
self.to_assrt = { ('zho', None, 'Hans'): u'chs', ('zho', None, 'Hant'): u'cht', ('eng',) : u'eng' }
|
||||
self.to_assrt = { ('zho', None, 'Hans'): u'chs', ('zho', None, 'Hant'): u'cht', ('eng',) : u'eng',
|
||||
('zho',): u'chs'}
|
||||
self.codes = set(self.from_assrt.keys())
|
||||
|
||||
def convert(self, alpha3, country=None, script=None):
|
||||
|
|
|
@ -38,12 +38,29 @@ custom_resolver = dns.resolver.Resolver(configure=False)
|
|||
custom_resolver.nameservers = ['8.8.8.8', '1.1.1.1']
|
||||
|
||||
|
||||
class CertifiSession(CloudflareScraper):
|
||||
class TimeoutSession(requests.Session):
|
||||
timeout = 10
|
||||
|
||||
def __init__(self, timeout=None):
|
||||
super(TimeoutSession, self).__init__()
|
||||
self.timeout = timeout or self.timeout
|
||||
|
||||
def request(self, method, url, *args, **kwargs):
|
||||
if kwargs.get('timeout') is None:
|
||||
kwargs['timeout'] = self.timeout
|
||||
|
||||
return super(TimeoutSession, self).request(method, url, *args, **kwargs)
|
||||
|
||||
|
||||
class CertifiSession(TimeoutSession):
|
||||
def __init__(self):
|
||||
super(CertifiSession, self).__init__()
|
||||
self.verify = pem_file
|
||||
|
||||
|
||||
class CFSession(CloudflareScraper, CertifiSession, TimeoutSession):
|
||||
def __init__(self):
|
||||
super(CFSession, self).__init__()
|
||||
self.headers.update({
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
'Accept-Language': 'en-US,en;q=0.5',
|
||||
|
@ -53,9 +70,6 @@ class CertifiSession(CloudflareScraper):
|
|||
})
|
||||
|
||||
def request(self, method, url, *args, **kwargs):
|
||||
if kwargs.get('timeout') is None:
|
||||
kwargs['timeout'] = self.timeout
|
||||
|
||||
parsed_url = urlparse(url)
|
||||
domain = parsed_url.netloc
|
||||
|
||||
|
@ -71,7 +85,7 @@ class CertifiSession(CloudflareScraper):
|
|||
|
||||
self.headers['User-Agent'] = user_agent
|
||||
|
||||
ret = super(CertifiSession, self).request(method, url, *args, **kwargs)
|
||||
ret = super(CFSession, self).request(method, url, *args, **kwargs)
|
||||
try:
|
||||
cf_data = self.get_live_tokens(domain)
|
||||
except:
|
||||
|
@ -85,12 +99,11 @@ class CertifiSession(CloudflareScraper):
|
|||
return ret
|
||||
|
||||
|
||||
class RetryingSession(CertifiSession):
|
||||
class RetryingSession(CFSession):
|
||||
proxied_functions = ("get", "post")
|
||||
|
||||
def __init__(self):
|
||||
super(RetryingSession, self).__init__()
|
||||
self.verify = pem_file
|
||||
|
||||
proxy = os.environ.get('SZ_HTTP_PROXY')
|
||||
if proxy:
|
||||
|
|
|
@ -146,6 +146,47 @@ class Addic7edProvider(_Addic7edProvider):
|
|||
def terminate(self):
|
||||
self.session.close()
|
||||
|
||||
def get_show_id(self, series, year=None, country_code=None):
|
||||
"""Get the best matching show id for `series`, `year` and `country_code`.
|
||||
|
||||
First search in the result of :meth:`_get_show_ids` and fallback on a search with :meth:`_search_show_id`.
|
||||
|
||||
:param str series: series of the episode.
|
||||
:param year: year of the series, if any.
|
||||
:type year: int
|
||||
:param country_code: country code of the series, if any.
|
||||
:type country_code: str
|
||||
:return: the show id, if found.
|
||||
:rtype: int
|
||||
|
||||
"""
|
||||
series_sanitized = sanitize(series).lower()
|
||||
show_ids = self._get_show_ids()
|
||||
show_id = None
|
||||
|
||||
# attempt with country
|
||||
if not show_id and country_code:
|
||||
logger.debug('Getting show id with country')
|
||||
show_id = show_ids.get('%s %s' % (series_sanitized, country_code.lower()))
|
||||
|
||||
# attempt with year
|
||||
if not show_id and year:
|
||||
logger.debug('Getting show id with year')
|
||||
show_id = show_ids.get('%s %d' % (series_sanitized, year))
|
||||
|
||||
# attempt clean
|
||||
if not show_id:
|
||||
logger.debug('Getting show id')
|
||||
show_id = show_ids.get(series_sanitized)
|
||||
|
||||
# search as last resort
|
||||
# broken right now
|
||||
# if not show_id:
|
||||
# logger.warning('Series %s not found in show ids', series)
|
||||
# show_id = self._search_show_id(series)
|
||||
|
||||
return show_id
|
||||
|
||||
@region.cache_on_arguments(expiration_time=SHOW_EXPIRATION_TIME)
|
||||
def _get_show_ids(self):
|
||||
"""Get the ``dict`` of show ids per series by querying the `shows.php` page.
|
||||
|
|
|
@ -5,10 +5,13 @@ import base64
|
|||
import zlib
|
||||
from subliminal import __short_version__
|
||||
from subliminal.refiners.omdb import OMDBClient, refine as refine_orig, Episode, Movie
|
||||
from subliminal_patch.http import TimeoutSession
|
||||
|
||||
|
||||
class SZOMDBClient(OMDBClient):
|
||||
def __init__(self, version=1, session=None, headers=None, timeout=10):
|
||||
if not session:
|
||||
session = TimeoutSession(timeout=timeout)
|
||||
super(SZOMDBClient, self).__init__(version=version, session=session, headers=headers, timeout=timeout)
|
||||
|
||||
def get_params(self, params):
|
||||
|
|
|
@ -5,9 +5,12 @@ import datetime
|
|||
from subliminal.refiners.tvdb import Episode, logger, search_series, series_re, sanitize, get_series, \
|
||||
get_series_episode, region, tvdb_client
|
||||
|
||||
from util import fix_session_bases
|
||||
|
||||
TVDB_SEASON_EXPIRATION_TIME = datetime.timedelta(days=1).total_seconds()
|
||||
|
||||
fix_session_bases(tvdb_client.session)
|
||||
|
||||
|
||||
@region.cache_on_arguments(expiration_time=TVDB_SEASON_EXPIRATION_TIME)
|
||||
def is_season_fully_aired(series_id, season):
|
||||
|
|
Loading…
Reference in a new issue