Skip to content

Commit

Permalink
add '-J/--resolve-json' command-line option (#5864)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jul 26, 2024
1 parent 70f18b7 commit 8ecd408
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
-G, --resolve-urls Print URLs instead of downloading; resolve
intermediary URLs
-j, --dump-json Print JSON information
-J, --resolve-json Print JSON information; resolve intermediary
URLs
-s, --simulate Simulate data extraction; do not download
anything
-E, --extractor-info Print extractor defaults and settings
Expand All @@ -54,6 +56,7 @@
extractors but cannot be handled, to FILE
--write-pages Write downloaded intermediary pages to files in
the current directory to debug problems
--print-traffic Display sent and read HTTP traffic
--no-colors Do not emit ANSI color codes in output

## Networking Options:
Expand Down
3 changes: 3 additions & 0 deletions gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ def main():
if config.get(("output",), "fallback", True):
jobtype.handle_url = \
staticmethod(jobtype.handle_url_fallback)
elif args.dump_json:
jobtype = job.DataJob
jobtype.resolve = args.dump_json - 1
else:
jobtype = args.jobtype or job.DownloadJob

Expand Down
5 changes: 3 additions & 2 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,20 @@ def _print_config(self, title, optname, value):

class DataJob(Job):
"""Collect extractor results and dump them"""
resolve = False

def __init__(self, url, parent=None, file=sys.stdout, ensure_ascii=True,
resolve=False):
Job.__init__(self, url, parent)
self.file = file
self.data = []
self.ascii = config.get(("output",), "ascii", ensure_ascii)
self.resolve = 128 if resolve is True else resolve
self.resolve = 128 if resolve is True else (resolve or self.resolve)

private = config.get(("output",), "private")
self.filter = dict.copy if private else util.filter_dict

if resolve:
if self.resolve > 0:
self.handle_queue = self.handle_queue_resolve

def run(self):
Expand Down
7 changes: 6 additions & 1 deletion gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,14 @@ def build_parser():
)
output.add_argument(
"-j", "--dump-json",
dest="jobtype", action="store_const", const=job.DataJob,
dest="dump_json", action="count",
help="Print JSON information",
)
output.add_argument(
"-J", "--resolve-json",
dest="dump_json", action="store_const", const=128,
help="Print JSON information; resolve intermediary URLs",
)
output.add_argument(
"-s", "--simulate",
dest="jobtype", action="store_const", const=job.SimulationJob,
Expand Down

0 comments on commit 8ecd408

Please sign in to comment.