From bc0b101fd7f93d424949f88e865085f0822bb5ce Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sat, 18 Nov 2023 21:25:57 -0500 Subject: [PATCH] Improved providers exceptions throttling to reduce useless calls to providers. --- bazarr/app/get_providers.py | 12 ++++++------ libs/subliminal_patch/pitcher.py | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py index 9ad4fd152..28a8b1aeb 100644 --- a/bazarr/app/get_providers.py +++ b/bazarr/app/get_providers.py @@ -16,7 +16,7 @@ from requests import ConnectionError from subzero.language import Language from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \ MustGetBlacklisted, SearchLimitReached -from subliminal.providers.opensubtitles import DownloadLimitReached, PaymentRequired +from subliminal.providers.opensubtitles import DownloadLimitReached, PaymentRequired, Unauthorized from subliminal.exceptions import DownloadLimitExceeded, ServiceUnavailable, AuthenticationError, ConfigurationError from subliminal import region as subliminal_cache_region from subliminal_patch.extensions import provider_registry @@ -75,18 +75,21 @@ def provider_throttle_map(): 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"), + ConfigurationError: (datetime.timedelta(hours=12), "12 hours"), + PermissionError: (datetime.timedelta(hours=12), "12 hours"), + requests.exceptions.ProxyError: (datetime.timedelta(hours=1), "1 hour"), + AuthenticationError: (datetime.timedelta(hours=12), "12 hours"), }, "opensubtitles": { TooManyRequests: (datetime.timedelta(hours=3), "3 hours"), DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"), DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"), PaymentRequired: (datetime.timedelta(hours=12), "12 hours"), + Unauthorized: (datetime.timedelta(hours=12), "12 hours"), APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"), ServiceUnavailable: (datetime.timedelta(hours=1), "1 hour"), }, "opensubtitlescom": { - AuthenticationError: (datetime.timedelta(hours=12), "12 hours"), - ConfigurationError: (datetime.timedelta(hours=12), "12 hours"), TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"), DownloadLimitExceeded: (datetime.timedelta(hours=24), "24 hours"), }, @@ -112,9 +115,6 @@ def provider_throttle_map(): legendasdivx_limit_reset_timedelta(), f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"), }, - "subf2m": { - ConfigurationError: (datetime.timedelta(hours=24), "24 hours"), - }, "whisperai": { ConnectionError: (datetime.timedelta(hours=24), "24 hours"), }, diff --git a/libs/subliminal_patch/pitcher.py b/libs/subliminal_patch/pitcher.py index 03af805d9..566e559ef 100644 --- a/libs/subliminal_patch/pitcher.py +++ b/libs/subliminal_patch/pitcher.py @@ -12,6 +12,7 @@ from deathbycaptcha import SocketClient as DBCClient, DEFAULT_TOKEN_TIMEOUT import six from six.moves import range from urllib import parse +from subliminal.exceptions import ConfigurationError logger = logging.getLogger(__name__) @@ -33,7 +34,7 @@ class PitcherRegistry(object): def get_pitcher(self, name_or_site=None, with_proxy=False): name_or_site = name_or_site or os.environ.get("ANTICAPTCHA_CLASS") if not name_or_site: - raise Exception("AntiCaptcha class not given, exiting") + raise ConfigurationError("AntiCaptcha class not given, exiting") key = "%s_%s" % (name_or_site, with_proxy)