1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-28 02:27:28 +00:00

Merge pull request #971 from redglory/development

Throttle connections to Addic7ed provider throwing IPAddressBlocked
This commit is contained in:
morpheus65535 2020-05-08 07:41:57 -04:00 committed by GitHub
commit 1aa06630bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -44,6 +44,8 @@ PROVIDER_THROTTLE_MAP = {
"addic7ed": { "addic7ed": {
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"), DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours"),
TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"), TooManyRequests: (datetime.timedelta(minutes=5), "5 minutes"),
IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
}, },
"titulky": { "titulky": {
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours") DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours")

View file

@ -9,13 +9,14 @@ from random import randint
from dogpile.cache.api import NO_VALUE from dogpile.cache.api import NO_VALUE
from requests import Session from requests import Session
from requests.exceptions import ConnectionError
from subliminal.cache import region from subliminal.cache import region
from subliminal.exceptions import DownloadLimitExceeded, AuthenticationError, ConfigurationError from subliminal.exceptions import DownloadLimitExceeded, AuthenticationError, ConfigurationError
from subliminal.providers.addic7ed import Addic7edProvider as _Addic7edProvider, \ from subliminal.providers.addic7ed import Addic7edProvider as _Addic7edProvider, \
Addic7edSubtitle as _Addic7edSubtitle, ParserBeautifulSoup Addic7edSubtitle as _Addic7edSubtitle, ParserBeautifulSoup
from subliminal.subtitle import fix_line_ending from subliminal.subtitle import fix_line_ending
from subliminal_patch.utils import sanitize from subliminal_patch.utils import sanitize
from subliminal_patch.exceptions import TooManyRequests from subliminal_patch.exceptions import TooManyRequests, IPAddressBlocked
from subliminal_patch.pitcher import pitchers, load_verification, store_verification from subliminal_patch.pitcher import pitchers, load_verification, store_verification
from subzero.language import Language from subzero.language import Language
@ -91,15 +92,19 @@ class Addic7edProvider(_Addic7edProvider):
# login # login
if self.username and self.password: if self.username and self.password:
def check_verification(cache_region): def check_verification(cache_region):
rr = self.session.get(self.server_url + 'panel.php', allow_redirects=False, timeout=10, try:
headers={"Referer": self.server_url}) rr = self.session.get(self.server_url + 'panel.php', allow_redirects=False, timeout=10,
if rr.status_code == 302: headers={"Referer": self.server_url})
logger.info('Addic7ed: Login expired') if rr.status_code == 302:
cache_region.delete("addic7ed_data") logger.info('Addic7ed: Login expired')
else: cache_region.delete("addic7ed_data")
logger.info('Addic7ed: Re-using old login') else:
self.logged_in = True logger.info('Addic7ed: Re-using old login')
return True self.logged_in = True
return True
except ConnectionError as e:
logger.debug("Addic7ed: There was a problem reaching the server: %s." % e)
raise IPAddressBlocked("Addic7ed: Your IP is temporarily blocked.")
if load_verification("addic7ed", self.session, callback=check_verification): if load_verification("addic7ed", self.session, callback=check_verification):
return return