From b3b4fef8c7b8de80d9c7167a445815b8f356f8aa Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Sat, 18 Nov 2023 10:30:37 -0500 Subject: [PATCH] Implemented PaymentRequired exception on opensubtitles.org that now requires VIP subscription. --- bazarr/app/get_providers.py | 9 ++++++--- libs/subliminal/providers/opensubtitles.py | 5 +++++ libs/subliminal_patch/providers/opensubtitles.py | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py index 48a4cef65..026a20291 100644 --- a/bazarr/app/get_providers.py +++ b/bazarr/app/get_providers.py @@ -15,7 +15,7 @@ import re 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 @@ -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"), }, @@ -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.') diff --git a/libs/subliminal/providers/opensubtitles.py b/libs/subliminal/providers/opensubtitles.py index 7a0b60029..ebe791e53 100644 --- a/libs/subliminal/providers/opensubtitles.py +++ b/libs/subliminal/providers/opensubtitles.py @@ -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 diff --git a/libs/subliminal_patch/providers/opensubtitles.py b/libs/subliminal_patch/providers/opensubtitles.py index 2918fd6ce..678ec882e 100644 --- a/libs/subliminal_patch/providers/opensubtitles.py +++ b/libs/subliminal_patch/providers/opensubtitles.py @@ -15,7 +15,7 @@ from guessit import guessit 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 @@ -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: