diff --git a/docs/configuration.rst b/docs/configuration.rst index a2b5a282..e34087d7 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -251,6 +251,25 @@ Description } +extractor.*.parent-session +-------------------------- +Type + ``bool`` +Default + ``true`` + ``[chevereto]`` | + ``[imagehost]`` + ``false`` + otherwise +Description + Share a parent's + `session `__ + with its child extractors, including + `cookies `__, + `headers `__, + and other networking settings. + + extractor.*.parent-skip ----------------------- Type diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 37ca8317..93efad8c 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -60,6 +60,7 @@ "parent-directory": false, "parent-metadata" : false, + "parent-session" : false, "parent-skip" : false, "path-restrict": "auto", @@ -1023,6 +1024,7 @@ "chevereto": { "parent-metadata": true, + "parent-session" : true, "password" : "" }, @@ -1097,7 +1099,8 @@ "imagehost": { - "parent-metadata": true + "parent-metadata": true, + "parent-session" : true }, "mastodon": diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index ede017f5..8255cd2b 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014-2025 Mike Fährmann +# Copyright 2014-2026 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -39,8 +39,10 @@ class Extractor(): archive_fmt = "" status = 0 root = "" - cookies_domain = "" + cookies_file = "" cookies_index = 0 + cookies_domain = "" + session = None referer = True ciphers = None tls12 = True @@ -85,8 +87,15 @@ class Extractor(): def initialize(self): self._init_options() - self._init_session() - self._init_cookies() + + if self.session is None: + self._init_session() + self.cookies = self.session.cookies + if self.cookies_domain is not None: + self._init_cookies() + else: + self.cookies = self.session.cookies + self._init() self.initialize = util.noop @@ -541,11 +550,6 @@ class Extractor(): def _init_cookies(self): """Populate the session's cookiejar""" - self.cookies = self.session.cookies - self.cookies_file = None - if self.cookies_domain is None: - return - if cookies := self.config("cookies"): if select := self.config("cookies-select"): if select == "rotate": diff --git a/gallery_dl/job.py b/gallery_dl/job.py index acec6997..3337bf07 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015-2025 Mike Fährmann +# Copyright 2015-2026 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -459,6 +459,9 @@ class DownloadJob(Job): if kwdict: job.kwdict.update(kwdict) + if pextr.config("parent-session", pextr.parent): + extr.session = pextr.session + while True: try: if pextr.config("parent-skip"):