Merge remote-tracking branch 'origin/development' into development

# Conflicts:
#	bazarr/get_providers.py
This commit is contained in:
morpheus65535 2021-01-31 08:40:45 -05:00
commit f93af2f3e0
1 changed files with 107 additions and 94 deletions

View File

@ -16,6 +16,7 @@ from subliminal.providers.opensubtitles import DownloadLimitReached
from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable
from subliminal import region as subliminal_cache_region
def time_until_end_of_day(dt=None):
# type: (datetime.datetime) -> datetime.timedelta
"""
@ -26,6 +27,7 @@ def time_until_end_of_day(dt=None):
tomorrow = dt + datetime.timedelta(days=1)
return datetime.datetime.combine(tomorrow, datetime.time.min) - dt
hours_until_end_of_day = time_until_end_of_day().seconds // 3600 + 1
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
@ -53,7 +55,8 @@ PROVIDER_THROTTLE_MAP = {
},
"opensubtitlescom": {
TooManyRequests : (datetime.timedelta(minutes=1), "1 minute"),
DownloadLimitExceeded: (datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
},
"addic7ed" : {
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
@ -61,17 +64,20 @@ PROVIDER_THROTTLE_MAP = {
IPAddressBlocked : (datetime.timedelta(hours=1), "1 hours"),
},
"titulky" : {
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours")
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day)))
},
"legendasdivx" : {
TooManyRequests : (datetime.timedelta(hours=3), "3 hours"),
DownloadLimitExceeded: (datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
IPAddressBlocked: (datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
DownloadLimitExceeded: (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
IPAddressBlocked : (
datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
}
}
PROVIDERS_FORCED_OFF = ["addic7ed", "tvsubtitles", "legendasdivx", "legendastv", "napiprojekt", "shooter", "hosszupuska",
"supersubtitles", "titlovi", "argenteam", "assrt", "subscene"]
PROVIDERS_FORCED_OFF = ["addic7ed", "tvsubtitles", "legendasdivx", "legendastv", "napiprojekt", "shooter",
"hosszupuska", "supersubtitles", "titlovi", "argenteam", "assrt", "subscene"]
throttle_count = {}
@ -112,19 +118,25 @@ def get_providers():
def get_providers_auth():
providers_auth = {
'addic7ed': {'username': settings.addic7ed.username,
return {
'addic7ed' : {
'username': settings.addic7ed.username,
'password': settings.addic7ed.password,
},
'opensubtitles': {'username': settings.opensubtitles.username,
'opensubtitles' : {
'username' : settings.opensubtitles.username,
'password' : settings.opensubtitles.password,
'use_tag_search': settings.opensubtitles.getboolean('use_tag_search'),
'use_tag_search': settings.opensubtitles.getboolean(
'use_tag_search'
),
'only_foreign' : False, # fixme
'also_foreign' : False, # fixme
'is_vip' : settings.opensubtitles.getboolean('vip'),
'use_ssl' : settings.opensubtitles.getboolean('ssl'),
'timeout' : int(settings.opensubtitles.timeout) or 15,
'skip_wrong_fps': settings.opensubtitles.getboolean('skip_wrong_fps'),
'skip_wrong_fps': settings.opensubtitles.getboolean(
'skip_wrong_fps'
),
},
'opensubtitlescom': {'username': settings.opensubtitlescom.username,
'password': settings.opensubtitlescom.password,
@ -135,35 +147,44 @@ def get_providers_auth():
'only_foreign': False, # fixme
'also_foreign': False, # fixme
},
'subscene': {'username': settings.subscene.username,
'subscene' : {
'username' : settings.subscene.username,
'password' : settings.subscene.password,
'only_foreign': False, # fixme
},
'legendasdivx': {'username': settings.legendasdivx.username,
'legendasdivx' : {
'username' : settings.legendasdivx.username,
'password' : settings.legendasdivx.password,
'skip_wrong_fps': settings.legendasdivx.getboolean('skip_wrong_fps'),
'skip_wrong_fps': settings.legendasdivx.getboolean(
'skip_wrong_fps'
),
},
'legendastv': {'username': settings.legendastv.username,
'legendastv' : {
'username': settings.legendastv.username,
'password': settings.legendastv.password,
},
'xsubs': {'username': settings.xsubs.username,
'xsubs' : {
'username': settings.xsubs.username,
'password': settings.xsubs.password,
},
'assrt': {'token': settings.assrt.token, },
'napisy24': {'username': settings.napisy24.username,
'assrt' : {
'token': settings.assrt.token,
},
'napisy24' : {
'username': settings.napisy24.username,
'password': settings.napisy24.password,
},
'betaseries' : {'token': settings.betaseries.token},
'titulky': {'username': settings.titulky.username,
'titulky' : {
'username': settings.titulky.username,
'password': settings.titulky.password,
},
'titlovi': {'username': settings.titlovi.username,
'titlovi' : {
'username': settings.titlovi.username,
'password': settings.titlovi.password,
},
}
return providers_auth
def provider_throttle(name, exception):
cls = getattr(exception, "__class__")
@ -214,20 +235,14 @@ def throttled_count(name):
else:
throttle_count[name] = {"count": 1, "time": (datetime.datetime.now() + datetime.timedelta(seconds=120))}
if throttle_count[name]['count'] < 5:
if throttle_count[name]['time'] > datetime.datetime.now():
logging.info("Provider %s throttle count %s of 5, waiting 5sec and trying again", name,
throttle_count[name]['count'])
time.sleep(5)
return False
else:
if throttle_count[name]['count'] >= 5:
return True
if throttle_count[name]['time'] <= datetime.datetime.now():
throttle_count[name] = {"count": 1, "time": (datetime.datetime.now() + datetime.timedelta(seconds=120))}
logging.info("Provider %s throttle count %s of 5, waiting 5sec and trying again", name,
throttle_count[name]['count'])
time.sleep(5)
return False
else:
return True
def update_throttled_provider():
@ -242,9 +257,7 @@ def update_throttled_provider():
if reason:
now = datetime.datetime.now()
if now < until:
pass
else:
if now >= until:
logging.info("Using %s again after %s, (disabled because: %s)", provider, throttle_desc, reason)
del tp[provider]
set_throttled_providers(str(tp))