Skip to content

Commit

Permalink
Implemented PaymentRequired exception on opensubtitles.org that now r…
Browse files Browse the repository at this point in the history
…equires VIP subscription.
  • Loading branch information
morpheus65535 committed Nov 18, 2023
1 parent 7e650c2 commit b3b4fef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions bazarr/app/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from subzero.language import Language
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError, IPAddressBlocked, \
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 import region as subliminal_cache_region
from subliminal_patch.extensions import provider_registry
Expand Down Expand Up @@ -79,6 +79,7 @@ def provider_throttle_map():
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"),
APIThrottled: (datetime.timedelta(seconds=15), "15 seconds"),
ServiceUnavailable: (datetime.timedelta(hours=1), "1 hour"),
},
Expand Down Expand Up @@ -458,13 +459,15 @@ def list_throttled_providers():

def reset_throttled_providers(only_auth_or_conf_error=False):
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
del tp[provider]
set_throttled_providers(str(tp))
update_throttled_provider()
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:
logging.info('BAZARR throttled providers have been reset.')

Expand Down
5 changes: 5 additions & 0 deletions libs/subliminal/providers/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ class Unauthorized(OpenSubtitlesError, AuthenticationError):
pass


class PaymentRequired(OpenSubtitlesError):
"""Exception raised when status is '402 Payment Required'."""
pass


class NoSession(OpenSubtitlesError, AuthenticationError):
"""Exception raised when status is '406 No session'."""
pass
Expand Down
4 changes: 3 additions & 1 deletion libs/subliminal_patch/providers/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from subliminal.exceptions import ConfigurationError, ServiceUnavailable
from subliminal.providers.opensubtitles import OpenSubtitlesProvider as _OpenSubtitlesProvider,\
OpenSubtitlesSubtitle as _OpenSubtitlesSubtitle, Episode, Movie, ServerProxy, Unauthorized, NoSession, \
DownloadLimitReached, InvalidImdbid, UnknownUserAgent, DisabledUserAgent, OpenSubtitlesError
DownloadLimitReached, InvalidImdbid, UnknownUserAgent, DisabledUserAgent, OpenSubtitlesError, PaymentRequired
from .mixins import ProviderRetryMixin
from subliminal.subtitle import fix_line_ending
from subliminal_patch.providers import reinitialize_on_error
Expand Down Expand Up @@ -418,6 +418,8 @@ def checked(fn, raise_api_limit=False):

if status_code == 401:
raise Unauthorized
if status_code == 402:
raise PaymentRequired
if status_code == 406:
raise NoSession
if status_code == 407:
Expand Down

0 comments on commit b3b4fef

Please sign in to comment.