From 71bba774daa3fd7ca8bae018bb029b9f57de10b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 24 Mar 2022 23:05:36 +0100 Subject: [PATCH] respect 'output.private' in '-K/--list-keywords' output --- docs/configuration.rst | 32 ++++++++++++++++++++++---------- gallery_dl/job.py | 13 ++++++++----- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index c4e9a910..339decf4 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2792,16 +2792,6 @@ Output Options ============== -output.fallback ---------------- -Type - ``bool`` -Default - ``true`` -Description - Include fallback URLs in the output of ``-g/--get-urls``. - - output.mode ----------- Type @@ -2842,6 +2832,28 @@ Description Show skipped file downloads. +output.fallback +--------------- +Type + ``bool`` +Default + ``true`` +Description + Include fallback URLs in the output of ``-g/--get-urls``. + + +output.private +-------------- +Type + ``bool`` +Default + ``false`` +Description + Include private fields, + i.e. fields whose name starts with an underscore, + in the output of ``-K/--list-keywords`` and ``-j/--dump-json``. + + output.progress --------------- Type diff --git a/gallery_dl/job.py b/gallery_dl/job.py index ab4e9e6b..044369ab 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -532,6 +532,10 @@ class SimulationJob(DownloadJob): class KeywordJob(Job): """Print available keywords""" + def __init__(self, url, parent=None): + Job.__init__(self, url, parent) + self.private = config.get(("output",), "private") + def handle_url(self, url, kwdict): print("\nKeywords for filenames and --filter:") print("------------------------------------") @@ -569,21 +573,20 @@ class KeywordJob(Job): KeywordJob(extr or url, self).run() raise exception.StopExtraction() - @staticmethod - def print_kwdict(kwdict, prefix=""): + def print_kwdict(self, kwdict, prefix=""): """Print key-value pairs in 'kwdict' with formatting""" suffix = "]" if prefix else "" for key, value in sorted(kwdict.items()): - if key[0] == "_": + if key[0] == "_" and not self.private: continue key = prefix + key + suffix if isinstance(value, dict): - KeywordJob.print_kwdict(value, key + "[") + self.print_kwdict(value, key + "[") elif isinstance(value, list): if value and isinstance(value[0], dict): - KeywordJob.print_kwdict(value[0], key + "[][") + self.print_kwdict(value[0], key + "[][") else: print(key, "[]", sep="") for val in value: