From e95f99882fdc6d85154311c62bd5034b2aec8f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 13 Jul 2021 02:04:59 +0200 Subject: [PATCH] extend 'parent-metadata' functionality (#1687, #1651, #1364) --- docs/configuration.rst | 16 ++++++++++++++-- gallery_dl/job.py | 17 ++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index af37d4cc..4ec4b314 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -165,11 +165,23 @@ Description extractor.*.parent-metadata --------------------------- Type - ``bool`` + ``bool`` or ``string`` Default ``false`` Description - Overwrite any metadata provided by a child extractor with its parent's. + If ``true``, overwrite any metadata provided by a child extractor + with its parent's. + + | If this is a ``string``, add a parent's metadata to its children's + to a field named after said string. + | For example with ``"parent-metadata": "_p_"``: + + .. code:: json + + { + "id": "child-id", + "_p_": {"id": "parent-id"} + } extractor.*.parent-skip diff --git a/gallery_dl/job.py b/gallery_dl/job.py index e515eff7..4d3a1e80 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -302,11 +302,18 @@ class DownloadJob(Job): else: extr._parentdir = pextr._parentdir - if pextr.config("parent-metadata"): - if self.kwdict: - job.kwdict.update(self.kwdict) - if kwdict: - job.kwdict.update(kwdict) + pmeta = pextr.config("parent-metadata") + if pmeta: + if isinstance(pmeta, str): + data = self.kwdict.copy() + if kwdict: + data.update(kwdict) + job.kwdict[pmeta] = data + else: + if self.kwdict: + job.kwdict.update(self.kwdict) + if kwdict: + job.kwdict.update(kwdict) if pextr.config("parent-skip"): job._skipcnt = self._skipcnt