[pp:metadata] add '"mode": "print"' (#2691)
https://github.com/mikf/gallery-dl/issues/2691#issuecomment-3276158980
This commit is contained in:
@@ -45,6 +45,15 @@ class MetadataPP(PostProcessor):
|
||||
cfmt = "\n".join(cfmt) + "\n"
|
||||
self._content_fmt = formatter.parse(cfmt).format_map
|
||||
ext = "txt"
|
||||
elif mode == "print":
|
||||
nl = "\n"
|
||||
if isinstance(cfmt, list):
|
||||
cfmt = f"{nl.join(cfmt)}{nl}"
|
||||
if cfmt[-1] != nl and (cfmt[0] != "\f" or cfmt[1] == "F"):
|
||||
cfmt = f"{cfmt}{nl}"
|
||||
self.write = self._write_custom
|
||||
self._content_fmt = formatter.parse(cfmt).format_map
|
||||
filename = "-"
|
||||
elif mode == "jsonl":
|
||||
self.write = self._write_json
|
||||
self._json_encode = self._make_encoder(options).encode
|
||||
|
||||
@@ -555,6 +555,17 @@ class MetadataTest(BasePostprocessorTest):
|
||||
test({"mode": "custom", "format": "{foo}\n{missing}\n"})
|
||||
test({"format": "{foo}\n{missing}\n"})
|
||||
|
||||
def test_metadata_mode_print(self):
|
||||
self._create(
|
||||
{"mode": "print", "format": "{foo}\n{missing}"},
|
||||
{"foo": "bar"},
|
||||
)
|
||||
|
||||
with patch("sys.stdout", Mock()) as m:
|
||||
self._trigger()
|
||||
|
||||
self.assertEqual(self._output(m), "bar\nNone\n")
|
||||
|
||||
def test_metadata_extfmt(self):
|
||||
pp = self._create({
|
||||
"extension" : "ignored",
|
||||
|
||||
Reference in New Issue
Block a user