[job] apply 'keywords-eval' to 'keywords-global' values (#6582)

https://github.com/mikf/gallery-dl/issues/6582#issuecomment-3527246051
This commit is contained in:
Mike Fährmann
2025-11-13 20:29:31 +01:00
parent e840e3c680
commit 5cda64c8d8
2 changed files with 21 additions and 14 deletions

View File

@@ -976,8 +976,11 @@ Type
Default
``false``
Description
Evaluate each `keywords <extractor.*.keywords_>`__ ``string`` value
as a `Format String`_.
Evaluate each
`keywords <extractor.*.keywords_>`__
and
`keywords-global <extractor.*.keywords-global_>`__
``string`` value as a `Format String`_.
extractor.*.keywords-global
@@ -9653,6 +9656,7 @@ Reference
.. |open()| replace:: the built-in ``open()`` function
.. |json.dump()| replace:: ``json.dump()``
.. |ISO 639-1| replace:: `ISO 639-1 <https://en.wikipedia.org/wiki/ISO_639-1>`__ language
.. |ISO 8601| replace:: `ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601>`__ language
.. _directory: `extractor.*.directory`_
.. _base-directory: `extractor.*.base-directory`_

View File

@@ -87,19 +87,22 @@ class Job():
"current_git_head": util.git_head()
}
# user-supplied metadata
if kwdict := extr.config("keywords-global"):
kwdict = extr.config("keywords")
if kwdict_global := extr.config("keywords-global"):
kwdict = {**kwdict_global, **kwdict} if kwdict else kwdict_global
elif not kwdict:
return
if extr.config("keywords-eval"):
self.kwdict_eval = []
for key, value in kwdict.items():
if isinstance(value, str):
fmt = formatter.parse(value, None, util.identity)
self.kwdict_eval.append((key, fmt.format_map))
else:
self.kwdict[key] = value
else:
self.kwdict.update(kwdict)
if kwdict := extr.config("keywords"):
if extr.config("keywords-eval"):
self.kwdict_eval = []
for key, value in kwdict.items():
if isinstance(value, str):
fmt = formatter.parse(value, None, util.identity)
self.kwdict_eval.append((key, fmt.format_map))
else:
self.kwdict[key] = value
else:
self.kwdict.update(kwdict)
def _build_config_path(self, parent):
extr = self.extractor