diff --git a/docs/configuration.rst b/docs/configuration.rst index 651275c5..5077a5e5 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -457,13 +457,17 @@ Description extractor.*.cookies-update -------------------------- Type - ``bool`` + * ``bool`` + * |Path|_ Default ``true`` Description - If `extractor.*.cookies`_ specifies the |Path|_ of a cookies.txt - file and it can be opened and parsed without errors, - update its contents with cookies received during data extraction. + Export session cookies in cookies.txt format. + + * 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 diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 78760e0a..09737ef9 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -379,12 +379,22 @@ 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): - try: - with open(self._cookiefile, "w") as fp: - util.cookiestxt_store(fp, self._cookiejar) - except OSError as exc: - self.log.warning("cookies: %s", exc) + export = self.config("cookies-update", True) + if not export: + return + + if isinstance(export, str): + 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=""): """Update the session's cookiejar with 'cookies'"""