summaryrefslogtreecommitdiffstats
path: root/gallery_dl/job.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-05-26 23:57:04 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2022-05-26 23:57:04 -0400
commitad61a6d8122973534ab63df48f6090954bc73db6 (patch)
treeaedce94427ac95fa180005f88fc94b5c8ef5a62a /gallery_dl/job.py
parentc6b88a96bd191711fc540d7babab3d2e09c68da8 (diff)
New upstream version 1.22.0.upstream/1.22.0
Diffstat (limited to 'gallery_dl/job.py')
-rw-r--r--gallery_dl/job.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/gallery_dl/job.py b/gallery_dl/job.py
index 044369a..a0adffb 100644
--- a/gallery_dl/job.py
+++ b/gallery_dl/job.py
@@ -16,6 +16,7 @@ import collections
from . import extractor, downloader, postprocessor
from . import config, text, util, path, formatter, output, exception
from .extractor.message import Message
+from .output import stdout_write
class Job():
@@ -264,7 +265,7 @@ class DownloadJob(Job):
# download succeeded
pathfmt.finalize()
- self.out.success(pathfmt.path, 0)
+ self.out.success(pathfmt.path)
self._skipcnt = 0
if archive:
archive.add(kwdict)
@@ -537,14 +538,14 @@ class KeywordJob(Job):
self.private = config.get(("output",), "private")
def handle_url(self, url, kwdict):
- print("\nKeywords for filenames and --filter:")
- print("------------------------------------")
+ stdout_write("\nKeywords for filenames and --filter:\n"
+ "------------------------------------\n")
self.print_kwdict(kwdict)
raise exception.StopExtraction()
def handle_directory(self, kwdict):
- print("Keywords for directory names:")
- print("-----------------------------")
+ stdout_write("Keywords for directory names:\n"
+ "-----------------------------\n")
self.print_kwdict(kwdict)
def handle_queue(self, url, kwdict):
@@ -565,36 +566,47 @@ class KeywordJob(Job):
self.extractor.log.info(
"Try 'gallery-dl -K \"%s\"' instead.", url)
else:
- print("Keywords for --chapter-filter:")
- print("------------------------------")
+ stdout_write("Keywords for --chapter-filter:\n"
+ "------------------------------\n")
self.print_kwdict(kwdict)
if extr or self.extractor.categorytransfer:
- print()
+ stdout_write("\n")
KeywordJob(extr or url, self).run()
raise exception.StopExtraction()
- def print_kwdict(self, kwdict, prefix=""):
+ def print_kwdict(self, kwdict, prefix="", markers=None):
"""Print key-value pairs in 'kwdict' with formatting"""
+ write = sys.stdout.write
suffix = "]" if prefix else ""
+
+ markerid = id(kwdict)
+ if markers is None:
+ markers = {markerid}
+ elif markerid in markers:
+ write("{}\n <circular reference>\n".format(prefix[:-1]))
+ return # ignore circular reference
+ else:
+ markers.add(markerid)
+
for key, value in sorted(kwdict.items()):
if key[0] == "_" and not self.private:
continue
key = prefix + key + suffix
if isinstance(value, dict):
- self.print_kwdict(value, key + "[")
+ self.print_kwdict(value, key + "[", markers)
elif isinstance(value, list):
if value and isinstance(value[0], dict):
- self.print_kwdict(value[0], key + "[][")
+ self.print_kwdict(value[0], key + "[][", markers)
else:
- print(key, "[]", sep="")
+ write(key + "[]\n")
for val in value:
- print(" -", val)
+ write(" - " + str(val) + "\n")
else:
# string or number
- print(key, "\n ", value, sep="")
+ write("{}\n {}\n".format(key, value))
class UrlJob(Job):
@@ -609,14 +621,14 @@ class UrlJob(Job):
@staticmethod
def handle_url(url, _):
- print(url)
+ stdout_write(url + "\n")
@staticmethod
def handle_url_fallback(url, kwdict):
- print(url)
+ stdout_write(url + "\n")
if "_fallback" in kwdict:
for url in kwdict["_fallback"]:
- print("|", url)
+ stdout_write("| " + url + "\n")
def handle_queue(self, url, kwdict):
cls = kwdict.get("_extractor")
@@ -653,15 +665,18 @@ class InfoJob(Job):
return 0
def _print_multi(self, title, *values):
- print(title, "\n ", " / ".join(json.dumps(v) for v in values), sep="")
+ stdout_write("{}\n {}\n\n".format(
+ title, " / ".join(json.dumps(v) for v in values)))
def _print_config(self, title, optname, value):
optval = self.extractor.config(optname, util.SENTINEL)
if optval is not util.SENTINEL:
- print(title, "(custom):\n ", json.dumps(optval))
- print(title, "(default):\n ", json.dumps(value))
+ stdout_write(
+ "{} (custom):\n {}\n{} (default):\n {}\n\n".format(
+ title, json.dumps(optval), title, json.dumps(value)))
elif value:
- print(title, "(default):\n ", json.dumps(value))
+ stdout_write(
+ "{} (default):\n {}\n\n".format(title, json.dumps(value)))
class DataJob(Job):