respect 'output.private' in '-K/--list-keywords' output

This commit is contained in:
Mike Fährmann
2022-03-24 23:05:36 +01:00
parent b03ca7f10c
commit 71bba774da
2 changed files with 30 additions and 15 deletions

View File

@@ -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 output.mode
----------- -----------
Type Type
@@ -2842,6 +2832,28 @@ Description
Show skipped file downloads. 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 output.progress
--------------- ---------------
Type Type

View File

@@ -532,6 +532,10 @@ class SimulationJob(DownloadJob):
class KeywordJob(Job): class KeywordJob(Job):
"""Print available keywords""" """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): def handle_url(self, url, kwdict):
print("\nKeywords for filenames and --filter:") print("\nKeywords for filenames and --filter:")
print("------------------------------------") print("------------------------------------")
@@ -569,21 +573,20 @@ class KeywordJob(Job):
KeywordJob(extr or url, self).run() KeywordJob(extr or url, self).run()
raise exception.StopExtraction() raise exception.StopExtraction()
@staticmethod def print_kwdict(self, kwdict, prefix=""):
def print_kwdict(kwdict, prefix=""):
"""Print key-value pairs in 'kwdict' with formatting""" """Print key-value pairs in 'kwdict' with formatting"""
suffix = "]" if prefix else "" suffix = "]" if prefix else ""
for key, value in sorted(kwdict.items()): for key, value in sorted(kwdict.items()):
if key[0] == "_": if key[0] == "_" and not self.private:
continue continue
key = prefix + key + suffix key = prefix + key + suffix
if isinstance(value, dict): if isinstance(value, dict):
KeywordJob.print_kwdict(value, key + "[") self.print_kwdict(value, key + "[")
elif isinstance(value, list): elif isinstance(value, list):
if value and isinstance(value[0], dict): if value and isinstance(value[0], dict):
KeywordJob.print_kwdict(value[0], key + "[][") self.print_kwdict(value[0], key + "[][")
else: else:
print(key, "[]", sep="") print(key, "[]", sep="")
for val in value: for val in value: