Implemented PaymentRequired exception on opensubtitles.org that now requires VIP subscription.

This commit is contained in:
morpheus65535 2023-11-18 10:30:37 -05:00
parent 7e650c2bab
commit b3b4fef8c7
3 changed files with 14 additions and 4 deletions

View File

@ -15,7 +15,7 @@ import re
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 from subliminal.providers.opensubtitles import DownloadLimitReached, PaymentRequired
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
@ -79,6 +79,7 @@ def provider_throttle_map():
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"),
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"),
}, },
@ -458,13 +459,15 @@ def list_throttled_providers():
def reset_throttled_providers(only_auth_or_conf_error=False): def reset_throttled_providers(only_auth_or_conf_error=False):
for provider in list(tp): for provider in list(tp):
if only_auth_or_conf_error and tp[provider][0] not in ['AuthenticationError', 'ConfigurationError']: if only_auth_or_conf_error and tp[provider][0] not in ['AuthenticationError', 'ConfigurationError',
'PaymentRequired']:
continue continue
del tp[provider] del tp[provider]
set_throttled_providers(str(tp)) set_throttled_providers(str(tp))
update_throttled_provider() update_throttled_provider()
if only_auth_or_conf_error: if only_auth_or_conf_error:
logging.info('BAZARR throttled providers have been reset (only AuthenticationError and ConfigurationError).') logging.info('BAZARR throttled providers have been reset (only AuthenticationError, ConfigurationError and '
'PaymentRequired).')
else: else:
logging.info('BAZARR throttled providers have been reset.') logging.info('BAZARR throttled providers have been reset.')

View File

@ -237,6 +237,11 @@ class Unauthorized(OpenSubtitlesError, AuthenticationError):
pass pass
class PaymentRequired(OpenSubtitlesError):
"""Exception raised when status is '402 Payment Required'."""
pass
class NoSession(OpenSubtitlesError, AuthenticationError): class NoSession(OpenSubtitlesError, AuthenticationError):
"""Exception raised when status is '406 No session'.""" """Exception raised when status is '406 No session'."""
pass pass

View File

@ -15,7 +15,7 @@ from guessit import guessit
from subliminal.exceptions import ConfigurationError, ServiceUnavailable from subliminal.exceptions import ConfigurationError, ServiceUnavailable
from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSubtitlesProvider,\ from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSubtitlesProvider,\
OpenSubtitlesSubtitle as _OpenSubtitlesSubtitle, Episode, Movie, ServerProxy, Unauthorized, NoSession, \ OpenSubtitlesSubtitle as _OpenSubtitlesSubtitle, Episode, Movie, ServerProxy, Unauthorized, NoSession, \
DownloadLimitReached, InvalidImdbid, UnknownUserAgent, DisabledUserAgent, OpenSubtitlesError DownloadLimitReached, InvalidImdbid, UnknownUserAgent, DisabledUserAgent, OpenSubtitlesError, PaymentRequired
from .mixins import ProviderRetryMixin from .mixins import ProviderRetryMixin
from subliminal.subtitle import fix_line_ending from subliminal.subtitle import fix_line_ending
from subliminal_patch.providers import reinitialize_on_error from subliminal_patch.providers import reinitialize_on_error
@ -418,6 +418,8 @@ def checked(fn, raise_api_limit=False):
if status_code == 401: if status_code == 401:
raise Unauthorized raise Unauthorized
if status_code == 402:
raise PaymentRequired
if status_code == 406: if status_code == 406:
raise NoSession raise NoSession
if status_code == 407: if status_code == 407: