mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 10:42:34 +01:00
rework the output format for --list-keywords
This commit is contained in:
parent
b6b214f7e9
commit
4c88c0d496
@ -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):
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user