summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-06-14 15:56:04 -0400
committermorpheus65535 <[email protected]>2022-06-14 15:56:04 -0400
commita79c2187deab7d3effc63516dc1f0007f934104b (patch)
tree3325539da85a5cdda88a1e4678d9e0a07682df4a
parentba0f827eb45abad41ae31026e823659981041cee (diff)
downloadbazarr-a79c2187deab7d3effc63516dc1f0007f934104b.tar.gz
bazarr-a79c2187deab7d3effc63516dc1f0007f934104b.zip
Fixed throttle expiration for providers that reset at midnight. #1863
-rw-r--r--bazarr/app/get_providers.py102
1 files changed, 54 insertions, 48 deletions
diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py
index e9d4fadd7..53007cdf1 100644
--- a/bazarr/app/get_providers.py
+++ b/bazarr/app/get_providers.py
@@ -39,62 +39,68 @@ def time_until_midnight(timezone):
# Titulky resets its download limits at the start of a new day from its perspective - the Europe/Prague timezone
# Needs to convert to offset-naive dt
-titulky_limit_reset_timedelta = time_until_midnight(timezone=pytz.timezone('Europe/Prague'))
+def titulky_limit_reset_timedelta():
+ return time_until_midnight(timezone=pytz.timezone('Europe/Prague'))
+
# LegendasDivx reset its searches limit at approximately midnight, Lisbon time, everyday.
-legendasdivx_limit_reset_timedelta = time_until_midnight(timezone=pytz.timezone('Europe/Lisbon')) + \
- datetime.timedelta(minutes=15)
+def legendasdivx_limit_reset_timedelta():
+ return time_until_midnight(timezone=pytz.timezone('Europe/Lisbon')) + datetime.timedelta(minutes=15)
-hours_until_end_of_day = time_until_midnight(timezone=tzlocal.get_localzone()).days + 1
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
ParseResponseError, IPAddressBlocked)
VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled', requests.exceptions.Timeout,
requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout, socket.timeout)
-PROVIDER_THROTTLE_MAP = {
- "default": {
- TooManyRequests: (datetime.timedelta(hours=1), "1 hour"),
- DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
- ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
- APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
- ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
- requests.exceptions.Timeout: (datetime.timedelta(hours=1), "1 hour"),
- socket.timeout: (datetime.timedelta(hours=1), "1 hour"),
- requests.exceptions.ConnectTimeout: (datetime.timedelta(hours=1), "1 hour"),
- requests.exceptions.ReadTimeout: (datetime.timedelta(hours=1), "1 hour"),
- },
- "opensubtitles": {
- TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
- DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"),
- DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"),
- APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"),
- },
- "opensubtitlescom": {
- TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"),
- DownloadLimitExceeded: (datetime.timedelta(hours=24), "24 hours"),
- },
- "addic7ed": {
- DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
- TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"),
- IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
- },
- "titulky": {
- DownloadLimitExceeded: (titulky_limit_reset_timedelta, f"{titulky_limit_reset_timedelta.seconds // 3600 + 1} hours")
- },
- "legendasdivx": {
- TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
- DownloadLimitExceeded: (
- legendasdivx_limit_reset_timedelta,
- f"{legendasdivx_limit_reset_timedelta.seconds // 3600 + 1} hours"),
- IPAddressBlocked: (
- legendasdivx_limit_reset_timedelta,
- f"{legendasdivx_limit_reset_timedelta.seconds // 3600 + 1} hours"),
- SearchLimitReached: (
- legendasdivx_limit_reset_timedelta,
- f"{legendasdivx_limit_reset_timedelta.seconds // 3600 + 1} hours"),
+
+def provider_throttle_map():
+ return {
+ "default": {
+ TooManyRequests: (datetime.timedelta(hours=1), "1 hour"),
+ DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
+ ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
+ APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
+ ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
+ requests.exceptions.Timeout: (datetime.timedelta(hours=1), "1 hour"),
+ socket.timeout: (datetime.timedelta(hours=1), "1 hour"),
+ requests.exceptions.ConnectTimeout: (datetime.timedelta(hours=1), "1 hour"),
+ requests.exceptions.ReadTimeout: (datetime.timedelta(hours=1), "1 hour"),
+ },
+ "opensubtitles": {
+ TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
+ DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"),
+ DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"),
+ APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"),
+ },
+ "opensubtitlescom": {
+ TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"),
+ DownloadLimitExceeded: (datetime.timedelta(hours=24), "24 hours"),
+ },
+ "addic7ed": {
+ DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
+ TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"),
+ IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
+ },
+ "titulky": {
+ DownloadLimitExceeded: (
+ titulky_limit_reset_timedelta(),
+ f"{titulky_limit_reset_timedelta().seconds // 3600 + 1} hours")
+ },
+ "legendasdivx": {
+ TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
+ DownloadLimitExceeded: (
+ legendasdivx_limit_reset_timedelta(),
+ f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"),
+ IPAddressBlocked: (
+ legendasdivx_limit_reset_timedelta(),
+ f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"),
+ SearchLimitReached: (
+ legendasdivx_limit_reset_timedelta(),
+ f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"),
+ }
}
-}
+
PROVIDERS_FORCED_OFF = ["addic7ed", "tvsubtitles", "legendasdivx", "legendastv", "napiprojekt", "shooter",
"hosszupuska", "supersubtitles", "titlovi", "argenteam", "assrt", "subscene"]
@@ -252,8 +258,8 @@ def provider_throttle(name, exception):
if isinstance(cls, valid_cls):
cls = valid_cls
- throttle_data = PROVIDER_THROTTLE_MAP.get(name, PROVIDER_THROTTLE_MAP["default"]).get(cls, None) or \
- PROVIDER_THROTTLE_MAP["default"].get(cls, None)
+ throttle_data = provider_throttle_map().get(name, provider_throttle_map()["default"]).get(cls, None) or \
+ provider_throttle_map()["default"].get(cls, None)
if throttle_data:
throttle_delta, throttle_description = throttle_data