diff --git a/docs/configuration.rst b/docs/configuration.rst index 5c452606..1ad5e661 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -6611,6 +6611,17 @@ Description Note: `metadata.extension`_ is ignored if this option is set. +metadata.metadata-path +---------------------- +Type + ``string`` +Example + ``"_meta_path"`` +Description + Insert the path of generated files + into metadata dictionaries as the given name. + + metadata.event -------------- Type diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index cb6fac29..fbb3fb80 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -108,6 +108,7 @@ class MetadataPP(PostProcessor): self.omode = options.get("open", omode) self.encoding = options.get("encoding", "utf-8") self.skip = options.get("skip", False) + self.meta_path = options.get("metadata-path") def run(self, pathfmt): archive = self.archive @@ -120,6 +121,9 @@ class MetadataPP(PostProcessor): directory = self._directory(pathfmt) path = directory + self._filename(pathfmt) + if self.meta_path is not None: + pathfmt.kwdict[self.meta_path] = path + if self.skip and os.path.exists(path): return diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index d3bff4a0..8b073b4c 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -555,6 +555,16 @@ class MetadataTest(BasePostprocessorTest): path = self.pathfmt.realdirectory + "test_file__meta_.data" m.assert_called_once_with(path, "w", encoding="utf-8") + def test_metadata_meta_path(self): + self._create({ + "metadata-path": "_meta_path", + }) + + self._trigger() + + self.assertEqual(self.pathfmt.kwdict["_meta_path"], + self.pathfmt.realpath + ".json") + def test_metadata_stdout(self): self._create({"filename": "-", "indent": None, "sort": True})