summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/common.py')
-rw-r--r--gallery_dl/extractor/common.py39
1 files changed, 19 insertions, 20 deletions
diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py
index 55b15d4..19ee182 100644
--- a/gallery_dl/extractor/common.py
+++ b/gallery_dl/extractor/common.py
@@ -16,7 +16,6 @@ import logging
import datetime
import requests
import threading
-import http.cookiejar
from .message import Message
from .. import config, text, util, exception, cloudflare
@@ -40,6 +39,7 @@ class Extractor():
self._cookiefile = None
self._cookiejar = self.session.cookies
+ self._parentdir = ""
self._retries = self.config("retries", 4)
self._timeout = self.config("timeout", 30)
self._verify = self.config("verify", True)
@@ -197,13 +197,13 @@ class Extractor():
self._update_cookies_dict(cookies, self.cookiedomain)
elif isinstance(cookies, str):
cookiefile = util.expand_path(cookies)
- cookiejar = http.cookiejar.MozillaCookieJar()
try:
- cookiejar.load(cookiefile)
- except OSError as exc:
+ with open(cookiefile) as fp:
+ cookies = util.load_cookiestxt(fp)
+ except Exception as exc:
self.log.warning("cookies: %s", exc)
else:
- self._cookiejar.update(cookiejar)
+ self._update_cookies(cookies)
self._cookiefile = cookiefile
else:
self.log.warning(
@@ -218,11 +218,9 @@ class Extractor():
def _store_cookies(self):
"""Store the session's cookiejar in a cookies.txt file"""
if self._cookiefile and self.config("cookies-update", True):
- cookiejar = http.cookiejar.MozillaCookieJar()
- for cookie in self._cookiejar:
- cookiejar.set_cookie(cookie)
try:
- cookiejar.save(self._cookiefile)
+ with open(self._cookiefile, "w") as fp:
+ util.save_cookiestxt(fp, self._cookiejar)
except OSError as exc:
self.log.warning("cookies: %s", exc)
@@ -248,15 +246,22 @@ class Extractor():
def _check_cookies(self, cookienames, *, domain=None):
"""Check if all 'cookienames' are in the session's cookiejar"""
+ if not self._cookiejar:
+ return False
+
if domain is None:
domain = self.cookiedomain
-
names = set(cookienames)
+ now = time.time()
+
for cookie in self._cookiejar:
- if cookie.domain == domain:
- names.discard(cookie.name)
- if not names:
- return True
+ if cookie.name in names and cookie.domain == domain:
+ if cookie.expires and cookie.expires < now:
+ self.log.warning("Cookie '%s' has expired", cookie.name)
+ else:
+ names.discard(cookie.name)
+ if not names:
+ return True
return False
def _get_date_min_max(self, dmin=None, dmax=None):
@@ -491,12 +496,6 @@ def generate_extractors(extractor_data, symtable, classes):
symtable[Extr.__name__] = prev = Extr
-# Reduce strictness of the expected magic string in cookiejar files.
-# (This allows the use of Wget-generated cookiejars without modification)
-http.cookiejar.MozillaCookieJar.magic_re = re.compile(
- "#( Netscape)? HTTP Cookie File", re.IGNORECASE)
-
-
# Undo automatic pyOpenSSL injection by requests
pyopenssl = config.get((), "pyopenssl", False)
if not pyopenssl: