mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-03 05:25:28 +00:00
Fixed titrari provider to prevent abuse and throttle properly. #2709
This commit is contained in:
parent
43d9d43224
commit
9d62d84ef5
2 changed files with 12 additions and 3 deletions
|
@ -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(),
|
||||
|
|
|
@ -5,18 +5,18 @@ import os
|
|||
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 @@ class TitrariProvider(Provider, ProviderSubtitleArchiveMixin):
|
|||
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 @@ class TitrariProvider(Provider, ProviderSubtitleArchiveMixin):
|
|||
|
||||
ordered_subs = self.order(subtitles)
|
||||
|
||||
sleep(5) # prevent being blocked for too many requests
|
||||
|
||||
return ordered_subs
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in a new issue