mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 18:53:21 +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
|
metadata.content-format
|
||||||
-----------------------
|
-----------------------
|
||||||
Type
|
Type
|
||||||
``string``
|
``string`` or ``list`` of ``strings``
|
||||||
Example
|
Example
|
||||||
``"tags:\n\n{tags:J\n}\n"``
|
* ``"tags:\n\n{tags:J\n}\n"``
|
||||||
|
* ``["tags:", "", "{tags:J\n}"]``
|
||||||
Description
|
Description
|
||||||
Custom format string to build the content of metadata files with.
|
Custom format string to build the content of metadata files with.
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ class MetadataPP(PostProcessor):
|
|||||||
if mode == "custom":
|
if mode == "custom":
|
||||||
self.write = self._write_custom
|
self.write = self._write_custom
|
||||||
cfmt = options.get("content-format") or options.get("format")
|
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
|
self.contentfmt = util.Formatter(cfmt).format_map
|
||||||
ext = "txt"
|
ext = "txt"
|
||||||
elif mode == "tags":
|
elif mode == "tags":
|
||||||
|
@ -235,18 +235,20 @@ class MetadataTest(BasePostprocessorTest):
|
|||||||
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
|
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
|
||||||
|
|
||||||
def test_metadata_custom(self):
|
def test_metadata_custom(self):
|
||||||
pp = self._create(
|
def test(pp_info):
|
||||||
{"mode": "custom", "format": "{foo}\n{missing}\n"},
|
pp = self._create(pp_info, {"foo": "bar"})
|
||||||
{"foo": "bar"},
|
self.assertEqual(pp.write, pp._write_custom)
|
||||||
)
|
self.assertEqual(pp.extension, "txt")
|
||||||
self.assertEqual(pp.write, pp._write_custom)
|
self.assertTrue(pp.contentfmt)
|
||||||
self.assertEqual(pp.extension, "txt")
|
|
||||||
self.assertTrue(pp.contentfmt)
|
|
||||||
|
|
||||||
with patch("builtins.open", mock_open()) as m:
|
with patch("builtins.open", mock_open()) as m:
|
||||||
pp.prepare(self.pathfmt)
|
pp.prepare(self.pathfmt)
|
||||||
pp.run(self.pathfmt)
|
pp.run(self.pathfmt)
|
||||||
self.assertEqual(self._output(m), "bar\nNone\n")
|
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):
|
def test_metadata_extfmt(self):
|
||||||
pp = self._create({
|
pp = self._create({
|
||||||
|
Loading…
Reference in New Issue
Block a user