From 9d62d84ef590c65e7e9392fe82f1f2022b90bede Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Fri, 20 Dec 2024 20:32:13 -0500 Subject: [PATCH] Fixed titrari provider to prevent abuse and throttle properly. #2709 --- bazarr/app/get_providers.py | 3 +++ custom_libs/subliminal_patch/providers/titrari.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bazarr/app/get_providers.py b/bazarr/app/get_providers.py index f45118326..c4c9b5be4 100644 --- a/bazarr/app/get_providers.py +++ b/bazarr/app/get_providers.py @@ -100,6 +100,9 @@ def provider_throttle_map(): "titlovi": { TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"), }, + "titrari": { + TooManyRequests: (datetime.timedelta(minutes=10), "10 minutes"), + }, "titulky": { DownloadLimitExceeded: ( titulky_limit_reset_timedelta(), diff --git a/custom_libs/subliminal_patch/providers/titrari.py b/custom_libs/subliminal_patch/providers/titrari.py index 7caed684d..a9976df21 100644 --- a/custom_libs/subliminal_patch/providers/titrari.py +++ b/custom_libs/subliminal_patch/providers/titrari.py @@ -5,18 +5,18 @@ import io import logging import re -import rarfile -from random import randint from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile from guessit import guessit +from time import sleep + from subliminal_patch.providers import Provider 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 .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST from subliminal.exceptions import ProviderError +from subliminal_patch.exceptions import TooManyRequests from subliminal.providers import ParserBeautifulSoup from subliminal.video import Episode, Movie from subliminal.subtitle import SUBTITLE_EXTENSIONS @@ -147,6 +147,10 @@ def query(self, language=None, title=None, imdb_id=None, video=None): params = self.getQueryParams(imdb_id, title, language) search_response = self.session.get(self.api_url, params=params, timeout=15) + + if search_response.status_code == 404 and 'Too many requests' in search_response.content: + raise TooManyRequests(search_response.content) + search_response.raise_for_status() if not search_response.content: @@ -215,6 +219,8 @@ def query(self, language=None, title=None, imdb_id=None, video=None): ordered_subs = self.order(subtitles) + sleep(5) # prevent being blocked for too many requests + return ordered_subs @staticmethod