From 4052068d5a9ca0e3e20d2f26b62a31b64b4e5e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 22 Sep 2025 17:50:00 +0200 Subject: [PATCH] [pp:metadata] add '"mode": "print"' (#2691) https://github.com/mikf/gallery-dl/issues/2691#issuecomment-3276158980 --- gallery_dl/postprocessor/metadata.py | 9 +++++++++ test/test_postprocessor.py | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/gallery_dl/postprocessor/metadata.py b/gallery_dl/postprocessor/metadata.py index c74f92fb..a6d2b7f8 100644 --- a/gallery_dl/postprocessor/metadata.py +++ b/gallery_dl/postprocessor/metadata.py @@ -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 diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index 310f63f5..2902feab 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -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",