From edf3f7b69fbede314229ac165f38f1ab3360b1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 13 Nov 2015 01:02:49 +0100 Subject: [PATCH] add KeywordJob class --- gallery_dl/jobs.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gallery_dl/jobs.py b/gallery_dl/jobs.py index b5ffef20..cc61c8ca 100644 --- a/gallery_dl/jobs.py +++ b/gallery_dl/jobs.py @@ -113,3 +113,32 @@ class DownloadJob(): if tries == 0: print("\r", end="") print("\r\033[1;32m", path, "\033[0m", sep="") + + +class KeywordJob(): + + def __init__(self, url): + self.extractor, self.info = extractor.find(url) + if self.extractor is None: + print(url, ": No extractor found", sep="", file=sys.stderr) + return + + def run(self): + """Execute/Run the download job""" + if self.extractor is None: + return + for msg in self.extractor: + if msg[0] == Message.Url: + print("Keywords for filenames:") + self.print_keywords(msg[2]) + return + elif msg[0] == Message.Directory: + print("Keywords for directory names:") + self.print_keywords(msg[1]) + + @staticmethod + def print_keywords(keywords): + offset = max(map(len, keywords.keys())) + 1 + for key, value in sorted(keywords.items()): + print(key, ":", " "*(offset-len(key)), value, sep="") + print()