[pp:metadata] add 'metadata-path' option (#6582)
https://github.com/mikf/gallery-dl/issues/6582#issuecomment-2781643835
This commit is contained in:
@@ -6611,6 +6611,17 @@ Description
|
|||||||
Note: `metadata.extension`_ is ignored if this option is set.
|
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
|
metadata.event
|
||||||
--------------
|
--------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ class MetadataPP(PostProcessor):
|
|||||||
self.omode = options.get("open", omode)
|
self.omode = options.get("open", omode)
|
||||||
self.encoding = options.get("encoding", "utf-8")
|
self.encoding = options.get("encoding", "utf-8")
|
||||||
self.skip = options.get("skip", False)
|
self.skip = options.get("skip", False)
|
||||||
|
self.meta_path = options.get("metadata-path")
|
||||||
|
|
||||||
def run(self, pathfmt):
|
def run(self, pathfmt):
|
||||||
archive = self.archive
|
archive = self.archive
|
||||||
@@ -120,6 +121,9 @@ class MetadataPP(PostProcessor):
|
|||||||
directory = self._directory(pathfmt)
|
directory = self._directory(pathfmt)
|
||||||
path = directory + self._filename(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):
|
if self.skip and os.path.exists(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -555,6 +555,16 @@ class MetadataTest(BasePostprocessorTest):
|
|||||||
path = self.pathfmt.realdirectory + "test_file__meta_.data"
|
path = self.pathfmt.realdirectory + "test_file__meta_.data"
|
||||||
m.assert_called_once_with(path, "w", encoding="utf-8")
|
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):
|
def test_metadata_stdout(self):
|
||||||
self._create({"filename": "-", "indent": None, "sort": True})
|
self._create({"filename": "-", "indent": None, "sort": True})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user