Skip to content

Commit ab759fd

Browse files
committed
Handled "429 Too Many Requests" error in Titulky provider by raising TooManyRequests exception and adjusting throttling duration. #3165
1 parent 93b38bf commit ab759fd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

bazarr/app/get_providers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def provider_throttle_map():
9494
TooManyRequests: (datetime.timedelta(minutes=10), "10 minutes"),
9595
},
9696
"titulky": {
97+
TooManyRequests: (datetime.timedelta(minutes=1), "1 minute"),
9798
DownloadLimitExceeded: (
9899
titulky_limit_reset_timedelta(),
99100
f"{titulky_limit_reset_timedelta().seconds // 3600 + 1} hours")

custom_libs/subliminal_patch/providers/titulky.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import rarfile
1111
from guessit import guessit
1212
from requests import Session
13-
from requests.adapters import HTTPAdapter
1413
from requests.exceptions import HTTPError
1514

1615
from subliminal.cache import region as cache
@@ -21,6 +20,7 @@
2120

2221
from subliminal_patch.providers import Provider
2322
from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin
23+
from subliminal_patch.exceptions import TooManyRequests
2424

2525
from subliminal_patch.subtitle import Subtitle, guess_matches
2626

@@ -271,6 +271,8 @@ def get_request(self, url, ref=server_url, allow_redirects=False, _recursion=0):
271271
def fetch_page(self, url, ref=server_url, allow_redirects=False):
272272
res = self.get_request(url, ref=ref, allow_redirects=allow_redirects)
273273

274+
if res.status_code == 429:
275+
raise TooManyRequests("Titulky.com: Too many requests, sleeping for 60 seconds.")
274276
if res.status_code != 200:
275277
raise HTTPError(f"Fetch failed with status code {res.status_code}")
276278
if not res.text:
@@ -512,6 +514,9 @@ def list_subtitles(self, video, languages):
512514
def download_subtitle(self, subtitle):
513515
res = self.get_request(subtitle.download_link, ref=subtitle.page_link)
514516

517+
if res.status_code == 429:
518+
raise TooManyRequests("Titulky.com: Too many requests, sleeping for 60 seconds.")
519+
515520
try:
516521
res.raise_for_status()
517522
except:

0 commit comments

Comments
 (0)