diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 9e5620eef..15ac1372c 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1939,7 +1939,10 @@ class YoutubeDL(object): self.to_stdout(formatSeconds(info_dict['duration'])) print_mandatory('format') 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))) @_catch_unsafe_file_extension def process_info(self, info_dict): diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 3c1272e7b..3a2d8d992 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -439,6 +439,7 @@ def _real_main(argv=None): # just for deprecation check 'autonumber': opts.autonumber if opts.autonumber 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: diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 61705d1f0..887deb48d 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -679,6 +679,11 @@ def parseOpts(overrideArguments=None): '--no-call-home', dest='call_home', action='store_false', default=False, 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.add_option(