From 34a387b6e2159fa3692df282fdfe81d1524f2971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 18 Nov 2023 23:43:40 +0100 Subject: [PATCH] support 'metadata-*' names for '*-metadata' options For example, instead of 'url-metadata' it is now also possible to use 'metadata-url' as option name. - metadata-url - metadata-path - metadata-http - metadata-version - metadata-parent --- docs/configuration.rst | 18 ++++++++++-------- gallery_dl/extractor/common.py | 6 ++++++ gallery_dl/job.py | 15 +++++++-------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index c22bd8c2..b0d09b7f 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -166,6 +166,8 @@ Description extractor.*.parent-metadata --------------------------- +extractor.*.metadata-parent +--------------------------- Type * ``bool`` * ``string`` @@ -642,12 +644,12 @@ Description `format strings`_. +extractor.*.metadata-url +------------------------ extractor.*.url-metadata ------------------------ Type ``string`` -Default - ``null`` Description Insert a file's download URL into its metadata dictionary as the given name. @@ -658,12 +660,12 @@ Description with a ``metadata`` post processor, etc. +extractor.*.metadata-path +------------------------- extractor.*.path-metadata ------------------------- Type ``string`` -Default - ``null`` Description Insert a reference to the current `PathFormat `__ @@ -673,12 +675,12 @@ Description to access the current file's filename as ``"{gdl_path.filename}"``. +extractor.*.metadata-http +------------------------- extractor.*.http-metadata ------------------------- Type ``string`` -Default - ``null`` Description Insert an ``object`` containing a file's HTTP headers and ``filename``, ``extension``, and ``date`` parsed from them @@ -689,12 +691,12 @@ Description and its parsed form as ``"{gdl_http[date]}"``. +extractor.*.metadata-version +---------------------------- extractor.*.version-metadata ---------------------------- Type ``string`` -Default - ``null`` Description Insert an ``object`` containing gallery-dl's version info into metadata dictionaries as the given name. diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 3bec4248..f3784272 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -78,6 +78,12 @@ class Extractor(): def config(self, key, default=None): return config.interpolate(self._cfgpath, key, default) + def config2(self, key, key2, default=None, sentinel=util.SENTINEL): + value = self.config(key, sentinel) + if value is not sentinel: + return value + return self.config(key2, default) + def config_deprecated(self, key, deprecated, default=None, sentinel=util.SENTINEL, history=set()): value = self.config(deprecated, sentinel) diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 1e80cbf3..9aad226f 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -87,11 +87,10 @@ class Job(): extr.category = pextr.category extr.subcategory = pextr.subcategory - self.metadata_url = extr.config("url-metadata") - self.metadata_http = extr.config("http-metadata") - - version_info = extr.config("version-metadata") - metadata_path = extr.config("path-metadata") + self.metadata_url = extr.config2("metadata-url", "url-metadata") + self.metadata_http = extr.config2("metadata-http", "http-metadata") + metadata_path = extr.config2("metadata-path", "path-metadata") + metadata_version = extr.config2("metadata-version", "version-metadata") # user-supplied metadata kwdict = extr.config("keywords") @@ -99,8 +98,8 @@ class Job(): self.kwdict.update(kwdict) if metadata_path: self.kwdict[metadata_path] = path_proxy - if version_info: - self.kwdict[version_info] = { + if metadata_version: + self.kwdict[metadata_version] = { "version" : version.__version__, "is_executable" : util.EXECUTABLE, "current_git_head": util.git_head() @@ -375,7 +374,7 @@ class DownloadJob(Job): else: extr._parentdir = pextr._parentdir - pmeta = pextr.config("parent-metadata") + pmeta = pextr.config2("parent-metadata", "metadata-parent") if pmeta: if isinstance(pmeta, str): data = self.kwdict.copy()