Improved providers exceptions throttling to reduce useless calls to providers.

This commit is contained in:
morpheus65535 2023-11-18 21:25:57 -05:00
parent b25d4164c2
commit bc0b101fd7
2 changed files with 8 additions and 7 deletions

View File

@ -16,7 +16,7 @@ from requests import ConnectionError
from subzero.language import Language from subzero.language import Language
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \ from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
MustGetBlacklisted, SearchLimitReached 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.exceptions import DownloadLimitExceeded, ServiceUnavailable, AuthenticationError, ConfigurationError
from subliminal import region as subliminal_cache_region from subliminal import region as subliminal_cache_region
from subliminal_patch.extensions import provider_registry from subliminal_patch.extensions import provider_registry
@ -75,18 +75,21 @@ def provider_throttle_map():
socket.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.ConnectTimeout: (datetime.timedelta(hours=1), "1 hour"),
requests.exceptions.ReadTimeout: (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": { "opensubtitles": {
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"), TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"), DownloadLimitExceeded: (datetime.timedelta(hours=6), "6 hours"),
DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"), DownloadLimitReached: (datetime.timedelta(hours=6), "6 hours"),
PaymentRequired: (datetime.timedelta(hours=12), "12 hours"), PaymentRequired: (datetime.timedelta(hours=12), "12 hours"),
Unauthorized: (datetime.timedelta(hours=12), "12 hours"),
APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"), APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"),
ServiceUnavailable: (datetime.timedelta(hours=1), "1 hour"), ServiceUnavailable: (datetime.timedelta(hours=1), "1 hour"),
}, },
"opensubtitlescom": { "opensubtitlescom": {
AuthenticationError: (datetime.timedelta(hours=12), "12 hours"),
ConfigurationError: (datetime.timedelta(hours=12), "12 hours"),
TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"), TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"),
DownloadLimitExceeded: (datetime.timedelta(hours=24), "24 hours"), DownloadLimitExceeded: (datetime.timedelta(hours=24), "24 hours"),
}, },
@ -112,9 +115,6 @@ def provider_throttle_map():
legendasdivx_limit_reset_timedelta(), legendasdivx_limit_reset_timedelta(),
f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"), f"{legendasdivx_limit_reset_timedelta().seconds // 3600 + 1} hours"),
}, },
"subf2m": {
ConfigurationError: (datetime.timedelta(hours=24), "24 hours"),
},
"whisperai": { "whisperai": {
ConnectionError: (datetime.timedelta(hours=24), "24 hours"), ConnectionError: (datetime.timedelta(hours=24), "24 hours"),
}, },

View File

@ -12,6 +12,7 @@ from deathbycaptcha import SocketClient as DBCClient, DEFAULT_TOKEN_TIMEOUT
import six import six
from six.moves import range from six.moves import range
from urllib import parse from urllib import parse
from subliminal.exceptions import ConfigurationError
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -33,7 +34,7 @@ class PitcherRegistry(object):
def get_pitcher(self, name_or_site=None, with_proxy=False): def get_pitcher(self, name_or_site=None, with_proxy=False):
name_or_site = name_or_site or os.environ.get("ANTICAPTCHA_CLASS") name_or_site = name_or_site or os.environ.get("ANTICAPTCHA_CLASS")
if not name_or_site: 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) key = "%s_%s" % (name_or_site, with_proxy)