Skip to content

Commit

Permalink
Improved providers exceptions throttling to reduce useless calls to p…
Browse files Browse the repository at this point in the history
…roviders.
  • Loading branch information
morpheus65535 committed Nov 19, 2023
1 parent b25d416 commit bc0b101
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bazarr/app/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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
Expand Down Expand Up @@ -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"),
},
Expand All @@ -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"),
},
Expand Down
3 changes: 2 additions & 1 deletion libs/subliminal_patch/pitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import six
from six.moves import range
from urllib import parse
from subliminal.exceptions import ConfigurationError


logger = logging.getLogger(__name__)
Expand All @@ -33,7 +34,7 @@ def register(self, cls):
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)

Expand Down

0 comments on commit bc0b101

Please sign in to comment.