From df94182e11ff75302bc7442bdf3f8dea709b7f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 11 Mar 2021 01:10:34 +0100 Subject: [PATCH] implement 'parent-metadata' option (#1364) experimental, might not work as expected, etc. --- docs/configuration.rst | 10 ++++++++++ gallery_dl/job.py | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 266a309f..7a988e1b 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -133,6 +133,16 @@ Description for any spawned child extractors. +extractor.*.parent-metadata +--------------------------- +Type + ``bool`` +Default + ``false`` +Description + Overwrite any metadata provided by a child extractor with its parent's. + + extractor.*.path-restrict ------------------------- Type diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 752de44a..eae7bcb9 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -42,7 +42,14 @@ class Job(): self.status = 0 self.pred_url = self._prepare_predicates("image", True) self.pred_queue = self._prepare_predicates("chapter", False) + self.kwdict = {} + # user-supplied metadata + kwdict = self.extractor.config("keywords") + if kwdict: + self.kwdict.update(kwdict) + + # data from parent job if parent: pextr = parent.extractor @@ -57,9 +64,6 @@ class Job(): # reuse connection adapters extr.session.adapters = pextr.session.adapters - # user-supplied metadata - self.userkwds = self.extractor.config("keywords") - def run(self): """Execute or run the job""" sleep = self.extractor.config("sleep-extractor") @@ -137,8 +141,8 @@ class Job(): extr = self.extractor kwdict["category"] = extr.category kwdict["subcategory"] = extr.subcategory - if self.userkwds: - kwdict.update(self.userkwds) + if self.kwdict: + kwdict.update(self.kwdict) def _prepare_predicates(self, target, skip=True): predicates = [] @@ -183,7 +187,7 @@ class Job(): class DownloadJob(Job): """Download images into appropriate directory/filename locations""" - def __init__(self, url, parent=None): + def __init__(self, url, parent=None, kwdict=None): Job.__init__(self, url, parent) self.log = self.get_logger("download") self.blacklist = None @@ -198,6 +202,8 @@ class DownloadJob(Job): pfmt = parent.pathfmt if pfmt and parent.extractor.config("parent-directory"): self.extractor._parentdir = pfmt.directory + if kwdict and parent.extractor.config("parent-metadata"): + self.kwdict.update(kwdict) else: self.visited = set() @@ -291,7 +297,7 @@ class DownloadJob(Job): extr = None if extr: - self.status |= self.__class__(extr, self).run() + self.status |= self.__class__(extr, self, kwdict).run() else: self._write_unsupported(url)