mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-27 01:57:33 +00:00
Fix for #1034.
This commit is contained in:
parent
d38cd38399
commit
e2b1726c87
3 changed files with 25 additions and 22 deletions
|
@ -5,6 +5,8 @@ import logging
|
||||||
import subliminal_patch
|
import subliminal_patch
|
||||||
import pretty
|
import pretty
|
||||||
import time
|
import time
|
||||||
|
import socket
|
||||||
|
import requests
|
||||||
|
|
||||||
from get_args import args
|
from get_args import args
|
||||||
from config import settings
|
from config import settings
|
||||||
|
@ -28,7 +30,7 @@ hours_until_end_of_day = time_until_end_of_day().seconds // 3600 + 1
|
||||||
|
|
||||||
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
|
VALID_THROTTLE_EXCEPTIONS = (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled,
|
||||||
ParseResponseError, IPAddressBlocked)
|
ParseResponseError, IPAddressBlocked)
|
||||||
VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled')
|
VALID_COUNT_EXCEPTIONS = ('TooManyRequests', 'ServiceUnavailable', 'APIThrottled', requests.Timeout, socket.timeout)
|
||||||
|
|
||||||
PROVIDER_THROTTLE_MAP = {
|
PROVIDER_THROTTLE_MAP = {
|
||||||
"default": {
|
"default": {
|
||||||
|
@ -37,6 +39,8 @@ PROVIDER_THROTTLE_MAP = {
|
||||||
ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
|
ServiceUnavailable: (datetime.timedelta(minutes=20), "20 minutes"),
|
||||||
APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
|
APIThrottled: (datetime.timedelta(minutes=10), "10 minutes"),
|
||||||
ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
|
ParseResponseError: (datetime.timedelta(hours=6), "6 hours"),
|
||||||
|
requests.Timeout: (datetime.timedelta(minutes=20), "20 minutes"),
|
||||||
|
socket.timeout: (datetime.timedelta(minutes=20), "20 minutes"),
|
||||||
},
|
},
|
||||||
"opensubtitles": {
|
"opensubtitles": {
|
||||||
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
|
TooManyRequests: (datetime.timedelta(hours=3), "3 hours"),
|
||||||
|
@ -48,7 +52,6 @@ PROVIDER_THROTTLE_MAP = {
|
||||||
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"),
|
IPAddressBlocked: (datetime.timedelta(hours=1), "1 hours"),
|
||||||
|
|
||||||
},
|
},
|
||||||
"titulky": {
|
"titulky": {
|
||||||
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours")
|
DownloadLimitExceeded: (datetime.timedelta(hours=3), "3 hours")
|
||||||
|
|
|
@ -114,10 +114,12 @@ class SZProviderPool(ProviderPool):
|
||||||
try:
|
try:
|
||||||
logger.info('Terminating provider %s', name)
|
logger.info('Terminating provider %s', name)
|
||||||
self.initialized_providers[name].terminate()
|
self.initialized_providers[name].terminate()
|
||||||
except (requests.Timeout, socket.timeout):
|
except (requests.Timeout, socket.timeout) as e:
|
||||||
logger.error('Provider %r timed out, improperly terminated', name)
|
logger.error('Provider %r timed out, improperly terminated', name)
|
||||||
except:
|
self.throttle_callback(name, e)
|
||||||
|
except Exception as e:
|
||||||
logger.exception('Provider %r terminated unexpectedly', name)
|
logger.exception('Provider %r terminated unexpectedly', name)
|
||||||
|
self.throttle_callback(name, e)
|
||||||
|
|
||||||
del self.initialized_providers[name]
|
del self.initialized_providers[name]
|
||||||
|
|
||||||
|
@ -189,8 +191,9 @@ class SZProviderPool(ProviderPool):
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
except (requests.Timeout, socket.timeout):
|
except (requests.Timeout, socket.timeout) as e:
|
||||||
logger.error('Provider %r timed out', provider)
|
logger.error('Provider %r timed out', provider)
|
||||||
|
self.throttle_callback(provider, e)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception('Unexpected error in provider %r: %s', provider, traceback.format_exc())
|
logger.exception('Unexpected error in provider %r: %s', provider, traceback.format_exc())
|
||||||
|
@ -269,10 +272,11 @@ class SZProviderPool(ProviderPool):
|
||||||
requests.exceptions.ProxyError,
|
requests.exceptions.ProxyError,
|
||||||
requests.exceptions.SSLError,
|
requests.exceptions.SSLError,
|
||||||
requests.Timeout,
|
requests.Timeout,
|
||||||
socket.timeout):
|
socket.timeout) as e:
|
||||||
logger.error('Provider %r connection error', subtitle.provider_name)
|
logger.error('Provider %r connection error', subtitle.provider_name)
|
||||||
|
self.throttle_callback(subtitle.provider_name, e)
|
||||||
|
|
||||||
except ResponseNotReady:
|
except ResponseNotReady as e:
|
||||||
logger.error('Provider %r response error, reinitializing', subtitle.provider_name)
|
logger.error('Provider %r response error, reinitializing', subtitle.provider_name)
|
||||||
try:
|
try:
|
||||||
self[subtitle.provider_name].terminate()
|
self[subtitle.provider_name].terminate()
|
||||||
|
@ -280,6 +284,7 @@ class SZProviderPool(ProviderPool):
|
||||||
except:
|
except:
|
||||||
logger.error('Provider %r reinitialization error: %s', subtitle.provider_name,
|
logger.error('Provider %r reinitialization error: %s', subtitle.provider_name,
|
||||||
traceback.format_exc())
|
traceback.format_exc())
|
||||||
|
self.throttle_callback(subtitle.provider_name, e)
|
||||||
|
|
||||||
except rarfile.BadRarFile:
|
except rarfile.BadRarFile:
|
||||||
logger.error('Malformed RAR file from provider %r, skipping subtitle.', subtitle.provider_name)
|
logger.error('Malformed RAR file from provider %r, skipping subtitle.', subtitle.provider_name)
|
||||||
|
|
|
@ -9,14 +9,13 @@ 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, ConnectTimeout
|
|
||||||
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, IPAddressBlocked
|
from subliminal_patch.exceptions import TooManyRequests
|
||||||
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
|
||||||
|
|
||||||
|
@ -92,19 +91,15 @@ 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):
|
||||||
try:
|
rr = self.session.get(self.server_url + 'panel.php', allow_redirects=False, timeout=10,
|
||||||
rr = self.session.get(self.server_url + 'panel.php', allow_redirects=False, timeout=10,
|
headers={"Referer": self.server_url})
|
||||||
headers={"Referer": self.server_url})
|
if rr.status_code == 302:
|
||||||
if rr.status_code == 302:
|
logger.info('Addic7ed: Login expired')
|
||||||
logger.info('Addic7ed: Login expired')
|
cache_region.delete("addic7ed_data")
|
||||||
cache_region.delete("addic7ed_data")
|
else:
|
||||||
else:
|
logger.info('Addic7ed: Re-using old login')
|
||||||
logger.info('Addic7ed: Re-using old login')
|
self.logged_in = True
|
||||||
self.logged_in = True
|
return True
|
||||||
return True
|
|
||||||
except (ConnectionError, ConnectTimeout) 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
|
||||||
|
|
Loading…
Reference in a new issue