Skip to content

Commit

Permalink
extend 'parent-metadata' functionality (#1687, #1651, #1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jul 14, 2021
1 parent 193401c commit e95f998
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
16 changes: 14 additions & 2 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,18 @@ def handle_queue(self, url, kwdict):
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
Expand Down

0 comments on commit e95f998

Please sign in to comment.