From e78937a5803004c4c69a8da6c4e704a7b9f2dac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 27 Nov 2015 21:32:07 +0100 Subject: [PATCH] cache cookies from cloudflare-bypass --- gallery_dl/cloudflare.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gallery_dl/cloudflare.py b/gallery_dl/cloudflare.py index 53c039ad..fc4959bc 100644 --- a/gallery_dl/cloudflare.py +++ b/gallery_dl/cloudflare.py @@ -16,6 +16,9 @@ from . import text def bypass_ddos_protection(session, url): """Prepare a requests.session to access 'url' behind Cloudflare protection""" session.headers["Referer"] = url + if url in _cache: + session.cookies.update(_cache[url]) + return page = session.get(url).text params = text.extract_all(page, ( ('jschl_vc', 'name="jschl_vc" value="', '"'), @@ -24,6 +27,7 @@ def bypass_ddos_protection(session, url): params["jschl_answer"] = solve_jschl(url, page) time.sleep(4) session.get(urllib.parse.urljoin(url, "/cdn-cgi/l/chk_jschl"), params=params) + _cache[url] = session.cookies.copy() def solve_jschl(url, page): """Solve challenge to get 'jschl_answer' value""" @@ -75,3 +79,5 @@ expression_values = { "!+": 1, "+!!": 1, } + +_cache = {}