[common] implement 'parent-session'

This commit is contained in:
Mike Fährmann
2026-01-21 19:45:28 +01:00
parent 9ca45aae73
commit 4798ac4836
4 changed files with 40 additions and 11 deletions

View File

@@ -251,6 +251,25 @@ Description
} }
extractor.*.parent-session
--------------------------
Type
``bool``
Default
``true``
``[chevereto]`` |
``[imagehost]``
``false``
otherwise
Description
Share a parent's
`session <https://requests.readthedocs.io/en/latest/user/advanced/#session-objects>`__
with its child extractors, including
`cookies <extractor.*.cookies_>`__,
`headers <extractor.*.headers_>`__,
and other networking settings.
extractor.*.parent-skip extractor.*.parent-skip
----------------------- -----------------------
Type Type

View File

@@ -60,6 +60,7 @@
"parent-directory": false, "parent-directory": false,
"parent-metadata" : false, "parent-metadata" : false,
"parent-session" : false,
"parent-skip" : false, "parent-skip" : false,
"path-restrict": "auto", "path-restrict": "auto",
@@ -1023,6 +1024,7 @@
"chevereto": "chevereto":
{ {
"parent-metadata": true, "parent-metadata": true,
"parent-session" : true,
"password" : "" "password" : ""
}, },
@@ -1097,7 +1099,8 @@
"imagehost": "imagehost":
{ {
"parent-metadata": true "parent-metadata": true,
"parent-session" : true
}, },
"mastodon": "mastodon":

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # it under the terms of the GNU General Public License version 2 as
@@ -39,8 +39,10 @@ class Extractor():
archive_fmt = "" archive_fmt = ""
status = 0 status = 0
root = "" root = ""
cookies_domain = "" cookies_file = ""
cookies_index = 0 cookies_index = 0
cookies_domain = ""
session = None
referer = True referer = True
ciphers = None ciphers = None
tls12 = True tls12 = True
@@ -85,8 +87,15 @@ class Extractor():
def initialize(self): def initialize(self):
self._init_options() 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._init()
self.initialize = util.noop self.initialize = util.noop
@@ -541,11 +550,6 @@ class Extractor():
def _init_cookies(self): def _init_cookies(self):
"""Populate the session's cookiejar""" """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 cookies := self.config("cookies"):
if select := self.config("cookies-select"): if select := self.config("cookies-select"):
if select == "rotate": if select == "rotate":

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # it under the terms of the GNU General Public License version 2 as
@@ -459,6 +459,9 @@ class DownloadJob(Job):
if kwdict: if kwdict:
job.kwdict.update(kwdict) job.kwdict.update(kwdict)
if pextr.config("parent-session", pextr.parent):
extr.session = pextr.session
while True: while True:
try: try:
if pextr.config("parent-skip"): if pextr.config("parent-skip"):