mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
[postprocessor:metadata] accept a string-list for 'content-format'
(closes #1080)
This commit is contained in:
parent
198c33ec36
commit
d83b95fd28
@ -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.
|
||||
|
||||
|
@ -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":
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user