summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-03-18 22:04:10 -0400
committermorpheus65535 <[email protected]>2022-03-18 22:04:10 -0400
commitaf4af41a230fc51c480fd42e827cb91c80f372ca (patch)
treecd861ddf00ee7b384ba67257e79a20af3c7eb77a
parent73fca9646b72dde94a0cfc35f106488a323585f3 (diff)
downloadbazarr-af4af41a230fc51c480fd42e827cb91c80f372ca.tar.gz
bazarr-af4af41a230fc51c480fd42e827cb91c80f372ca.zip
no log: trying to fix midnight throttling
-rw-r--r--bazarr/get_providers.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py
index 446c08908..9314aa96f 100644
--- a/bazarr/get_providers.py
+++ b/bazarr/get_providers.py
@@ -8,6 +8,7 @@ import pretty
import time
import socket
import requests
+import tzlocal
from get_args import args
from config import settings, get_array_from
@@ -21,28 +22,26 @@ from subliminal import region as subliminal_cache_region
from subliminal_patch.extensions import provider_registry
-def time_until_end_of_day(dt=None):
+def time_until_midnight(timezone):
# type: (datetime.datetime) -> datetime.timedelta
"""
- Get timedelta until end of day on the datetime passed, or current time.
+ Get timedelta until midnight.
"""
- if dt is None:
- dt = datetime.datetime.now()
- tomorrow = dt + datetime.timedelta(days=1)
- return datetime.datetime.combine(tomorrow, datetime.time.min) - dt
+ now_in_tz = datetime.datetime.now(tz=timezone)
+ midnight = now_in_tz.replace(hour=0, minute=0, second=0, microsecond=0) + \
+ datetime.timedelta(days=1)
+ return midnight - now_in_tz
# 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_server_local_time = datetime.datetime.now(tz=pytz.timezone('Europe/Prague')).replace(tzinfo=None)
-titulky_limit_reset_datetime = time_until_end_of_day(dt=titulky_server_local_time)
+titulky_limit_reset_timedelta = time_until_midnight(timezone=pytz.timezone('Europe/Prague'))
# LegendasDivx reset its searches limit at approximately midnight, Lisbon time, everyday.
-legendasdivx_server_local_time = datetime.datetime.now(tz=pytz.timezone('Europe/Lisbon')).replace(tzinfo=None)
-legendasdivx_limit_reset_datetime = time_until_end_of_day(dt=legendasdivx_server_local_time) + \
+legendasdivx_limit_reset_timedelta = time_until_midnight(timezone=pytz.timezone('Europe/Lisbon')) + \
datetime.timedelta(minutes=15)
-hours_until_end_of_day = time_until_end_of_day().seconds // 3600 + 1
+hours_until_end_of_day = time_until_midnight(timezone=tzlocal.get_localzone()).days + 1
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
ParseResponseError, IPAddressBlocked)
@@ -77,16 +76,19 @@ PROVIDER_THROTTLE_MAP = {
IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
},
"titulky": {
- DownloadLimitExceeded: (titulky_limit_reset_datetime, f"{titulky_limit_reset_datetime.seconds // 3600 + 1} hours")
+ DownloadLimitExceeded: (titulky_limit_reset_timedelta, f"{titulky_limit_reset_timedelta.seconds // 3600 + 1} hours")
},
"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))),
+ legendasdivx_limit_reset_timedelta,
+ f"{legendasdivx_limit_reset_timedelta.seconds // 3600 + 1} hours"),
IPAddressBlocked: (
- datetime.timedelta(hours=hours_until_end_of_day), "{} hours".format(str(hours_until_end_of_day))),
- SearchLimitReached: (legendasdivx_limit_reset_datetime,
- f"{legendasdivx_limit_reset_datetime.seconds // 3600} hours"),
+ 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"),
}
}