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

[postprocessor:metadata] accept a string-list for 'content-format'

(closes #1080)
This commit is contained in:
Mike Fährmann 2020-10-27 20:09:58 +01:00
parent 198c33ec36
commit d83b95fd28
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 18 additions and 13 deletions

View File

@ -2053,9 +2053,10 @@ Description
metadata.content-format
-----------------------
Type
``string``
``string`` or ``list`` of ``strings``
Example
``"tags:\n\n{tags:J\n}\n"``
* ``"tags:\n\n{tags:J\n}\n"``
* ``["tags:", "", "{tags:J\n}"]``
Description
Custom format string to build the content of metadata files with.

View File

@ -22,6 +22,8 @@ class MetadataPP(PostProcessor):
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.contentfmt = util.Formatter(cfmt).format_map
ext = "txt"
elif mode == "tags":

View File

@ -235,18 +235,20 @@ class MetadataTest(BasePostprocessorTest):
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
def test_metadata_custom(self):
pp = self._create(
{"mode": "custom", "format": "{foo}\n{missing}\n"},
{"foo": "bar"},
)
self.assertEqual(pp.write, pp._write_custom)
self.assertEqual(pp.extension, "txt")
self.assertTrue(pp.contentfmt)
def test(pp_info):
pp = self._create(pp_info, {"foo": "bar"})
self.assertEqual(pp.write, pp._write_custom)
self.assertEqual(pp.extension, "txt")
self.assertTrue(pp.contentfmt)
with patch("builtins.open", mock_open()) as m:
pp.prepare(self.pathfmt)
pp.run(self.pathfmt)
self.assertEqual(self._output(m), "bar\nNone\n")
with patch("builtins.open", mock_open()) as m:
pp.prepare(self.pathfmt)
pp.run(self.pathfmt)
self.assertEqual(self._output(m), "bar\nNone\n")
test({"mode": "custom", "content-format": "{foo}\n{missing}\n"})
test({"mode": "custom", "content-format": ["{foo}", "{missing}"]})
test({"mode": "custom", "format": "{foo}\n{missing}\n"})
def test_metadata_extfmt(self):
pp = self._create({