1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-01-23 14:47:49 +08:00

+ Check is sove proces was OK

* Change some errors to ExtractorError
This commit is contained in:
bato3 2018-07-31 15:19:32 +02:00
parent 1e77c43688
commit 1659616492
2 changed files with 11 additions and 6 deletions

View File

@ -2827,7 +2827,7 @@ class InfoExtractor(object):
try: try:
js = re.search(r"setTimeout\(function\(\){\s+(var s,t,o,p,b,r,e,a,k,i,n,g,f.+?\r?\n[\s\S]+?a\.value =.+?)\r?\n", body).group(1) js = re.search(r"setTimeout\(function\(\){\s+(var s,t,o,p,b,r,e,a,k,i,n,g,f.+?\r?\n[\s\S]+?a\.value =.+?)\r?\n", body).group(1)
except Exception: except Exception:
raise ValueError("Unable to identify Cloudflare IUAM Javascript on website.") raise ExtractorError("Unable to identify Cloudflare IUAM Javascript on website.")
js = re.sub(r"a\.value = (.+ \+ t\.length).+", r"\1", js) js = re.sub(r"a\.value = (.+ \+ t\.length).+", r"\1", js)
js = re.sub(r"\s{3,}[a-z](?: = |\.).+", "", js).replace("t.length", str(len(domain))) js = re.sub(r"\s{3,}[a-z](?: = |\.).+", "", js).replace("t.length", str(len(domain)))
@ -2837,7 +2837,7 @@ class InfoExtractor(object):
js = re.sub(r"[\n\\']", "", js) js = re.sub(r"[\n\\']", "", js)
if "toFixed" not in js: if "toFixed" not in js:
raise ValueError("Error parsing Cloudflare IUAM Javascript challenge.") raise ExtractorError("Error parsing Cloudflare IUAM Javascript challenge.")
# Use vm.runInNewContext to safely evaluate code # Use vm.runInNewContext to safely evaluate code
# The sandboxed code cannot use the Node.js standard library # The sandboxed code cannot use the Node.js standard library
@ -2848,7 +2848,7 @@ class InfoExtractor(object):
result = subprocess.check_output(["node", "-e", js]).strip() result = subprocess.check_output(["node", "-e", js]).strip()
except OSError as e: except OSError as e:
if e.errno == 2: if e.errno == 2:
raise EnvironmentError("Missing Node.js runtime. Node is required and must be in the PATH (check with `node -v`). Your Node binary may be called `nodejs` rather than `node`, in which case you may need to run `apt-get install nodejs-legacy` on some Debian-based systems. (Please read the cfscrape README's Dependencies section: https://github.com/Anorov/cloudflare-scrape#dependencies.") raise ExtractorError("Missing Node.js runtime. Node is required and must be in the PATH (check with `node -v`). Your Node binary may be called `nodejs` rather than `node`, in which case you may need to run `apt-get install nodejs-legacy` on some Debian-based systems. (Please read the cfscrape README's Dependencies section: https://github.com/Anorov/cloudflare-scrape#dependencies.")
raise raise
except Exception: except Exception:
self.to_screen("Error executing Cloudflare IUAM Javascript.") self.to_screen("Error executing Cloudflare IUAM Javascript.")
@ -2857,12 +2857,15 @@ class InfoExtractor(object):
try: try:
float(result) float(result)
except Exception: except Exception:
raise ValueError("Cloudflare IUAM challenge returned unexpected answer.") raise ExtractorError("Cloudflare IUAM challenge returned unexpected answer.")
return result return result
def has_cf_challenge(self, html):
return True if '/cdn-cgi/l/chk_jschl' in html else False
def cf_solve_and_download_webpage(self, html, download_url): def cf_solve_and_download_webpage(self, html, download_url):
if '/cdn-cgi/l/chk_jschl' not in html: if not self.has_cf_challenge(html):
return False return False
parsed_url = compat_urlparse.urlparse(download_url) parsed_url = compat_urlparse.urlparse(download_url)
domain = parsed_url.netloc domain = parsed_url.netloc

View File

@ -76,7 +76,9 @@ class CrunchyrollBaseIE(InfoExtractor):
if cf_page: if cf_page:
login_page = cf_page login_page = cf_page
if is_logged(cf_page): if is_logged(cf_page):
login_page = self._download_webpage(self._PROFILE_URL, None, 'Get new CSRF Token') login_page = self._download_webpage(self._PROFILE_URL, None, 'Get new CSRF Token', expected_status=503)
if self.has_cf_challenge(login_page):
raise ExtractorError('Cloudflare challenge still is present, try run again', expected=True)
if is_logged(login_page): if is_logged(login_page):
return return