add '-J/--resolve-json' command-line option (#5864)

This commit is contained in:
Mike Fährmann
2024-07-26 20:36:04 +02:00
parent 70f18b7a78
commit 8ecd408f53
4 changed files with 15 additions and 3 deletions

View File

@@ -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

View File

@@ -856,6 +856,7 @@ class InfoJob(Job):
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):
@@ -863,12 +864,12 @@ class DataJob(Job):
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):

View File

@@ -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,