mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-11 01:07:36 +08:00
core: update to subliminal_patch:head; addic7ed: fix captcha solving; fix getting show list
This commit is contained in:
parent
29b2660da8
commit
e452394841
2 changed files with 26 additions and 32 deletions
|
@ -28,7 +28,7 @@ from subliminal.utils import hash_napiprojekt, hash_opensubtitles, hash_shooter,
|
||||||
from subliminal.video import VIDEO_EXTENSIONS, Video, Episode, Movie
|
from subliminal.video import VIDEO_EXTENSIONS, Video, Episode, Movie
|
||||||
from subliminal.core import guessit, ProviderPool, io, is_windows_special_path, \
|
from subliminal.core import guessit, ProviderPool, io, is_windows_special_path, \
|
||||||
ThreadPoolExecutor, check_video
|
ThreadPoolExecutor, check_video
|
||||||
from subliminal_patch.exceptions import TooManyRequests, APIThrottled, ParseResponseError
|
from subliminal_patch.exceptions import TooManyRequests, APIThrottled
|
||||||
|
|
||||||
from subzero.language import Language, ENDSWITH_LANGUAGECODE_RE
|
from subzero.language import Language, ENDSWITH_LANGUAGECODE_RE
|
||||||
from scandir import scandir, scandir_generic as _scandir_generic
|
from scandir import scandir, scandir_generic as _scandir_generic
|
||||||
|
@ -280,14 +280,10 @@ class SZProviderPool(ProviderPool):
|
||||||
logger.debug("RAR Traceback: %s", traceback.format_exc())
|
logger.debug("RAR Traceback: %s", traceback.format_exc())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except (TooManyRequests, DownloadLimitExceeded, ServiceUnavailable, APIThrottled, ParseResponseError) as e:
|
except Exception as e:
|
||||||
self.throttle_callback(subtitle.provider_name, e)
|
|
||||||
self.discarded_providers.add(subtitle.provider_name)
|
|
||||||
return False
|
|
||||||
|
|
||||||
except:
|
|
||||||
logger.exception('Unexpected error in provider %r, Traceback: %s', subtitle.provider_name,
|
logger.exception('Unexpected error in provider %r, Traceback: %s', subtitle.provider_name,
|
||||||
traceback.format_exc())
|
traceback.format_exc())
|
||||||
|
self.throttle_callback(subtitle.provider_name, e)
|
||||||
self.discarded_providers.add(subtitle.provider_name)
|
self.discarded_providers.add(subtitle.provider_name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -611,16 +607,6 @@ def _search_external_subtitles(path, languages=None, only_one=False, scandir_gen
|
||||||
if adv_tag:
|
if adv_tag:
|
||||||
forced = "forced" in adv_tag
|
forced = "forced" in adv_tag
|
||||||
|
|
||||||
# extract the potential language code
|
|
||||||
try:
|
|
||||||
language_code = p_root.rsplit(".", 1)[1].replace('_', '-')
|
|
||||||
try:
|
|
||||||
Language.fromietf(language_code)
|
|
||||||
except:
|
|
||||||
language_code = None
|
|
||||||
except IndexError:
|
|
||||||
language_code = None
|
|
||||||
|
|
||||||
# remove possible language code for matching
|
# remove possible language code for matching
|
||||||
p_root_bare = ENDSWITH_LANGUAGECODE_RE.sub("", p_root)
|
p_root_bare = ENDSWITH_LANGUAGECODE_RE.sub("", p_root)
|
||||||
|
|
||||||
|
@ -633,19 +619,21 @@ def _search_external_subtitles(path, languages=None, only_one=False, scandir_gen
|
||||||
if match_strictness == "strict" or (match_strictness == "loose" and not filename_contains):
|
if match_strictness == "strict" or (match_strictness == "loose" and not filename_contains):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# default language is undefined
|
language = None
|
||||||
language = Language('und')
|
|
||||||
|
|
||||||
# attempt to parse
|
# extract the potential language code
|
||||||
if language_code:
|
try:
|
||||||
|
language_code = p_root.rsplit(".", 1)[1].replace('_', '-')
|
||||||
try:
|
try:
|
||||||
language = Language.fromietf(language_code)
|
language = Language.fromietf(language_code)
|
||||||
language.forced = forced
|
language.forced = forced
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.error('Cannot parse language code %r', language_code)
|
logger.error('Cannot parse language code %r', language_code)
|
||||||
language = None
|
language_code = None
|
||||||
|
except IndexError:
|
||||||
|
language_code = None
|
||||||
|
|
||||||
elif not language_code and only_one:
|
if not language and not language_code and only_one:
|
||||||
language = Language.rebuild(list(languages)[0], forced=forced)
|
language = Language.rebuild(list(languages)[0], forced=forced)
|
||||||
|
|
||||||
subtitles[p] = language
|
subtitles[p] = language
|
||||||
|
@ -875,6 +863,7 @@ def save_subtitles(file_path, subtitles, single=False, directory=None, chmod=Non
|
||||||
if content:
|
if content:
|
||||||
if os.path.exists(subtitle_path):
|
if os.path.exists(subtitle_path):
|
||||||
os.remove(subtitle_path)
|
os.remove(subtitle_path)
|
||||||
|
|
||||||
with open(subtitle_path, 'w') as f:
|
with open(subtitle_path, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
subtitle.storage_path = subtitle_path
|
subtitle.storage_path = subtitle_path
|
||||||
|
|
|
@ -10,7 +10,7 @@ from requests import Session
|
||||||
from subliminal.cache import region
|
from subliminal.cache import region
|
||||||
from subliminal.exceptions import DownloadLimitExceeded, AuthenticationError
|
from subliminal.exceptions import DownloadLimitExceeded, AuthenticationError
|
||||||
from subliminal.providers.addic7ed import Addic7edProvider as _Addic7edProvider, \
|
from subliminal.providers.addic7ed import Addic7edProvider as _Addic7edProvider, \
|
||||||
Addic7edSubtitle as _Addic7edSubtitle, ParserBeautifulSoup, show_cells_re
|
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
|
||||||
|
@ -19,6 +19,8 @@ from subzero.language import Language
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
show_cells_re = re.compile(b'<td class="(?:version|vr)">.*?</td>', re.DOTALL)
|
||||||
|
|
||||||
#: Series header parsing regex
|
#: Series header parsing regex
|
||||||
series_year_re = re.compile(r'^(?P<series>[ \w\'.:(),*&!?-]+?)(?: \((?P<year>\d{4})\))?$')
|
series_year_re = re.compile(r'^(?P<series>[ \w\'.:(),*&!?-]+?)(?: \((?P<year>\d{4})\))?$')
|
||||||
|
|
||||||
|
@ -103,11 +105,15 @@ class Addic7edProvider(_Addic7edProvider):
|
||||||
tries = 0
|
tries = 0
|
||||||
while tries < 3:
|
while tries < 3:
|
||||||
r = self.session.get(self.server_url + 'login.php', timeout=10, headers={"Referer": self.server_url})
|
r = self.session.get(self.server_url + 'login.php', timeout=10, headers={"Referer": self.server_url})
|
||||||
if "grecaptcha" in r.content:
|
if "g-recaptcha" in r.content or "grecaptcha" in r.content:
|
||||||
logger.info('Addic7ed: Solving captcha. This might take a couple of minutes, but should only '
|
logger.info('Addic7ed: Solving captcha. This might take a couple of minutes, but should only '
|
||||||
'happen once every so often')
|
'happen once every so often')
|
||||||
|
|
||||||
site_key = re.search(r'grecaptcha.execute\(\'(.+?)\',', r.content).group(1)
|
for g, s in (("g-recaptcha-response", r'g-recaptcha.+?data-sitekey=\"(.+?)\"'),
|
||||||
|
("recaptcha_response", r'grecaptcha.execute\(\'(.+?)\',')):
|
||||||
|
site_key = re.search(s, r.content).group(1)
|
||||||
|
if site_key:
|
||||||
|
break
|
||||||
if not site_key:
|
if not site_key:
|
||||||
logger.error("Addic7ed: Captcha site-key not found!")
|
logger.error("Addic7ed: Captcha site-key not found!")
|
||||||
return
|
return
|
||||||
|
@ -121,7 +127,7 @@ class Addic7edProvider(_Addic7edProvider):
|
||||||
if not result:
|
if not result:
|
||||||
raise Exception("Addic7ed: Couldn't solve captcha!")
|
raise Exception("Addic7ed: Couldn't solve captcha!")
|
||||||
|
|
||||||
data["recaptcha_response"] = result
|
data[g] = result
|
||||||
|
|
||||||
r = self.session.post(self.server_url + 'dologin.php', data, allow_redirects=False, timeout=10,
|
r = self.session.post(self.server_url + 'dologin.php', data, allow_redirects=False, timeout=10,
|
||||||
headers={"Referer": self.server_url + "login.php"})
|
headers={"Referer": self.server_url + "login.php"})
|
||||||
|
@ -129,12 +135,11 @@ class Addic7edProvider(_Addic7edProvider):
|
||||||
if "relax, slow down" in r.content:
|
if "relax, slow down" in r.content:
|
||||||
raise TooManyRequests(self.username)
|
raise TooManyRequests(self.username)
|
||||||
|
|
||||||
if r.status_code != 302:
|
if "Try again" in r.content or "Wrong password" in r.content:
|
||||||
if "User <b></b> doesn't exist" in r.content and tries <= 2:
|
raise AuthenticationError(self.username)
|
||||||
logger.info("Addic7ed: Error, trying again. (%s/%s)", tries+1, 3)
|
|
||||||
tries += 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
if r.status_code != 302:
|
||||||
|
logger.error("Addic7ed: Something went wrong when logging in")
|
||||||
raise AuthenticationError(self.username)
|
raise AuthenticationError(self.username)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue