mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-25 03:32:05 +00:00
indent json with --pretty-json
This commit is contained in:
parent
668332b973
commit
86808ab7c5
3 changed files with 10 additions and 1 deletions
|
@ -1914,7 +1914,10 @@ class YoutubeDL(object):
|
||||||
self.to_stdout(formatSeconds(info_dict['duration']))
|
self.to_stdout(formatSeconds(info_dict['duration']))
|
||||||
print_mandatory('format')
|
print_mandatory('format')
|
||||||
if self.params.get('forcejson', False):
|
if self.params.get('forcejson', False):
|
||||||
self.to_stdout(json.dumps(self.sanitize_info(info_dict)))
|
if self.params.get('indent_json', False):
|
||||||
|
self.to_stdout(json.dumps(self.sanitize_info(info_dict), indent=2))
|
||||||
|
else:
|
||||||
|
self.to_stdout(json.dumps(self.sanitize_info(info_dict)))
|
||||||
|
|
||||||
def process_info(self, info_dict):
|
def process_info(self, info_dict):
|
||||||
"""Process a single resolved IE result."""
|
"""Process a single resolved IE result."""
|
||||||
|
|
|
@ -435,6 +435,7 @@ def _real_main(argv=None):
|
||||||
# just for deprecation check
|
# just for deprecation check
|
||||||
'autonumber': opts.autonumber if opts.autonumber is True else None,
|
'autonumber': opts.autonumber if opts.autonumber is True else None,
|
||||||
'usetitle': opts.usetitle if opts.usetitle is True else None,
|
'usetitle': opts.usetitle if opts.usetitle is True else None,
|
||||||
|
'indent_json': opts.pretty_json,
|
||||||
}
|
}
|
||||||
|
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
with YoutubeDL(ydl_opts) as ydl:
|
||||||
|
|
|
@ -675,6 +675,11 @@ def parseOpts(overrideArguments=None):
|
||||||
'--no-call-home',
|
'--no-call-home',
|
||||||
dest='call_home', action='store_false', default=False,
|
dest='call_home', action='store_false', default=False,
|
||||||
help='Do NOT contact the youtube-dl server for debugging')
|
help='Do NOT contact the youtube-dl server for debugging')
|
||||||
|
verbosity.add_option(
|
||||||
|
'--pretty-json',
|
||||||
|
dest='pretty_json', action='store_true', default=False,
|
||||||
|
help='Print json with indentation. Only when --dump-json is provided'
|
||||||
|
)
|
||||||
|
|
||||||
filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
|
filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
|
||||||
filesystem.add_option(
|
filesystem.add_option(
|
||||||
|
|
Loading…
Reference in a new issue