1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

[postprocessor:metadata] assume 'mode: custom' when format is set

{"name": "metadata", "format": "foobar"}
will now implicitly use mode:custom and no longer mode:json like before
This commit is contained in:
Mike Fährmann 2022-10-04 17:53:04 +02:00
parent f0321f423d
commit b57015cf0a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 9 additions and 8 deletions

View File

@ -20,14 +20,8 @@ class MetadataPP(PostProcessor):
PostProcessor.__init__(self, job)
mode = options.get("mode", "json")
if mode == "custom":
self.write = self._write_custom
cfmt = options.get("content-format") or options.get("format")
if isinstance(cfmt, list):
cfmt = "\n".join(cfmt) + "\n"
self._content_fmt = formatter.parse(cfmt).format_map
ext = "txt"
elif mode == "tags":
cfmt = options.get("content-format") or options.get("format")
if mode == "tags":
self.write = self._write_tags
ext = "txt"
elif mode == "modify":
@ -41,6 +35,12 @@ class MetadataPP(PostProcessor):
self.run = self._run_delete
self.fields = options.get("fields")
ext = None
elif mode == "custom" or cfmt:
self.write = self._write_custom
if isinstance(cfmt, list):
cfmt = "\n".join(cfmt) + "\n"
self._content_fmt = formatter.parse(cfmt).format_map
ext = "txt"
else:
self.write = self._write_json
self.indent = options.get("indent", 4)

View File

@ -267,6 +267,7 @@ class MetadataTest(BasePostprocessorTest):
test({"mode": "custom", "content-format": "{foo}\n{missing}\n"})
test({"mode": "custom", "content-format": ["{foo}", "{missing}"]})
test({"mode": "custom", "format": "{foo}\n{missing}\n"})
test({"format": "{foo}\n{missing}\n"})
def test_metadata_extfmt(self):
pp = self._create({