|
10 | 10 | import rarfile |
11 | 11 | from guessit import guessit |
12 | 12 | from requests import Session |
13 | | -from requests.adapters import HTTPAdapter |
14 | 13 | from requests.exceptions import HTTPError |
15 | 14 |
|
16 | 15 | from subliminal.cache import region as cache |
|
21 | 20 |
|
22 | 21 | from subliminal_patch.providers import Provider |
23 | 22 | from subliminal_patch.providers.mixins import ProviderSubtitleArchiveMixin |
| 23 | +from subliminal_patch.exceptions import TooManyRequests |
24 | 24 |
|
25 | 25 | from subliminal_patch.subtitle import Subtitle, guess_matches |
26 | 26 |
|
@@ -271,6 +271,8 @@ def get_request(self, url, ref=server_url, allow_redirects=False, _recursion=0): |
271 | 271 | def fetch_page(self, url, ref=server_url, allow_redirects=False): |
272 | 272 | res = self.get_request(url, ref=ref, allow_redirects=allow_redirects) |
273 | 273 |
|
| 274 | + if res.status_code == 429: |
| 275 | + raise TooManyRequests("Titulky.com: Too many requests, sleeping for 60 seconds.") |
274 | 276 | if res.status_code != 200: |
275 | 277 | raise HTTPError(f"Fetch failed with status code {res.status_code}") |
276 | 278 | if not res.text: |
@@ -512,6 +514,9 @@ def list_subtitles(self, video, languages): |
512 | 514 | def download_subtitle(self, subtitle): |
513 | 515 | res = self.get_request(subtitle.download_link, ref=subtitle.page_link) |
514 | 516 |
|
| 517 | + if res.status_code == 429: |
| 518 | + raise TooManyRequests("Titulky.com: Too many requests, sleeping for 60 seconds.") |
| 519 | + |
515 | 520 | try: |
516 | 521 | res.raise_for_status() |
517 | 522 | except: |
|
0 commit comments