Skip to content

Commit

Permalink
Fixed titrari provider to prevent abuse and throttle properly. #2709
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus65535 committed Dec 21, 2024
1 parent 43d9d43 commit 9d62d84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions bazarr/app/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 9 additions & 3 deletions custom_libs/subliminal_patch/providers/titrari.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d62d84

Please sign in to comment.