update functions working with cookies.txt files

- rename
  - load_cookiestxt -> cookiestxt_load
  - save_cookiestxt -< cookiestxt_store
- in cookiestxt_load, add cookies directly to a cookie jar
  instead of storing them in a list first
- other unnoticeable performance increases
This commit is contained in:
Mike Fährmann
2022-05-06 13:21:29 +02:00
parent f190018e37
commit c4b9f7bab8
3 changed files with 21 additions and 20 deletions

View File

@@ -306,11 +306,10 @@ class Extractor():
cookiefile = util.expand_path(cookies)
try:
with open(cookiefile) as fp:
cookies = util.load_cookiestxt(fp)
util.cookiestxt_load(fp, self._cookiejar)
except Exception as exc:
self.log.warning("cookies: %s", exc)
else:
self._update_cookies(cookies)
self._cookiefile = cookiefile
else:
self.log.warning(
@@ -322,7 +321,7 @@ class Extractor():
if self._cookiefile and self.config("cookies-update", True):
try:
with open(self._cookiefile, "w") as fp:
util.save_cookiestxt(fp, self._cookiejar)
util.cookiestxt_store(fp, self._cookiejar)
except OSError as exc:
self.log.warning("cookies: %s", exc)