diff options
author | morpheus65535 <[email protected]> | 2024-01-13 16:58:13 -0500 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2024-01-13 16:58:13 -0500 |
commit | 828ac34074c35778ac47ce7df78c362def60de77 (patch) | |
tree | b448932954c40c4a133f344843a10de03be4eb5b | |
parent | e4ebc64ca95b4a18b7a1909a5cef517c0715d74d (diff) | |
download | bazarr-828ac34074c35778ac47ce7df78c362def60de77.tar.gz bazarr-828ac34074c35778ac47ce7df78c362def60de77.zip |
Fixed titlovi provider not being properly throttled and resulting in account locking. #2062v1.4.1-beta.16
-rw-r--r-- | bazarr/app/get_providers.py | 3 | ||||
-rw-r--r-- | libs/subliminal_patch/providers/titlovi.py | 14 |
2 files changed, 13 insertions, 4 deletions
diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py index 415340b19..2b6d5f5f7 100644 --- a/bazarr/app/get_providers.py +++ b/bazarr/app/get_providers.py @@ -98,6 +98,9 @@ def provider_throttle_map(): TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"), IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"), }, + "titlovi": { + TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"), + }, "titulky": { DownloadLimitExceeded: ( titulky_limit_reset_timedelta(), diff --git a/libs/subliminal_patch/providers/titlovi.py b/libs/subliminal_patch/providers/titlovi.py index 42c224bce..88782522c 100644 --- a/libs/subliminal_patch/providers/titlovi.py +++ b/libs/subliminal_patch/providers/titlovi.py @@ -7,8 +7,6 @@ import re from datetime import datetime, timedelta import dateutil.parser -import rarfile - from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile from babelfish import language_converters, Script @@ -20,6 +18,7 @@ from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin from subliminal_patch.subtitle import Subtitle, guess_matches from subliminal_patch.utils import sanitize, fix_inconsistent_naming as _fix_inconsistent_naming from subliminal.exceptions import ProviderError, AuthenticationError, ConfigurationError +from subliminal_patch.exceptions import TooManyRequests from subliminal.score import get_equivalent_release_groups from subliminal.utils import sanitize_release_group from subliminal.video import Episode, Movie @@ -190,7 +189,11 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): @region.cache_on_arguments(expiration_time=SHOW_EXPIRATION_TIME) def get_result(self, search_url, search_params): - return self.session.get(search_url, params=search_params) + resp = self.session.get(search_url, params=search_params) + if resp.status_code == request_codes.too_many_requests: + raise TooManyRequests('Too many requests') + else: + return resp def query(self, languages, title, season=None, episode=None, year=None, imdb_id=None, video=None): search_params = dict() @@ -235,7 +238,8 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): resp_json = response.json() if resp_json['SubtitleResults']: query_results.extend(resp_json['SubtitleResults']) - + except TooManyRequests: + raise except Exception as e: logger.error(e) @@ -295,6 +299,8 @@ class TitloviProvider(Provider, ProviderSubtitleArchiveMixin): def download_subtitle(self, subtitle): r = self.session.get(subtitle.download_link, timeout=10) + if r.status_code == request_codes.too_many_requests: + raise TooManyRequests('Too many requests') r.raise_for_status() # open the archive |