1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

detect Cloudflare CAPTCHAs and update cipher list

This commit is contained in:
Mike Fährmann 2019-07-09 23:07:55 +02:00
parent a7b42b37a2
commit 56c7a66a4a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 13 additions and 10 deletions

View File

@ -22,6 +22,7 @@ Optional
- FFmpeg_: Pixiv Ugoira to WebM conversion - FFmpeg_: Pixiv Ugoira to WebM conversion
- youtube-dl_: Video downloads - youtube-dl_: Video downloads
- pyOpenSSL_: Access Cloudflare protected sites
Installation Installation
@ -231,6 +232,7 @@ access to *gallery-dl*. Authorize it and you will be shown one or more
.. _Requests: http://docs.python-requests.org/en/master/ .. _Requests: http://docs.python-requests.org/en/master/
.. _FFmpeg: https://www.ffmpeg.org/ .. _FFmpeg: https://www.ffmpeg.org/
.. _youtube-dl: https://ytdl-org.github.io/youtube-dl/ .. _youtube-dl: https://ytdl-org.github.io/youtube-dl/
.. _pyOpenSSL: https://pyopenssl.org/
.. _Snapd: https://docs.snapcraft.io/installing-snapd .. _Snapd: https://docs.snapcraft.io/installing-snapd
.. _OAuth: https://en.wikipedia.org/wiki/OAuth .. _OAuth: https://en.wikipedia.org/wiki/OAuth

View File

@ -99,6 +99,14 @@ class Extractor():
session, response, kwargs) session, response, kwargs)
cloudflare.cookies.update(self.category, (domain, cookies)) cloudflare.cookies.update(self.category, (domain, cookies))
continue continue
if cloudflare.is_captcha(response):
try:
import OpenSSL # noqa
except ImportError:
msg = " - Install 'pyOpenSSL' and try again"
else:
msg = ""
self.log.warning("Cloudflare CAPTCHA" + msg)
msg = "{}: {} for url: {}".format(code, response.reason, url) msg = "{}: {} for url: {}".format(code, response.reason, url)
if code < 500 and code != 429 and code != 430: if code < 500 and code != 429 and code != 430:
@ -409,15 +417,10 @@ def generate_extractors(extractor_data, symtable, classes):
http.cookiejar.MozillaCookieJar.magic_re = re.compile( http.cookiejar.MozillaCookieJar.magic_re = re.compile(
"#( Netscape)? HTTP Cookie File", re.IGNORECASE) "#( Netscape)? HTTP Cookie File", re.IGNORECASE)
# Update default cipher list of urllib3 # Update default cipher list of urllib3 to avoid Cloudflare CAPTCHAs
# to fix issues with Cloudflare and, by extension, Artstation (#227) # List taken from urllib3 1.25:
from requests.packages.urllib3.util import ssl_ # noqa
logging.getLogger("gallery-dl").debug("updating default urllib3 ciphers")
# cipher list taken from urllib3 1.25
# https://github.com/urllib3/urllib3/blob/1.25/src/urllib3/util/ssl_.py # https://github.com/urllib3/urllib3/blob/1.25/src/urllib3/util/ssl_.py
# with additions from from requests.packages.urllib3.util import ssl_ # noqa
# https://github.com/Anorov/cloudflare-scrape/pull/242
ssl_.DEFAULT_CIPHERS = ( ssl_.DEFAULT_CIPHERS = (
"ECDHE+AESGCM:" "ECDHE+AESGCM:"
"ECDHE+CHACHA20:" "ECDHE+CHACHA20:"
@ -429,8 +432,6 @@ ssl_.DEFAULT_CIPHERS = (
"DH+AES:" "DH+AES:"
"RSA+AESGCM:" "RSA+AESGCM:"
"RSA+AES:" "RSA+AES:"
"!ECDHE+SHA:"
"!AES128-SHA:"
"!aNULL:" "!aNULL:"
"!eNULL:" "!eNULL:"
"!MD5:" "!MD5:"