extend 'cookies-update' functionality
Allow writing cookies to a different file than a given cookies.txt,
making it possible to export cookies imported with --cookies-from-browser
To convert browser cookies to cookies.txt format:
gallery-dl --cookies-fr chromium \
-o cookies-update=cookies.txt \
--no-download \
http://example.org/file.jpg
This commit is contained in:
@@ -457,13 +457,17 @@ Description
|
|||||||
extractor.*.cookies-update
|
extractor.*.cookies-update
|
||||||
--------------------------
|
--------------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
* ``bool``
|
||||||
|
* |Path|_
|
||||||
Default
|
Default
|
||||||
``true``
|
``true``
|
||||||
Description
|
Description
|
||||||
If `extractor.*.cookies`_ specifies the |Path|_ of a cookies.txt
|
Export session cookies in cookies.txt format.
|
||||||
file and it can be opened and parsed without errors,
|
|
||||||
update its contents with cookies received during data extraction.
|
* If this is a |Path|_, write cookies to the given file path.
|
||||||
|
|
||||||
|
* If this is ``true`` and `extractor.*.cookies`_ specifies the |Path|_
|
||||||
|
of a valid cookies.txt file, update its contents.
|
||||||
|
|
||||||
|
|
||||||
extractor.*.proxy
|
extractor.*.proxy
|
||||||
|
|||||||
@@ -379,12 +379,22 @@ class Extractor():
|
|||||||
|
|
||||||
def _store_cookies(self):
|
def _store_cookies(self):
|
||||||
"""Store the session's cookiejar in a cookies.txt file"""
|
"""Store the session's cookiejar in a cookies.txt file"""
|
||||||
if self._cookiefile and self.config("cookies-update", True):
|
export = self.config("cookies-update", True)
|
||||||
try:
|
if not export:
|
||||||
with open(self._cookiefile, "w") as fp:
|
return
|
||||||
util.cookiestxt_store(fp, self._cookiejar)
|
|
||||||
except OSError as exc:
|
if isinstance(export, str):
|
||||||
self.log.warning("cookies: %s", exc)
|
path = util.expand_path(export)
|
||||||
|
else:
|
||||||
|
path = self._cookiefile
|
||||||
|
if not path:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(path, "w") as fp:
|
||||||
|
util.cookiestxt_store(fp, self._cookiejar)
|
||||||
|
except OSError as exc:
|
||||||
|
self.log.warning("cookies: %s", exc)
|
||||||
|
|
||||||
def _update_cookies(self, cookies, domain=""):
|
def _update_cookies(self, cookies, domain=""):
|
||||||
"""Update the session's cookiejar with 'cookies'"""
|
"""Update the session's cookiejar with 'cookies'"""
|
||||||
|
|||||||
Reference in New Issue
Block a user