Add option --no-simulate to not simulate even when --print or --list... are used

* Deprecates `--print-json`
* Some listings like `--list-extractors` are handled by `yt_dlp` and so are not affected by this. These have been documented as such

Addresses: https://github.com/ytdl-org/youtube-dl/issues/29675, https://github.com/ytdl-org/youtube-dl/issues/29580#issuecomment-882046305
This commit is contained in:
pukkandan 2021-08-07 05:31:51 +05:30
parent 6e84b21559
commit b7b04c782e
4 changed files with 39 additions and 31 deletions

View file

@ -1424,6 +1424,7 @@ While these options still work, their use is not recommended since there are oth
--all-formats -f all --all-formats -f all
--all-subs --sub-langs all --write-subs --all-subs --sub-langs all --write-subs
--print-json -j --no-simulate
--autonumber-size NUMBER Use string formatting. Eg: %(autonumber)03d --autonumber-size NUMBER Use string formatting. Eg: %(autonumber)03d
--autonumber-start NUMBER Use internal field formatting like %(autonumber+NUMBER)s --autonumber-start NUMBER Use internal field formatting like %(autonumber+NUMBER)s
--metadata-from-title FORMAT --parse-metadata "%(title)s:FORMAT" --metadata-from-title FORMAT --parse-metadata "%(title)s:FORMAT"

View file

@ -198,7 +198,8 @@ class YoutubeDL(object):
(or video) as a single JSON line. (or video) as a single JSON line.
force_write_download_archive: Force writing download archive regardless force_write_download_archive: Force writing download archive regardless
of 'skip_download' or 'simulate'. of 'skip_download' or 'simulate'.
simulate: Do not download the video files. simulate: Do not download the video files. If unset (or None),
simulate only if listsubtitles, listformats or list_thumbnails is used
format: Video format code. see "FORMAT SELECTION" for more details. format: Video format code. see "FORMAT SELECTION" for more details.
allow_unplayable_formats: Allow unplayable formats to be extracted and downloaded. allow_unplayable_formats: Allow unplayable formats to be extracted and downloaded.
ignore_no_formats_error: Ignore "No video formats" error. Usefull for ignore_no_formats_error: Ignore "No video formats" error. Usefull for
@ -706,7 +707,7 @@ class YoutubeDL(object):
def save_console_title(self): def save_console_title(self):
if not self.params.get('consoletitle', False): if not self.params.get('consoletitle', False):
return return
if self.params.get('simulate', False): if self.params.get('simulate'):
return return
if compat_os_name != 'nt' and 'TERM' in os.environ: if compat_os_name != 'nt' and 'TERM' in os.environ:
# Save the title on stack # Save the title on stack
@ -715,7 +716,7 @@ class YoutubeDL(object):
def restore_console_title(self): def restore_console_title(self):
if not self.params.get('consoletitle', False): if not self.params.get('consoletitle', False):
return return
if self.params.get('simulate', False): if self.params.get('simulate'):
return return
if compat_os_name != 'nt' and 'TERM' in os.environ: if compat_os_name != 'nt' and 'TERM' in os.environ:
# Restore the title from stack # Restore the title from stack
@ -1616,7 +1617,7 @@ class YoutubeDL(object):
return merger.available and merger.can_merge() return merger.available and merger.can_merge()
prefer_best = ( prefer_best = (
not self.params.get('simulate', False) not self.params.get('simulate')
and download and download
and ( and (
not can_merge() not can_merge()
@ -2218,9 +2219,6 @@ class YoutubeDL(object):
info_dict, _ = self.pre_process(info_dict) info_dict, _ = self.pre_process(info_dict)
list_only = self.params.get('list_thumbnails') or self.params.get('listformats') or self.params.get('listsubtitles')
if list_only:
self.__forced_printings(info_dict, self.prepare_filename(info_dict), incomplete=True)
if self.params.get('list_thumbnails'): if self.params.get('list_thumbnails'):
self.list_thumbnails(info_dict) self.list_thumbnails(info_dict)
if self.params.get('listformats'): if self.params.get('listformats'):
@ -2232,6 +2230,11 @@ class YoutubeDL(object):
self.list_subtitles( self.list_subtitles(
info_dict['id'], automatic_captions, 'automatic captions') info_dict['id'], automatic_captions, 'automatic captions')
self.list_subtitles(info_dict['id'], subtitles, 'subtitles') self.list_subtitles(info_dict['id'], subtitles, 'subtitles')
list_only = self.params.get('simulate') is None and (
self.params.get('list_thumbnails') or self.params.get('listformats') or self.params.get('listsubtitles'))
if list_only:
# Without this printing, -F --print-json will not work
self.__forced_printings(info_dict, self.prepare_filename(info_dict), incomplete=True)
return return
format_selector = self.format_selector format_selector = self.format_selector
@ -2455,7 +2458,7 @@ class YoutubeDL(object):
# Forced printings # Forced printings
self.__forced_printings(info_dict, full_filename, incomplete=('format' not in info_dict)) self.__forced_printings(info_dict, full_filename, incomplete=('format' not in info_dict))
if self.params.get('simulate', False): if self.params.get('simulate'):
if self.params.get('force_write_download_archive', False): if self.params.get('force_write_download_archive', False):
self.record_download_archive(info_dict) self.record_download_archive(info_dict)

View file

@ -550,7 +550,7 @@ def _real_main(argv=None):
'forcejson': opts.dumpjson or opts.print_json, 'forcejson': opts.dumpjson or opts.print_json,
'dump_single_json': opts.dump_single_json, 'dump_single_json': opts.dump_single_json,
'force_write_download_archive': opts.force_write_download_archive, 'force_write_download_archive': opts.force_write_download_archive,
'simulate': opts.simulate or any_getting, 'simulate': (any_getting or None) if opts.simulate is None else opts.simulate,
'skip_download': opts.skip_download, 'skip_download': opts.skip_download,
'format': opts.format, 'format': opts.format,
'allow_unplayable_formats': opts.allow_unplayable_formats, 'allow_unplayable_formats': opts.allow_unplayable_formats,

View file

@ -190,15 +190,15 @@ def parseOpts(overrideArguments=None):
general.add_option( general.add_option(
'--dump-user-agent', '--dump-user-agent',
action='store_true', dest='dump_user_agent', default=False, action='store_true', dest='dump_user_agent', default=False,
help='Display the current browser identification') help='Display the current browser identification and exit')
general.add_option( general.add_option(
'--list-extractors', '--list-extractors',
action='store_true', dest='list_extractors', default=False, action='store_true', dest='list_extractors', default=False,
help='List all supported extractors') help='List all supported extractors and exit')
general.add_option( general.add_option(
'--extractor-descriptions', '--extractor-descriptions',
action='store_true', dest='list_extractor_descriptions', default=False, action='store_true', dest='list_extractor_descriptions', default=False,
help='Output descriptions of all supported extractors') help='Output descriptions of all supported extractors and exit')
general.add_option( general.add_option(
'--force-generic-extractor', '--force-generic-extractor',
action='store_true', dest='force_generic_extractor', default=False, action='store_true', dest='force_generic_extractor', default=False,
@ -532,7 +532,7 @@ def parseOpts(overrideArguments=None):
video_format.add_option( video_format.add_option(
'-F', '--list-formats', '-F', '--list-formats',
action='store_true', dest='listformats', action='store_true', dest='listformats',
help='List all available formats of requested videos') help='List available formats of each video. Simulate unless --no-simulate is used')
video_format.add_option( video_format.add_option(
'--list-formats-as-table', '--list-formats-as-table',
action='store_true', dest='listformats_table', default=True, action='store_true', dest='listformats_table', default=True,
@ -583,7 +583,7 @@ def parseOpts(overrideArguments=None):
subtitles.add_option( subtitles.add_option(
'--list-subs', '--list-subs',
action='store_true', dest='listsubtitles', default=False, action='store_true', dest='listsubtitles', default=False,
help='List all available subtitles for the video') help='List available subtitles of each video. Simulate unless --no-simulate is used')
subtitles.add_option( subtitles.add_option(
'--sub-format', '--sub-format',
action='store', dest='subtitlesformat', metavar='FORMAT', default='best', action='store', dest='subtitlesformat', metavar='FORMAT', default='best',
@ -788,8 +788,12 @@ def parseOpts(overrideArguments=None):
help='Ignore warnings') help='Ignore warnings')
verbosity.add_option( verbosity.add_option(
'-s', '--simulate', '-s', '--simulate',
action='store_true', dest='simulate', default=False, action='store_true', dest='simulate', default=None,
help='Do not download the video and do not write anything to disk') help='Do not download the video and do not write anything to disk')
verbosity.add_option(
'--no-simulate',
action='store_false', dest='simulate',
help='Download the video even if printing/listing options are used')
verbosity.add_option( verbosity.add_option(
'--ignore-no-formats-error', '--ignore-no-formats-error',
action='store_true', dest='ignore_no_formats_error', default=False, action='store_true', dest='ignore_no_formats_error', default=False,
@ -809,8 +813,8 @@ def parseOpts(overrideArguments=None):
action='callback', dest='forceprint', type='str', default=[], action='callback', dest='forceprint', type='str', default=[],
callback=_list_from_options_callback, callback_kwargs={'delim': None}, callback=_list_from_options_callback, callback_kwargs={'delim': None},
help=( help=(
'Simulate, quiet but print the given fields. Either a field name ' 'Quiet, but print the given fields for each video. Simulate unless --no-simulate is used. '
'or similar formatting as the output template can be used')) 'Either a field name or same syntax as the output template can be used'))
verbosity.add_option( verbosity.add_option(
'-g', '--get-url', '-g', '--get-url',
action='store_true', dest='geturl', default=False, action='store_true', dest='geturl', default=False,
@ -846,17 +850,17 @@ def parseOpts(overrideArguments=None):
verbosity.add_option( verbosity.add_option(
'-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 TEMPLATE" for a description of available keys') help='Quiet, but print JSON information for each video. Simulate unless --no-simulate is used. See "OUTPUT TEMPLATE" for a description of available keys')
verbosity.add_option( verbosity.add_option(
'-J', '--dump-single-json', '-J', '--dump-single-json',
action='store_true', dest='dump_single_json', default=False, action='store_true', dest='dump_single_json', default=False,
help=( help=(
'Simulate, quiet but print JSON information for each command-line argument. ' 'Quiet, but print JSON information for each url or infojson passed. Simulate unless --no-simulate is used. '
'If the URL refers to a playlist, dump the whole playlist information in a single line')) 'If the URL refers to a playlist, the whole playlist information is dumped in a single line'))
verbosity.add_option( verbosity.add_option(
'--print-json', '--print-json',
action='store_true', dest='print_json', default=False, action='store_true', dest='print_json', default=False,
help='Be quiet and print the video information as JSON (video is still being downloaded)') help=optparse.SUPPRESS_HELP)
verbosity.add_option( verbosity.add_option(
'--force-write-archive', '--force-write-download-archive', '--force-download-archive', '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
action='store_true', dest='force_write_download_archive', default=False, action='store_true', dest='force_write_download_archive', default=False,
@ -1127,7 +1131,7 @@ def parseOpts(overrideArguments=None):
thumbnail.add_option( thumbnail.add_option(
'--list-thumbnails', '--list-thumbnails',
action='store_true', dest='list_thumbnails', default=False, action='store_true', dest='list_thumbnails', default=False,
help='Simulate and list all available thumbnail formats') help='List available thumbnails of each video. Simulate unless --no-simulate is used')
link = optparse.OptionGroup(parser, 'Internet Shortcut Options') link = optparse.OptionGroup(parser, 'Internet Shortcut Options')
link.add_option( link.add_option(