mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 09:12:40 +01:00
New option --dump-single-json (#4003)
This commit is contained in:
parent
c64ed2a310
commit
63e0be3415
@ -107,6 +107,8 @@ class YoutubeDL(object):
|
|||||||
forcefilename: Force printing final filename.
|
forcefilename: Force printing final filename.
|
||||||
forceduration: Force printing duration.
|
forceduration: Force printing duration.
|
||||||
forcejson: Force printing info_dict as JSON.
|
forcejson: Force printing info_dict as JSON.
|
||||||
|
dump_single_json: Force printing the info_dict of the whole playlist
|
||||||
|
(or video) as a single JSON line.
|
||||||
simulate: Do not download the video files.
|
simulate: Do not download the video files.
|
||||||
format: Video format code.
|
format: Video format code.
|
||||||
format_limit: Highest quality format to try.
|
format_limit: Highest quality format to try.
|
||||||
@ -903,6 +905,8 @@ def process_info(self, info_dict):
|
|||||||
if self.params.get('forcejson', False):
|
if self.params.get('forcejson', False):
|
||||||
info_dict['_filename'] = filename
|
info_dict['_filename'] = filename
|
||||||
self.to_stdout(json.dumps(info_dict))
|
self.to_stdout(json.dumps(info_dict))
|
||||||
|
if self.params.get('dump_single_json', False):
|
||||||
|
info_dict['_filename'] = filename
|
||||||
|
|
||||||
# Do nothing else if in simulate mode
|
# Do nothing else if in simulate mode
|
||||||
if self.params.get('simulate', False):
|
if self.params.get('simulate', False):
|
||||||
@ -1070,12 +1074,15 @@ def download(self, url_list):
|
|||||||
for url in url_list:
|
for url in url_list:
|
||||||
try:
|
try:
|
||||||
#It also downloads the videos
|
#It also downloads the videos
|
||||||
self.extract_info(url)
|
res = self.extract_info(url)
|
||||||
except UnavailableVideoError:
|
except UnavailableVideoError:
|
||||||
self.report_error('unable to download video')
|
self.report_error('unable to download video')
|
||||||
except MaxDownloadsReached:
|
except MaxDownloadsReached:
|
||||||
self.to_screen('[info] Maximum number of downloaded files reached.')
|
self.to_screen('[info] Maximum number of downloaded files reached.')
|
||||||
raise
|
raise
|
||||||
|
else:
|
||||||
|
if self.params.get('dump_single_json', False):
|
||||||
|
self.to_stdout(json.dumps(res))
|
||||||
|
|
||||||
return self._download_retcode
|
return self._download_retcode
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ def _real_main(argv=None):
|
|||||||
u' file! Use "{0}.%(ext)s" instead of "{0}" as the output'
|
u' file! Use "{0}.%(ext)s" instead of "{0}" as the output'
|
||||||
u' template'.format(outtmpl))
|
u' template'.format(outtmpl))
|
||||||
|
|
||||||
any_printing = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson
|
any_printing = opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration or opts.dumpjson or opts.dump_single_json
|
||||||
download_archive_fn = os.path.expanduser(opts.download_archive) if opts.download_archive is not None else opts.download_archive
|
download_archive_fn = os.path.expanduser(opts.download_archive) if opts.download_archive is not None else opts.download_archive
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
@ -304,6 +304,7 @@ def _real_main(argv=None):
|
|||||||
'forcefilename': opts.getfilename,
|
'forcefilename': opts.getfilename,
|
||||||
'forceformat': opts.getformat,
|
'forceformat': opts.getformat,
|
||||||
'forcejson': opts.dumpjson,
|
'forcejson': opts.dumpjson,
|
||||||
|
'dump_single_json': opts.dump_single_json,
|
||||||
'simulate': opts.simulate,
|
'simulate': opts.simulate,
|
||||||
'skip_download': (opts.skip_download or opts.simulate or any_printing),
|
'skip_download': (opts.skip_download or opts.simulate or any_printing),
|
||||||
'format': opts.format,
|
'format': opts.format,
|
||||||
|
@ -417,6 +417,10 @@ def _hide_login_info(opts):
|
|||||||
'-j', '--dump-json',
|
'-j', '--dump-json',
|
||||||
action='store_true', dest='dumpjson', default=False,
|
action='store_true', dest='dumpjson', default=False,
|
||||||
help='simulate, quiet but print JSON information. See --output for a description of available keys.')
|
help='simulate, quiet but print JSON information. See --output for a description of available keys.')
|
||||||
|
verbosity.add_option(
|
||||||
|
'-J', '--dump-single-json',
|
||||||
|
action='store_true', dest='dump_single_json', default=False,
|
||||||
|
help='simulate, quiet but print JSON information for each command-line argument. If the URL refers to a playlist, dump the whole playlist information in a single line.')
|
||||||
verbosity.add_option(
|
verbosity.add_option(
|
||||||
'--newline',
|
'--newline',
|
||||||
action='store_true', dest='progress_with_newline', default=False,
|
action='store_true', dest='progress_with_newline', default=False,
|
||||||
|
Loading…
Reference in New Issue
Block a user