From 4c88c0d496baea76023aa7a242298d16c4222ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 15 May 2017 18:30:47 +0200 Subject: [PATCH] rework the output format for --list-keywords --- gallery_dl/job.py | 27 ++++++++++++++++++++++----- test/test_extractors.py | 2 +- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gallery_dl/job.py b/gallery_dl/job.py index dec7be3f..ae3a4439 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -175,22 +175,39 @@ class KeywordJob(Job): def run(self): for msg in self.extractor: if msg[0] == Message.Url: - print("Keywords for filenames:") + print("\nKeywords for filenames:") + print("-----------------------") self.update_kwdict(msg[2]) self.print_keywords(msg[2]) return elif msg[0] == Message.Directory: print("Keywords for directory names:") + print("-----------------------------") self.update_kwdict(msg[1]) self.print_keywords(msg[1]) @staticmethod - def print_keywords(keywords): + def print_keywords(keywords, prefix="", suffix=""): """Print key-value pairs with formatting""" - offset = max(map(len, keywords.keys())) + 1 for key, value in sorted(keywords.items()): - print(key, ":", " "*(offset-len(key)), value, sep="") - print() + + if isinstance(value, dict): + nprefix = prefix + key + "[" + KeywordJob.print_keywords(value, nprefix, suffix + "]") + + elif isinstance(value, list): + if value and isinstance(value[0], dict): + nprefix = prefix + key + "[][", + KeywordJob.print_keywords(value[0], nprefix, suffix + "]") + else: + print(prefix, key, "[]", suffix, sep="") + for val in value: + print(" - ", val, sep="") + + else: + # string or number + print(prefix, key, suffix, sep="") + print(" ", value, sep="") class UrlJob(Job): diff --git a/test/test_extractors.py b/test/test_extractors.py index 86a26d29..ab3c0481 100644 --- a/test/test_extractors.py +++ b/test/test_extractors.py @@ -51,7 +51,7 @@ skip = [ # dont work on travis-ci "exhentai", "kissmanga", "mangafox", "dynastyscans", "nijie", # temporary issues - "yomanga", + "yomanga", "hbrowse", ] # enable selective testing for direct calls if __name__ == '__main__' and len(sys.argv) > 1: