Skip to content

Commit

Permalink
Fixed titlovi provider not being properly throttled and resulting in …
Browse files Browse the repository at this point in the history
…account locking. #2062
  • Loading branch information
morpheus65535 committed Jan 13, 2024
1 parent e4ebc64 commit 828ac34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions bazarr/app/get_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
14 changes: 10 additions & 4 deletions libs/subliminal_patch/providers/titlovi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
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
Expand All @@ -20,6 +18,7 @@
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
Expand Down Expand Up @@ -190,7 +189,11 @@ def terminate(self):

@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()
Expand Down Expand Up @@ -235,7 +238,8 @@ def query(self, languages, title, season=None, episode=None, year=None, imdb_id=
resp_json = response.json()
if resp_json['SubtitleResults']:
query_results.extend(resp_json['SubtitleResults'])

except TooManyRequests:
raise
except Exception as e:
logger.error(e)

Expand Down Expand Up @@ -295,6 +299,8 @@ def list_subtitles(self, video, languages):

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
Expand Down

0 comments on commit 828ac34

Please sign in to comment.