11 from .compat
import compat_expanduser
12 from .cookies
import SUPPORTED_BROWSERS
, SUPPORTED_KEYRINGS
13 from .downloader
.external
import list_external_downloaders
14 from .postprocessor
import (
17 FFmpegSubtitlesConvertorPP
,
18 FFmpegThumbnailsConvertorPP
,
22 from .postprocessor
.modify_chapters
import DEFAULT_SPONSORBLOCK_CHAPTER_TITLE
23 from .update
import UPDATE_SOURCES
, detect_variant
, is_non_updateable
32 get_system_config_dirs
,
35 orderedSet_from_options
,
39 from .version
import CHANNEL
, __version__
42 def parseOpts(overrideArguments
=None, ignore_config_files
='if_override'):
43 PACKAGE_NAME
= 'yt-dlp'
45 root
= Config(create_parser())
46 if ignore_config_files
== 'if_override':
47 ignore_config_files
= overrideArguments
is not None
49 def read_config(*paths
):
50 path
= os
.path
.join(*paths
)
51 conf
= Config
.read_file(path
, default
=None)
55 def _load_from_config_dirs(config_dirs
):
56 for config_dir
in config_dirs
:
57 head
, tail
= os
.path
.split(config_dir
)
58 assert tail
== PACKAGE_NAME
or config_dir
== os
.path
.join(compat_expanduser('~'), f
'.{PACKAGE_NAME}')
60 yield read_config(head
, f
'{PACKAGE_NAME}.conf')
61 if tail
.startswith('.'): # ~/.PACKAGE_NAME
62 yield read_config(head
, f
'{PACKAGE_NAME}.conf.txt')
63 yield read_config(config_dir
, 'config')
64 yield read_config(config_dir
, 'config.txt')
66 def add_config(label
, path
=None, func
=None):
67 """ Adds config and returns whether to continue """
68 if root
.parse_known_args()[0].ignoreconfig
:
72 args
, current_path
= next(
73 filter(None, _load_from_config_dirs(func(PACKAGE_NAME
))), (None, None))
75 current_path
= os
.path
.join(path
, 'yt-dlp.conf')
76 args
= Config
.read_file(current_path
, default
=None)
78 root
.append_config(args
, current_path
, label
=label
)
82 yield not ignore_config_files
83 yield add_config('Portable', get_executable_path())
84 yield add_config('Home', expand_path(root
.parse_known_args()[0].paths
.get('home', '')).strip())
85 yield add_config('User', func
=get_user_config_dirs
)
86 yield add_config('System', func
=get_system_config_dirs
)
88 opts
= optparse
.Values({'verbose': True, 'print_help': False}
)
91 if overrideArguments
is not None:
92 root
.append_config(overrideArguments
, label
='Override')
94 root
.append_config(sys
.argv
[1:], label
='Command-line')
95 loaded_all_configs
= all(load_configs())
96 except ValueError as err
:
97 raise root
.parser
.error(err
)
99 if loaded_all_configs
:
100 # If ignoreconfig is found inside the system configuration file,
101 # the user configuration is removed
102 if root
.parse_known_args()[0].ignoreconfig
:
103 user_conf
= next((i
for i
, conf
in enumerate(root
.configs
) if conf
.label
== 'User'), None)
104 if user_conf
is not None:
105 root
.configs
.pop(user_conf
)
108 root
.configs
[0].load_configs() # Resolve any aliases using --config-location
109 except ValueError as err
:
110 raise root
.parser
.error(err
)
112 opts
, args
= root
.parse_args()
113 except optparse
.OptParseError
:
114 with contextlib
.suppress(optparse
.OptParseError
):
115 opts
, _
= root
.parse_known_args(strict
=False)
117 except (SystemExit, KeyboardInterrupt):
121 verbose
= opts
.verbose
and f
'\n{root}'.replace('\n| ', '\n[debug] ')[1:]
123 write_string(f
'{verbose}\n')
127 root
.parser
.print_help()
130 return root
.parser
, opts
, args
133 class _YoutubeDLHelpFormatter(optparse
.IndentedHelpFormatter
):
135 # No need to wrap help messages if we're on a wide console
136 max_width
= shutil
.get_terminal_size().columns
or 80
137 # The % is chosen to get a pretty output in README.md
138 super().__init
__(width
=max_width
, max_help_position
=int(0.45 * max_width
))
141 def format_option_strings(option
):
142 """ ('-o', '--option') -> -o, --format METAVAR """
143 opts
= join_nonempty(
144 option
._short
_opts
and option
._short
_opts
[0],
145 option
._long
_opts
and option
._long
_opts
[0],
147 if option
.takes_value():
148 opts
+= f
' {option.metavar}'
152 class _YoutubeDLOptionParser(optparse
.OptionParser
):
153 # optparse is deprecated since python 3.2. So assume a stable interface even for private methods
154 ALIAS_DEST
= '_triggered_aliases'
155 ALIAS_TRIGGER_LIMIT
= 100
159 prog
='yt-dlp' if detect_variant() == 'source' else None,
161 usage
='%prog [OPTIONS] URL [URL...]',
162 epilog
='See full documentation at https://github.com/yt-dlp/yt-dlp#readme',
163 formatter
=_YoutubeDLHelpFormatter(),
164 conflict_handler
='resolve',
166 self
.set_default(self
.ALIAS_DEST
, collections
.defaultdict(int))
168 _UNKNOWN_OPTION
= (optparse
.BadOptionError
, optparse
.AmbiguousOptionError
)
169 _BAD_OPTION
= optparse
.OptionValueError
171 def parse_known_args(self
, args
=None, values
=None, strict
=True):
172 """Same as parse_args, but ignore unknown switches. Similar to argparse.parse_known_args"""
173 self
.rargs
, self
.largs
= self
._get
_args
(args
), []
174 self
.values
= values
or self
.get_default_values()
181 elif arg
.startswith('--'):
182 self
._process
_long
_opt
(self
.rargs
, self
.values
)
183 elif arg
.startswith('-') and arg
!= '-':
184 self
._process
_short
_opts
(self
.rargs
, self
.values
)
185 elif self
.allow_interspersed_args
:
186 self
.largs
.append(self
.rargs
.pop(0))
189 except optparse
.OptParseError
as err
:
190 if isinstance(err
, self
._UNKNOWN
_OPTION
):
191 self
.largs
.append(err
.opt_str
)
193 if isinstance(err
, self
._BAD
_OPTION
):
196 return self
.check_values(self
.values
, self
.largs
)
198 def error(self
, msg
):
199 msg
= f
'{self.get_prog_name()}: error: {str(msg).strip()}\n'
200 raise optparse
.OptParseError(f
'{self.get_usage()}\n{msg}' if self
.usage
else msg
)
202 def _get_args(self
, args
):
203 return sys
.argv
[1:] if args
is None else list(args
)
205 def _match_long_opt(self
, opt
):
206 """Improve ambiguous argument resolution by comparing option objects instead of argument strings"""
208 return super()._match
_long
_opt
(opt
)
209 except optparse
.AmbiguousOptionError
as e
:
210 if len({self._long_opt[p] for p in e.possibilities}
) == 1:
211 return e
.possibilities
[0]
216 def _list_from_options_callback(option
, opt_str
, value
, parser
, append
=True, delim
=',', process
=str.strip
):
217 # append can be True, False or -1 (prepend)
218 current
= list(getattr(parser
.values
, option
.dest
)) if append
else []
219 value
= list(filter(None, [process(value
)] if delim
is None else map(process
, value
.split(delim
))))
221 parser
.values
, option
.dest
,
222 current
+ value
if append
is True else value
+ current
)
224 def _set_from_options_callback(
225 option
, opt_str
, value
, parser
, allowed_values
, delim
=',', aliases
={},
226 process
=lambda x
: x
.lower().strip()):
227 values
= [process(value
)] if delim
is None else map(process
, value
.split(delim
))
229 requested
= orderedSet_from_options(values
, collections
.ChainMap(aliases
, {'all': allowed_values}
),
230 start
=getattr(parser
.values
, option
.dest
))
231 except ValueError as e
:
232 raise optparse
.OptionValueError(f
'wrong {option.metavar} for {opt_str}: {e.args[0]}')
234 setattr(parser
.values
, option
.dest
, set(requested
))
236 def _dict_from_options_callback(
237 option
, opt_str
, value
, parser
,
238 allowed_keys
=r
'[\w-]+', delimiter
=':', default_key
=None, process
=None, multiple_keys
=True,
239 process_key
=str.lower
, append
=False):
241 out_dict
= dict(getattr(parser
.values
, option
.dest
))
242 multiple_args
= not isinstance(value
, str)
244 allowed_keys
= fr
'({allowed_keys})(,({allowed_keys}))*'
246 fr
'(?i)(?P<keys>{allowed_keys}){delimiter}(?P<val>.*)$',
247 value
[0] if multiple_args
else value
)
249 keys
, val
= mobj
.group('keys').split(','), mobj
.group('val')
251 val
= [val
, *value
[1:]]
252 elif default_key
is not None:
253 keys
, val
= [default_key
], value
255 raise optparse
.OptionValueError(
256 f
'wrong {opt_str} formatting; it should be {option.metavar}, not "{value}"')
258 keys
= map(process_key
, keys
) if process_key
else keys
259 val
= process(val
) if process
else val
260 except Exception as err
:
261 raise optparse
.OptionValueError(f
'wrong {opt_str} formatting; {err}')
263 out_dict
[key
] = out_dict
.get(key
, []) + [val
] if append
else val
264 setattr(parser
.values
, option
.dest
, out_dict
)
266 def when_prefix(default
):
270 'action': 'callback',
271 'callback': _dict_from_options_callback
,
273 'allowed_keys': '|'.join(map(re
.escape
, POSTPROCESS_WHEN
)),
274 'default_key': default
,
275 'multiple_keys': False,
280 parser
= _YoutubeDLOptionParser()
281 alias_group
= optparse
.OptionGroup(parser
, 'Aliases')
282 Formatter
= string
.Formatter()
284 def _create_alias(option
, opt_str
, value
, parser
):
285 aliases
, opts
= value
287 nargs
= len({i
if f
== '' else f
288 for i
, (_
, f
, _
, _
) in enumerate(Formatter
.parse(opts
)) if f
is not None})
289 opts
.format(*map(str, range(nargs
))) # validate
290 except Exception as err
:
291 raise optparse
.OptionValueError(f
'wrong {opt_str} OPTIONS formatting; {err}')
292 if alias_group
not in parser
.option_groups
:
293 parser
.add_option_group(alias_group
)
295 aliases
= (x
if x
.startswith('-') else f
'--{x}' for x
in map(str.strip
, aliases
.split(',')))
297 args
= [f
'ARG{i}' for i
in range(nargs
)]
298 alias_group
.add_option(
299 *aliases
, nargs
=nargs
, dest
=parser
.ALIAS_DEST
, type='str' if nargs
else None,
300 metavar
=' '.join(args
), help=opts
.format(*args
), action
='callback',
301 callback
=_alias_callback
, callback_kwargs
={'opts': opts, 'nargs': nargs}
)
302 except Exception as err
:
303 raise optparse
.OptionValueError(f
'wrong {opt_str} formatting; {err}')
305 def _alias_callback(option
, opt_str
, value
, parser
, opts
, nargs
):
306 counter
= getattr(parser
.values
, option
.dest
)
307 counter
[opt_str
] += 1
308 if counter
[opt_str
] > parser
.ALIAS_TRIGGER_LIMIT
:
309 raise optparse
.OptionValueError(f
'Alias {opt_str} exceeded invocation limit')
312 assert (nargs
== 0 and value
is None) or len(value
) == nargs
313 parser
.rargs
[:0] = shlex
.split(
314 opts
if value
is None else opts
.format(*map(shlex
.quote
, value
)))
316 general
= optparse
.OptionGroup(parser
, 'General Options')
318 '-h', '--help', dest
='print_help', action
='store_true',
319 help='Print this help text and exit')
323 help='Print program version and exit')
326 action
='store_true', dest
='update_self',
328 is_non_updateable(), None, 'Check if updates are available. %s',
329 default
=f
'Update this program to the latest {CHANNEL} version'))
332 action
='store_false', dest
='update_self',
333 help='Do not check for updates (default)')
336 action
='store', dest
='update_self', metavar
='[CHANNEL]@[TAG]',
338 'Upgrade/downgrade to a specific version. CHANNEL and TAG defaults to '
339 f
'"{CHANNEL}" and "latest" respectively if ommited; See "UPDATE" for details. '
340 f
'Supported channels: {", ".join(UPDATE_SOURCES)}'))
342 '-i', '--ignore-errors',
343 action
='store_true', dest
='ignoreerrors',
344 help='Ignore download and postprocessing errors. The download will be considered successful even if the postprocessing fails')
346 '--no-abort-on-error',
347 action
='store_const', dest
='ignoreerrors', const
='only_download',
348 help='Continue with next video on download errors; e.g. to skip unavailable videos in a playlist (default)')
350 '--abort-on-error', '--no-ignore-errors',
351 action
='store_false', dest
='ignoreerrors',
352 help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
355 action
='store_true', dest
='dump_user_agent', default
=False,
356 help='Display the current user-agent and exit')
359 action
='store_true', dest
='list_extractors', default
=False,
360 help='List all supported extractors and exit')
362 '--extractor-descriptions',
363 action
='store_true', dest
='list_extractor_descriptions', default
=False,
364 help='Output descriptions of all supported extractors and exit')
366 '--use-extractors', '--ies',
367 action
='callback', dest
='allowed_extractors', metavar
='NAMES', type='str',
368 default
=[], callback
=_list_from_options_callback
,
370 'Extractor names to use separated by commas. '
371 'You can also use regexes, "all", "default" and "end" (end URL matching); '
372 'e.g. --ies "holodex.*,end,youtube". '
373 'Prefix the name with a "-" to exclude it, e.g. --ies default,-generic. '
374 'Use --list-extractors for a list of extractor names. (Alias: --ies)'))
376 '--force-generic-extractor',
377 action
='store_true', dest
='force_generic_extractor', default
=False,
378 help=optparse
.SUPPRESS_HELP
)
381 dest
='default_search', metavar
='PREFIX',
383 'Use this prefix for unqualified URLs. '
384 'E.g. "gvsearch2:python" downloads two videos from google videos for the search term "python". '
385 'Use the value "auto" to let yt-dlp guess ("auto_warning" to emit a warning when guessing). '
386 '"error" just throws an error. The default value "fixup_error" repairs broken URLs, '
387 'but emits an error if this is not possible instead of searching'))
389 '--ignore-config', '--no-config',
390 action
='store_true', dest
='ignoreconfig',
392 'Don\'t load any more configuration files except those given by --config-locations. '
393 'For backward compatibility, if this option is found inside the system configuration file, the user configuration is not loaded. '
394 '(Alias: --no-config)'))
396 '--no-config-locations',
397 action
='store_const', dest
='config_locations', const
=[],
399 'Do not load any custom configuration files (default). When given inside a '
400 'configuration file, ignore all previous --config-locations defined in the current file'))
402 '--config-locations',
403 dest
='config_locations', metavar
='PATH', action
='append',
405 'Location of the main configuration file; either the path to the config or its containing directory '
406 '("-" for stdin). Can be used multiple times and inside other configuration files'))
409 action
='store_const', dest
='extract_flat', const
='in_playlist', default
=False,
410 help='Do not extract the videos of a playlist, only list them')
412 '--no-flat-playlist',
413 action
='store_false', dest
='extract_flat',
414 help='Extract the videos of a playlist')
417 action
='store_true', dest
='live_from_start',
418 help='Download livestreams from the start. Currently only supported for YouTube (Experimental)')
420 '--no-live-from-start',
421 action
='store_false', dest
='live_from_start',
422 help='Download livestreams from the current time (default)')
425 dest
='wait_for_video', metavar
='MIN[-MAX]', default
=None,
427 'Wait for scheduled streams to become available. '
428 'Pass the minimum number of seconds (or range) to wait between retries'))
430 '--no-wait-for-video',
431 dest
='wait_for_video', action
='store_const', const
=None,
432 help='Do not wait for scheduled streams (default)')
435 action
='store_true', dest
='mark_watched', default
=False,
436 help='Mark videos watched (even with --simulate)')
439 action
='store_false', dest
='mark_watched',
440 help='Do not mark videos watched (default)')
442 '--no-colors', '--no-colours',
443 action
='store_true', dest
='no_color', default
=False,
444 help='Do not emit color codes in output (Alias: --no-colours)')
447 metavar
='OPTS', dest
='compat_opts', default
=set(), type='str',
448 action
='callback', callback
=_set_from_options_callback
,
451 'filename', 'filename-sanitization', 'format-sort', 'abort-on-error', 'format-spec', 'no-playlist-metafiles',
452 'multistreams', 'no-live-chat', 'playlist-index', 'list-formats', 'no-direct-merge',
453 'no-attach-info-json', 'embed-thumbnail-atomicparsley', 'no-external-downloader-progress',
454 'embed-metadata', 'seperate-video-versions', 'no-clean-infojson', 'no-keep-subs', 'no-certifi',
455 'no-youtube-channel-redirect', 'no-youtube-unavailable-videos', 'no-youtube-prefer-utc-upload-date',
457 'youtube-dl': ['all', '-multistreams'],
458 'youtube-dlc': ['all', '-no-youtube-channel-redirect', '-no-live-chat'],
459 '2021': ['2022', 'no-certifi', 'filename-sanitization', 'no-youtube-prefer-utc-upload-date'],
460 '2022': ['no-external-downloader-progress'],
463 'Options that can help keep compatibility with youtube-dl or youtube-dlc '
464 'configurations by reverting some of the changes made in yt-dlp. '
465 'See "Differences in default behavior" for details'))
467 '--alias', metavar
='ALIASES OPTIONS', dest
='_', type='str', nargs
=2,
468 action
='callback', callback
=_create_alias
,
470 'Create aliases for an option string. Unless an alias starts with a dash "-", it is prefixed with "--". '
471 'Arguments are parsed according to the Python string formatting mini-language. '
472 'E.g. --alias get-audio,-X "-S=aext:{0},abr -x --audio-format {0}" creates options '
473 '"--get-audio" and "-X" that takes an argument (ARG0) and expands to '
474 '"-S=aext:ARG0,abr -x --audio-format ARG0". All defined aliases are listed in the --help output. '
475 'Alias options can trigger more aliases; so be careful to avoid defining recursive options. '
476 f
'As a safety measure, each alias may be triggered a maximum of {_YoutubeDLOptionParser.ALIAS_TRIGGER_LIMIT} times. '
477 'This option can be used multiple times'))
479 network
= optparse
.OptionGroup(parser
, 'Network Options')
481 '--proxy', dest
='proxy',
482 default
=None, metavar
='URL',
484 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable SOCKS proxy, specify a proper scheme, '
485 'e.g. socks5://user:pass@127.0.0.1:1080/. Pass in an empty string (--proxy "") for direct connection'))
488 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
489 help='Time to wait before giving up, in seconds')
492 metavar
='IP', dest
='source_address', default
=None,
493 help='Client-side IP address to bind to',
496 '-4', '--force-ipv4',
497 action
='store_const', const
='0.0.0.0', dest
='source_address',
498 help='Make all connections via IPv4',
501 '-6', '--force-ipv6',
502 action
='store_const', const
='::', dest
='source_address',
503 help='Make all connections via IPv6',
506 '--enable-file-urls', action
='store_true',
507 dest
='enable_file_urls', default
=False,
508 help='Enable file:// URLs. This is disabled by default for security reasons.'
511 geo
= optparse
.OptionGroup(parser
, 'Geo-restriction')
513 '--geo-verification-proxy',
514 dest
='geo_verification_proxy', default
=None, metavar
='URL',
516 'Use this proxy to verify the IP address for some geo-restricted sites. '
517 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
519 '--cn-verification-proxy',
520 dest
='cn_verification_proxy', default
=None, metavar
='URL',
521 help=optparse
.SUPPRESS_HELP
)
524 action
='store_true', dest
='geo_bypass', default
=True,
525 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header (default)')
528 action
='store_false', dest
='geo_bypass',
529 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
531 '--geo-bypass-country', metavar
='CODE',
532 dest
='geo_bypass_country', default
=None,
533 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
535 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
536 dest
='geo_bypass_ip_block', default
=None,
537 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
539 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
540 selection
.add_option(
542 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
543 help=optparse
.SUPPRESS_HELP
)
544 selection
.add_option(
546 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
547 help=optparse
.SUPPRESS_HELP
)
548 selection
.add_option(
549 '-I', '--playlist-items',
550 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
552 'Comma separated playlist_index of the items to download. '
553 'You can specify a range using "[START]:[STOP][:STEP]". For backward compatibility, START-STOP is also supported. '
554 'Use negative indices to count from the right and negative STEP to download in reverse order. '
555 'E.g. "-I 1:3,7,-5::2" used on a playlist of size 15 will download the items at index 1,2,3,7,11,13,15'))
556 selection
.add_option(
558 dest
='matchtitle', metavar
='REGEX',
559 help=optparse
.SUPPRESS_HELP
)
560 selection
.add_option(
562 dest
='rejecttitle', metavar
='REGEX',
563 help=optparse
.SUPPRESS_HELP
)
564 selection
.add_option(
566 metavar
='SIZE', dest
='min_filesize', default
=None,
567 help='Abort download if filesize is smaller than SIZE, e.g. 50k or 44.6M')
568 selection
.add_option(
570 metavar
='SIZE', dest
='max_filesize', default
=None,
571 help='Abort download if filesize is larger than SIZE, e.g. 50k or 44.6M')
572 selection
.add_option(
574 metavar
='DATE', dest
='date', default
=None,
576 'Download only videos uploaded on this date. '
577 'The date can be "YYYYMMDD" or in the format [now|today|yesterday][-N[day|week|month|year]]. '
578 'E.g. "--date today-2weeks" downloads only videos uploaded on the same day two weeks ago'))
579 selection
.add_option(
581 metavar
='DATE', dest
='datebefore', default
=None,
583 'Download only videos uploaded on or before this date. '
584 'The date formats accepted is the same as --date'))
585 selection
.add_option(
587 metavar
='DATE', dest
='dateafter', default
=None,
589 'Download only videos uploaded on or after this date. '
590 'The date formats accepted is the same as --date'))
591 selection
.add_option(
593 metavar
='COUNT', dest
='min_views', default
=None, type=int,
594 help=optparse
.SUPPRESS_HELP
)
595 selection
.add_option(
597 metavar
='COUNT', dest
='max_views', default
=None, type=int,
598 help=optparse
.SUPPRESS_HELP
)
599 selection
.add_option(
601 metavar
='FILTER', dest
='match_filter', action
='append',
603 'Generic video filter. Any "OUTPUT TEMPLATE" field can be compared with a '
604 'number or a string using the operators defined in "Filtering Formats". '
605 'You can also simply specify a field to match if the field is present, '
606 'use "!field" to check if the field is not present, and "&" to check multiple conditions. '
607 'Use a "\\" to escape "&" or quotes if needed. If used multiple times, '
608 'the filter matches if atleast one of the conditions are met. E.g. --match-filter '
609 '!is_live --match-filter "like_count>?100 & description~=\'(?i)\\bcats \\& dogs\\b\'" '
610 'matches only videos that are not live OR those that have a like count more than 100 '
611 '(or the like field is not available) and also has a description '
612 'that contains the phrase "cats & dogs" (caseless). '
613 'Use "--match-filter -" to interactively ask whether to download each video'))
614 selection
.add_option(
616 metavar
='FILTER', dest
='match_filter', action
='store_const', const
=None,
617 help='Do not use generic video filter (default)')
618 selection
.add_option(
620 action
='store_true', dest
='noplaylist', default
=False,
621 help='Download only the video, if the URL refers to a video and a playlist')
622 selection
.add_option(
624 action
='store_false', dest
='noplaylist',
625 help='Download the playlist, if the URL refers to a video and a playlist')
626 selection
.add_option(
628 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
629 help='Download only videos suitable for the given age')
630 selection
.add_option(
631 '--download-archive', metavar
='FILE',
632 dest
='download_archive',
633 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
634 selection
.add_option(
635 '--no-download-archive',
636 dest
='download_archive', action
="store_const", const
=None,
637 help='Do not use archive file (default)')
638 selection
.add_option(
640 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
641 help='Abort after downloading NUMBER files')
642 selection
.add_option(
643 '--break-on-existing',
644 action
='store_true', dest
='break_on_existing', default
=False,
645 help='Stop the download process when encountering a file that is in the archive')
646 selection
.add_option(
648 action
='store_true', dest
='break_on_reject', default
=False,
649 help='Stop the download process when encountering a file that has been filtered out')
650 selection
.add_option(
652 action
='store_true', dest
='break_per_url', default
=False,
653 help='Alters --max-downloads, --break-on-existing, --break-on-reject, and autonumber to reset per input URL')
654 selection
.add_option(
655 '--no-break-per-input',
656 action
='store_false', dest
='break_per_url',
657 help='--break-on-existing and similar options terminates the entire download queue')
658 selection
.add_option(
659 '--skip-playlist-after-errors', metavar
='N',
660 dest
='skip_playlist_after_errors', default
=None, type=int,
661 help='Number of allowed failures until the rest of the playlist is skipped')
662 selection
.add_option(
664 dest
='include_ads', action
='store_true',
665 help=optparse
.SUPPRESS_HELP
)
666 selection
.add_option(
668 dest
='include_ads', action
='store_false',
669 help=optparse
.SUPPRESS_HELP
)
671 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
672 authentication
.add_option(
674 dest
='username', metavar
='USERNAME',
675 help='Login with this account ID')
676 authentication
.add_option(
678 dest
='password', metavar
='PASSWORD',
679 help='Account password. If this option is left out, yt-dlp will ask interactively')
680 authentication
.add_option(
682 dest
='twofactor', metavar
='TWOFACTOR',
683 help='Two-factor authentication code')
684 authentication
.add_option(
686 action
='store_true', dest
='usenetrc', default
=False,
687 help='Use .netrc authentication data')
688 authentication
.add_option(
690 dest
='netrc_location', metavar
='PATH',
691 help='Location of .netrc authentication data; either the path or its containing directory. Defaults to ~/.netrc')
692 authentication
.add_option(
694 dest
='videopassword', metavar
='PASSWORD',
695 help='Video password (vimeo, youku)')
696 authentication
.add_option(
698 dest
='ap_mso', metavar
='MSO',
699 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
700 authentication
.add_option(
702 dest
='ap_username', metavar
='USERNAME',
703 help='Multiple-system operator account login')
704 authentication
.add_option(
706 dest
='ap_password', metavar
='PASSWORD',
707 help='Multiple-system operator account password. If this option is left out, yt-dlp will ask interactively')
708 authentication
.add_option(
710 action
='store_true', dest
='ap_list_mso', default
=False,
711 help='List all supported multiple-system operators')
712 authentication
.add_option(
713 '--client-certificate',
714 dest
='client_certificate', metavar
='CERTFILE',
715 help='Path to client certificate file in PEM format. May include the private key')
716 authentication
.add_option(
717 '--client-certificate-key',
718 dest
='client_certificate_key', metavar
='KEYFILE',
719 help='Path to private key file for client certificate')
720 authentication
.add_option(
721 '--client-certificate-password',
722 dest
='client_certificate_password', metavar
='PASSWORD',
723 help='Password for client certificate private key, if encrypted. '
724 'If not provided, and the key is encrypted, yt-dlp will ask interactively')
726 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
727 video_format
.add_option(
729 action
='store', dest
='format', metavar
='FORMAT', default
=None,
730 help='Video format code, see "FORMAT SELECTION" for more details')
731 video_format
.add_option(
732 '-S', '--format-sort', metavar
='SORTORDER',
733 dest
='format_sort', default
=[], type='str', action
='callback',
734 callback
=_list_from_options_callback
, callback_kwargs
={'append': -1}
,
735 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
736 video_format
.add_option(
737 '--format-sort-force', '--S-force',
738 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
740 'Force user specified sort order to have precedence over all fields, '
741 'see "Sorting Formats" for more details (Alias: --S-force)'))
742 video_format
.add_option(
743 '--no-format-sort-force',
744 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
745 help='Some fields have precedence over the user specified sort order (default)')
746 video_format
.add_option(
747 '--video-multistreams',
748 action
='store_true', dest
='allow_multiple_video_streams', default
=None,
749 help='Allow multiple video streams to be merged into a single file')
750 video_format
.add_option(
751 '--no-video-multistreams',
752 action
='store_false', dest
='allow_multiple_video_streams',
753 help='Only one video stream is downloaded for each output file (default)')
754 video_format
.add_option(
755 '--audio-multistreams',
756 action
='store_true', dest
='allow_multiple_audio_streams', default
=None,
757 help='Allow multiple audio streams to be merged into a single file')
758 video_format
.add_option(
759 '--no-audio-multistreams',
760 action
='store_false', dest
='allow_multiple_audio_streams',
761 help='Only one audio stream is downloaded for each output file (default)')
762 video_format
.add_option(
764 action
='store_const', dest
='format', const
='all',
765 help=optparse
.SUPPRESS_HELP
)
766 video_format
.add_option(
767 '--prefer-free-formats',
768 action
='store_true', dest
='prefer_free_formats', default
=False,
770 'Prefer video formats with free containers over non-free ones of same quality. '
771 'Use with "-S ext" to strictly prefer free containers irrespective of quality'))
772 video_format
.add_option(
773 '--no-prefer-free-formats',
774 action
='store_false', dest
='prefer_free_formats', default
=False,
775 help="Don't give any special preference to free containers (default)")
776 video_format
.add_option(
778 action
='store_const', const
='selected', dest
='check_formats', default
=None,
779 help='Make sure formats are selected only from those that are actually downloadable')
780 video_format
.add_option(
781 '--check-all-formats',
782 action
='store_true', dest
='check_formats',
783 help='Check all formats for whether they are actually downloadable')
784 video_format
.add_option(
785 '--no-check-formats',
786 action
='store_false', dest
='check_formats',
787 help='Do not check that the formats are actually downloadable')
788 video_format
.add_option(
789 '-F', '--list-formats',
790 action
='store_true', dest
='listformats',
791 help='List available formats of each video. Simulate unless --no-simulate is used')
792 video_format
.add_option(
793 '--list-formats-as-table',
794 action
='store_true', dest
='listformats_table', default
=True,
795 help=optparse
.SUPPRESS_HELP
)
796 video_format
.add_option(
797 '--list-formats-old', '--no-list-formats-as-table',
798 action
='store_false', dest
='listformats_table',
799 help=optparse
.SUPPRESS_HELP
)
800 video_format
.add_option(
801 '--merge-output-format',
802 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
804 'Containers that may be used when merging formats, separated by "/", e.g. "mp4/mkv". '
805 'Ignored if no merge is required. '
806 f
'(currently supported: {", ".join(sorted(FFmpegMergerPP.SUPPORTED_EXTS))})'))
807 video_format
.add_option(
808 '--allow-unplayable-formats',
809 action
='store_true', dest
='allow_unplayable_formats', default
=False,
810 help=optparse
.SUPPRESS_HELP
)
811 video_format
.add_option(
812 '--no-allow-unplayable-formats',
813 action
='store_false', dest
='allow_unplayable_formats',
814 help=optparse
.SUPPRESS_HELP
)
816 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
817 subtitles
.add_option(
818 '--write-subs', '--write-srt',
819 action
='store_true', dest
='writesubtitles', default
=False,
820 help='Write subtitle file')
821 subtitles
.add_option(
822 '--no-write-subs', '--no-write-srt',
823 action
='store_false', dest
='writesubtitles',
824 help='Do not write subtitle file (default)')
825 subtitles
.add_option(
826 '--write-auto-subs', '--write-automatic-subs',
827 action
='store_true', dest
='writeautomaticsub', default
=False,
828 help='Write automatically generated subtitle file (Alias: --write-automatic-subs)')
829 subtitles
.add_option(
830 '--no-write-auto-subs', '--no-write-automatic-subs',
831 action
='store_false', dest
='writeautomaticsub', default
=False,
832 help='Do not write auto-generated subtitles (default) (Alias: --no-write-automatic-subs)')
833 subtitles
.add_option(
835 action
='store_true', dest
='allsubtitles', default
=False,
836 help=optparse
.SUPPRESS_HELP
)
837 subtitles
.add_option(
839 action
='store_true', dest
='listsubtitles', default
=False,
840 help='List available subtitles of each video. Simulate unless --no-simulate is used')
841 subtitles
.add_option(
843 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
844 help='Subtitle format; accepts formats preference, e.g. "srt" or "ass/srt/best"')
845 subtitles
.add_option(
846 '--sub-langs', '--srt-langs',
847 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
848 default
=[], callback
=_list_from_options_callback
,
850 'Languages of the subtitles to download (can be regex) or "all" separated by commas, e.g. --sub-langs "en.*,ja". '
851 'You can prefix the language code with a "-" to exclude it from the requested languages, e.g. --sub-langs all,-live_chat. '
852 'Use --list-subs for a list of available language tags'))
854 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
855 downloader
.add_option(
856 '-N', '--concurrent-fragments',
857 dest
='concurrent_fragment_downloads', metavar
='N', default
=1, type=int,
858 help='Number of fragments of a dash/hlsnative video that should be downloaded concurrently (default is %default)')
859 downloader
.add_option(
860 '-r', '--limit-rate', '--rate-limit',
861 dest
='ratelimit', metavar
='RATE',
862 help='Maximum download rate in bytes per second, e.g. 50K or 4.2M')
863 downloader
.add_option(
865 dest
='throttledratelimit', metavar
='RATE',
866 help='Minimum download rate in bytes per second below which throttling is assumed and the video data is re-extracted, e.g. 100K')
867 downloader
.add_option(
869 dest
='retries', metavar
='RETRIES', default
=10,
870 help='Number of retries (default is %default), or "infinite"')
871 downloader
.add_option(
872 '--file-access-retries',
873 dest
='file_access_retries', metavar
='RETRIES', default
=3,
874 help='Number of times to retry on file access error (default is %default), or "infinite"')
875 downloader
.add_option(
876 '--fragment-retries',
877 dest
='fragment_retries', metavar
='RETRIES', default
=10,
878 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
879 downloader
.add_option(
881 dest
='retry_sleep', metavar
='[TYPE:]EXPR', default
={}, type='str',
882 action
='callback', callback
=_dict_from_options_callback
,
884 'allowed_keys': 'http|fragment|file_access|extractor',
885 'default_key': 'http',
887 'Time to sleep between retries in seconds (optionally) prefixed by the type of retry '
888 '(http (default), fragment, file_access, extractor) to apply the sleep to. '
889 'EXPR can be a number, linear=START[:END[:STEP=1]] or exp=START[:END[:BASE=2]]. '
890 'This option can be used multiple times to set the sleep for the different retry types, '
891 'e.g. --retry-sleep linear=1::2 --retry-sleep fragment:exp=1:20'))
892 downloader
.add_option(
893 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragments',
894 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
895 help='Skip unavailable fragments for DASH, hlsnative and ISM downloads (default) (Alias: --no-abort-on-unavailable-fragments)')
896 downloader
.add_option(
897 '--abort-on-unavailable-fragments', '--no-skip-unavailable-fragments',
898 action
='store_false', dest
='skip_unavailable_fragments',
899 help='Abort download if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
900 downloader
.add_option(
902 action
='store_true', dest
='keep_fragments', default
=False,
903 help='Keep downloaded fragments on disk after downloading is finished')
904 downloader
.add_option(
905 '--no-keep-fragments',
906 action
='store_false', dest
='keep_fragments',
907 help='Delete downloaded fragments after downloading is finished (default)')
908 downloader
.add_option(
910 dest
='buffersize', metavar
='SIZE', default
='1024',
911 help='Size of download buffer, e.g. 1024 or 16K (default is %default)')
912 downloader
.add_option(
914 action
='store_false', dest
='noresizebuffer',
915 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
916 downloader
.add_option(
917 '--no-resize-buffer',
918 action
='store_true', dest
='noresizebuffer', default
=False,
919 help='Do not automatically adjust the buffer size')
920 downloader
.add_option(
922 dest
='http_chunk_size', metavar
='SIZE', default
=None,
924 'Size of a chunk for chunk-based HTTP downloading, e.g. 10485760 or 10M (default is disabled). '
925 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
926 downloader
.add_option(
928 action
='store_true', dest
='test', default
=False,
929 help=optparse
.SUPPRESS_HELP
)
930 downloader
.add_option(
931 '--playlist-reverse',
932 action
='store_true', dest
='playlist_reverse',
933 help=optparse
.SUPPRESS_HELP
)
934 downloader
.add_option(
935 '--no-playlist-reverse',
936 action
='store_false', dest
='playlist_reverse',
937 help=optparse
.SUPPRESS_HELP
)
938 downloader
.add_option(
940 action
='store_true', dest
='playlist_random',
941 help='Download playlist videos in random order')
942 downloader
.add_option(
944 action
='store_true', dest
='lazy_playlist',
945 help='Process entries in the playlist as they are received. This disables n_entries, --playlist-random and --playlist-reverse')
946 downloader
.add_option(
947 '--no-lazy-playlist',
948 action
='store_false', dest
='lazy_playlist',
949 help='Process videos in the playlist only after the entire playlist is parsed (default)')
950 downloader
.add_option(
951 '--xattr-set-filesize',
952 dest
='xattr_set_filesize', action
='store_true',
953 help='Set file xattribute ytdl.filesize with expected file size')
954 downloader
.add_option(
955 '--hls-prefer-native',
956 dest
='hls_prefer_native', action
='store_true', default
=None,
957 help=optparse
.SUPPRESS_HELP
)
958 downloader
.add_option(
959 '--hls-prefer-ffmpeg',
960 dest
='hls_prefer_native', action
='store_false', default
=None,
961 help=optparse
.SUPPRESS_HELP
)
962 downloader
.add_option(
964 dest
='hls_use_mpegts', action
='store_true', default
=None,
966 'Use the mpegts container for HLS videos; '
967 'allowing some players to play the video while downloading, '
968 'and reducing the chance of file corruption if download is interrupted. '
969 'This is enabled by default for live streams'))
970 downloader
.add_option(
971 '--no-hls-use-mpegts',
972 dest
='hls_use_mpegts', action
='store_false',
974 'Do not use the mpegts container for HLS videos. '
975 'This is default when not downloading live streams'))
976 downloader
.add_option(
977 '--download-sections',
978 metavar
='REGEX', dest
='download_ranges', action
='append',
980 'Download only chapters whose title matches the given regular expression. '
981 'Time ranges prefixed by a "*" can also be used in place of chapters to download the specified range. '
982 'Needs ffmpeg. This option can be used multiple times to download multiple sections, '
983 'e.g. --download-sections "*10:15-inf" --download-sections "intro"'))
984 downloader
.add_option(
985 '--downloader', '--external-downloader',
986 dest
='external_downloader', metavar
='[PROTO:]NAME', default
={}, type='str',
987 action
='callback', callback
=_dict_from_options_callback
,
989 'allowed_keys': 'http|ftp|m3u8|dash|rtsp|rtmp|mms',
990 'default_key': 'default',
993 'Name or path of the external downloader to use (optionally) prefixed by '
994 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. '
995 f
'Currently supports native, {", ".join(sorted(list_external_downloaders()))}. '
996 'You can use this option multiple times to set different downloaders for different protocols. '
997 'E.g. --downloader aria2c --downloader "dash,m3u8:native" will use '
998 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads '
999 '(Alias: --external-downloader)'))
1000 downloader
.add_option(
1001 '--downloader-args', '--external-downloader-args',
1002 metavar
='NAME:ARGS', dest
='external_downloader_args', default
={}, type='str',
1003 action
='callback', callback
=_dict_from_options_callback
,
1005 'allowed_keys': r
'ffmpeg_[io]\d*|%s' % '|'.join(map(re
.escape
, list_external_downloaders())),
1006 'default_key': 'default',
1007 'process': shlex
.split
1009 'Give these arguments to the external downloader. '
1010 'Specify the downloader name and the arguments separated by a colon ":". '
1011 'For ffmpeg, arguments can be passed to different positions using the same syntax as --postprocessor-args. '
1012 'You can use this option multiple times to give different arguments to different downloaders '
1013 '(Alias: --external-downloader-args)'))
1015 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
1016 workarounds
.add_option(
1018 dest
='encoding', metavar
='ENCODING',
1019 help='Force the specified encoding (experimental)')
1020 workarounds
.add_option(
1021 '--legacy-server-connect',
1022 action
='store_true', dest
='legacy_server_connect', default
=False,
1023 help='Explicitly allow HTTPS connection to servers that do not support RFC 5746 secure renegotiation')
1024 workarounds
.add_option(
1025 '--no-check-certificates',
1026 action
='store_true', dest
='no_check_certificate', default
=False,
1027 help='Suppress HTTPS certificate validation')
1028 workarounds
.add_option(
1029 '--prefer-insecure', '--prefer-unsecure',
1030 action
='store_true', dest
='prefer_insecure',
1031 help='Use an unencrypted connection to retrieve information about the video (Currently supported only for YouTube)')
1032 workarounds
.add_option(
1034 metavar
='UA', dest
='user_agent',
1035 help=optparse
.SUPPRESS_HELP
)
1036 workarounds
.add_option(
1038 metavar
='URL', dest
='referer', default
=None,
1039 help=optparse
.SUPPRESS_HELP
)
1040 workarounds
.add_option(
1042 metavar
='FIELD:VALUE', dest
='headers', default
={}, type='str',
1043 action
='callback', callback
=_dict_from_options_callback
,
1044 callback_kwargs
={'multiple_keys': False}
,
1045 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
1047 workarounds
.add_option(
1048 '--bidi-workaround',
1049 dest
='bidi_workaround', action
='store_true',
1050 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
1051 workarounds
.add_option(
1052 '--sleep-requests', metavar
='SECONDS',
1053 dest
='sleep_interval_requests', type=float,
1054 help='Number of seconds to sleep between requests during data extraction')
1055 workarounds
.add_option(
1056 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
1057 dest
='sleep_interval', type=float,
1059 'Number of seconds to sleep before each download. '
1060 'This is the minimum time to sleep when used along with --max-sleep-interval '
1061 '(Alias: --min-sleep-interval)'))
1062 workarounds
.add_option(
1063 '--max-sleep-interval', metavar
='SECONDS',
1064 dest
='max_sleep_interval', type=float,
1065 help='Maximum number of seconds to sleep. Can only be used along with --min-sleep-interval')
1066 workarounds
.add_option(
1067 '--sleep-subtitles', metavar
='SECONDS',
1068 dest
='sleep_interval_subtitles', default
=0, type=int,
1069 help='Number of seconds to sleep before each subtitle download')
1071 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity and Simulation Options')
1072 verbosity
.add_option(
1074 action
='store_true', dest
='quiet', default
=False,
1075 help='Activate quiet mode. If used with --verbose, print the log to stderr')
1076 verbosity
.add_option(
1078 dest
='no_warnings', action
='store_true', default
=False,
1079 help='Ignore warnings')
1080 verbosity
.add_option(
1082 action
='store_true', dest
='simulate', default
=None,
1083 help='Do not download the video and do not write anything to disk')
1084 verbosity
.add_option(
1086 action
='store_false', dest
='simulate',
1087 help='Download the video even if printing/listing options are used')
1088 verbosity
.add_option(
1089 '--ignore-no-formats-error',
1090 action
='store_true', dest
='ignore_no_formats_error', default
=False,
1092 'Ignore "No video formats" error. Useful for extracting metadata '
1093 'even if the videos are not actually available for download (experimental)'))
1094 verbosity
.add_option(
1095 '--no-ignore-no-formats-error',
1096 action
='store_false', dest
='ignore_no_formats_error',
1097 help='Throw error when no downloadable video formats are found (default)')
1098 verbosity
.add_option(
1099 '--skip-download', '--no-download',
1100 action
='store_true', dest
='skip_download', default
=False,
1101 help='Do not download the video but write all related files (Alias: --no-download)')
1102 verbosity
.add_option(
1104 metavar
='[WHEN:]TEMPLATE', dest
='forceprint', **when_prefix('video'),
1106 'Field name or output template to print to screen, optionally prefixed with when to print it, separated by a ":". '
1107 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: video). '
1108 'Implies --quiet. Implies --simulate unless --no-simulate or later stages of WHEN are used. '
1109 'This option can be used multiple times'))
1110 verbosity
.add_option(
1112 metavar
='[WHEN:]TEMPLATE FILE', dest
='print_to_file', nargs
=2, **when_prefix('video'),
1114 'Append given template to the file. The values of WHEN and TEMPLATE are same as that of --print. '
1115 'FILE uses the same syntax as the output template. This option can be used multiple times'))
1116 verbosity
.add_option(
1118 action
='store_true', dest
='geturl', default
=False,
1119 help=optparse
.SUPPRESS_HELP
)
1120 verbosity
.add_option(
1121 '-e', '--get-title',
1122 action
='store_true', dest
='gettitle', default
=False,
1123 help=optparse
.SUPPRESS_HELP
)
1124 verbosity
.add_option(
1126 action
='store_true', dest
='getid', default
=False,
1127 help=optparse
.SUPPRESS_HELP
)
1128 verbosity
.add_option(
1130 action
='store_true', dest
='getthumbnail', default
=False,
1131 help=optparse
.SUPPRESS_HELP
)
1132 verbosity
.add_option(
1133 '--get-description',
1134 action
='store_true', dest
='getdescription', default
=False,
1135 help=optparse
.SUPPRESS_HELP
)
1136 verbosity
.add_option(
1138 action
='store_true', dest
='getduration', default
=False,
1139 help=optparse
.SUPPRESS_HELP
)
1140 verbosity
.add_option(
1142 action
='store_true', dest
='getfilename', default
=False,
1143 help=optparse
.SUPPRESS_HELP
)
1144 verbosity
.add_option(
1146 action
='store_true', dest
='getformat', default
=False,
1147 help=optparse
.SUPPRESS_HELP
)
1148 verbosity
.add_option(
1149 '-j', '--dump-json',
1150 action
='store_true', dest
='dumpjson', default
=False,
1151 help='Quiet, but print JSON information for each video. Simulate unless --no-simulate is used. See "OUTPUT TEMPLATE" for a description of available keys')
1152 verbosity
.add_option(
1153 '-J', '--dump-single-json',
1154 action
='store_true', dest
='dump_single_json', default
=False,
1156 'Quiet, but print JSON information for each url or infojson passed. Simulate unless --no-simulate is used. '
1157 'If the URL refers to a playlist, the whole playlist information is dumped in a single line'))
1158 verbosity
.add_option(
1160 action
='store_true', dest
='print_json', default
=False,
1161 help=optparse
.SUPPRESS_HELP
)
1162 verbosity
.add_option(
1163 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
1164 action
='store_true', dest
='force_write_download_archive', default
=False,
1166 'Force download archive entries to be written as far as no errors occur, '
1167 'even if -s or another simulation option is used (Alias: --force-download-archive)'))
1168 verbosity
.add_option(
1170 action
='store_true', dest
='progress_with_newline', default
=False,
1171 help='Output progress bar as new lines')
1172 verbosity
.add_option(
1174 action
='store_true', dest
='noprogress', default
=None,
1175 help='Do not print progress bar')
1176 verbosity
.add_option(
1178 action
='store_false', dest
='noprogress',
1179 help='Show progress bar, even if in quiet mode')
1180 verbosity
.add_option(
1182 action
='store_true', dest
='consoletitle', default
=False,
1183 help='Display progress in console titlebar')
1184 verbosity
.add_option(
1185 '--progress-template',
1186 metavar
='[TYPES:]TEMPLATE', dest
='progress_template', default
={}, type='str',
1187 action
='callback', callback
=_dict_from_options_callback
,
1189 'allowed_keys': '(download|postprocess)(-title)?',
1190 'default_key': 'download'
1192 'Template for progress outputs, optionally prefixed with one of "download:" (default), '
1193 '"download-title:" (the console title), "postprocess:", or "postprocess-title:". '
1194 'The video\'s fields are accessible under the "info" key and '
1195 'the progress attributes are accessible under "progress" key. E.g. '
1196 # TODO: Document the fields inside "progress"
1197 '--console-title --progress-template "download-title:%(info.id)s-%(progress.eta)s"'))
1198 verbosity
.add_option(
1200 action
='store_true', dest
='verbose', default
=False,
1201 help='Print various debugging information')
1202 verbosity
.add_option(
1203 '--dump-pages', '--dump-intermediate-pages',
1204 action
='store_true', dest
='dump_intermediate_pages', default
=False,
1205 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
1206 verbosity
.add_option(
1208 action
='store_true', dest
='write_pages', default
=False,
1209 help='Write downloaded intermediary pages to files in the current directory to debug problems')
1210 verbosity
.add_option(
1212 action
='store_true', dest
='load_pages', default
=False,
1213 help=optparse
.SUPPRESS_HELP
)
1214 verbosity
.add_option(
1215 '--youtube-print-sig-code',
1216 action
='store_true', dest
='youtube_print_sig_code', default
=False,
1217 help=optparse
.SUPPRESS_HELP
)
1218 verbosity
.add_option(
1219 '--print-traffic', '--dump-headers',
1220 dest
='debug_printtraffic', action
='store_true', default
=False,
1221 help='Display sent and read HTTP traffic')
1222 verbosity
.add_option(
1223 '-C', '--call-home',
1224 dest
='call_home', action
='store_true', default
=False,
1225 # help='Contact the yt-dlp server for debugging')
1226 help=optparse
.SUPPRESS_HELP
)
1227 verbosity
.add_option(
1229 dest
='call_home', action
='store_false',
1230 # help='Do not contact the yt-dlp server for debugging (default)')
1231 help=optparse
.SUPPRESS_HELP
)
1233 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
1234 filesystem
.add_option(
1235 '-a', '--batch-file',
1236 dest
='batchfile', metavar
='FILE',
1238 'File containing URLs to download ("-" for stdin), one URL per line. '
1239 'Lines starting with "#", ";" or "]" are considered as comments and ignored'))
1240 filesystem
.add_option(
1242 dest
='batchfile', action
='store_const', const
=None,
1243 help='Do not read URLs from batch file (default)')
1244 filesystem
.add_option(
1245 '--id', default
=False,
1246 action
='store_true', dest
='useid', help=optparse
.SUPPRESS_HELP
)
1247 filesystem
.add_option(
1249 metavar
='[TYPES:]PATH', dest
='paths', default
={}, type='str',
1250 action
='callback', callback
=_dict_from_options_callback
,
1252 'allowed_keys': 'home|temp|%s' % '|'.join(map(re
.escape
, OUTTMPL_TYPES
.keys())),
1253 'default_key': 'home'
1255 'The paths where the files should be downloaded. '
1256 'Specify the type of file and the path separated by a colon ":". '
1257 'All the same TYPES as --output are supported. '
1258 'Additionally, you can also provide "home" (default) and "temp" paths. '
1259 'All intermediary files are first downloaded to the temp path and '
1260 'then the final files are moved over to the home path after download is finished. '
1261 'This option is ignored if --output is an absolute path'))
1262 filesystem
.add_option(
1264 metavar
='[TYPES:]TEMPLATE', dest
='outtmpl', default
={}, type='str',
1265 action
='callback', callback
=_dict_from_options_callback
,
1267 'allowed_keys': '|'.join(map(re
.escape
, OUTTMPL_TYPES
.keys())),
1268 'default_key': 'default'
1269 }, help='Output filename template; see "OUTPUT TEMPLATE" for details')
1270 filesystem
.add_option(
1271 '--output-na-placeholder',
1272 dest
='outtmpl_na_placeholder', metavar
='TEXT', default
='NA',
1273 help=('Placeholder for unavailable fields in "OUTPUT TEMPLATE" (default: "%default")'))
1274 filesystem
.add_option(
1275 '--autonumber-size',
1276 dest
='autonumber_size', metavar
='NUMBER', type=int,
1277 help=optparse
.SUPPRESS_HELP
)
1278 filesystem
.add_option(
1279 '--autonumber-start',
1280 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
1281 help=optparse
.SUPPRESS_HELP
)
1282 filesystem
.add_option(
1283 '--restrict-filenames',
1284 action
='store_true', dest
='restrictfilenames', default
=False,
1285 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
1286 filesystem
.add_option(
1287 '--no-restrict-filenames',
1288 action
='store_false', dest
='restrictfilenames',
1289 help='Allow Unicode characters, "&" and spaces in filenames (default)')
1290 filesystem
.add_option(
1291 '--windows-filenames',
1292 action
='store_true', dest
='windowsfilenames', default
=False,
1293 help='Force filenames to be Windows-compatible')
1294 filesystem
.add_option(
1295 '--no-windows-filenames',
1296 action
='store_false', dest
='windowsfilenames',
1297 help='Make filenames Windows-compatible only if using Windows (default)')
1298 filesystem
.add_option(
1299 '--trim-filenames', '--trim-file-names', metavar
='LENGTH',
1300 dest
='trim_file_name', default
=0, type=int,
1301 help='Limit the filename length (excluding extension) to the specified number of characters')
1302 filesystem
.add_option(
1303 '-w', '--no-overwrites',
1304 action
='store_false', dest
='overwrites', default
=None,
1305 help='Do not overwrite any files')
1306 filesystem
.add_option(
1307 '--force-overwrites', '--yes-overwrites',
1308 action
='store_true', dest
='overwrites',
1309 help='Overwrite all video and metadata files. This option includes --no-continue')
1310 filesystem
.add_option(
1311 '--no-force-overwrites',
1312 action
='store_const', dest
='overwrites', const
=None,
1313 help='Do not overwrite the video, but overwrite related files (default)')
1314 filesystem
.add_option(
1316 action
='store_true', dest
='continue_dl', default
=True,
1317 help='Resume partially downloaded files/fragments (default)')
1318 filesystem
.add_option(
1320 action
='store_false', dest
='continue_dl',
1322 'Do not resume partially downloaded fragments. '
1323 'If the file is not fragmented, restart download of the entire file'))
1324 filesystem
.add_option(
1326 action
='store_false', dest
='nopart', default
=False,
1327 help='Use .part files instead of writing directly into output file (default)')
1328 filesystem
.add_option(
1330 action
='store_true', dest
='nopart',
1331 help='Do not use .part files - write directly into output file')
1332 filesystem
.add_option(
1334 action
='store_true', dest
='updatetime', default
=True,
1335 help='Use the Last-modified header to set the file modification time (default)')
1336 filesystem
.add_option(
1338 action
='store_false', dest
='updatetime',
1339 help='Do not use the Last-modified header to set the file modification time')
1340 filesystem
.add_option(
1341 '--write-description',
1342 action
='store_true', dest
='writedescription', default
=False,
1343 help='Write video description to a .description file')
1344 filesystem
.add_option(
1345 '--no-write-description',
1346 action
='store_false', dest
='writedescription',
1347 help='Do not write video description (default)')
1348 filesystem
.add_option(
1349 '--write-info-json',
1350 action
='store_true', dest
='writeinfojson', default
=None,
1351 help='Write video metadata to a .info.json file (this may contain personal information)')
1352 filesystem
.add_option(
1353 '--no-write-info-json',
1354 action
='store_false', dest
='writeinfojson',
1355 help='Do not write video metadata (default)')
1356 filesystem
.add_option(
1357 '--write-annotations',
1358 action
='store_true', dest
='writeannotations', default
=False,
1359 help=optparse
.SUPPRESS_HELP
)
1360 filesystem
.add_option(
1361 '--no-write-annotations',
1362 action
='store_false', dest
='writeannotations',
1363 help=optparse
.SUPPRESS_HELP
)
1364 filesystem
.add_option(
1365 '--write-playlist-metafiles',
1366 action
='store_true', dest
='allow_playlist_files', default
=None,
1368 'Write playlist metadata in addition to the video metadata '
1369 'when using --write-info-json, --write-description etc. (default)'))
1370 filesystem
.add_option(
1371 '--no-write-playlist-metafiles',
1372 action
='store_false', dest
='allow_playlist_files',
1373 help='Do not write playlist metadata when using --write-info-json, --write-description etc.')
1374 filesystem
.add_option(
1375 '--clean-info-json', '--clean-infojson',
1376 action
='store_true', dest
='clean_infojson', default
=None,
1378 'Remove some private fields such as filenames from the infojson. '
1379 'Note that it could still contain some personal information (default)'))
1380 filesystem
.add_option(
1381 '--no-clean-info-json', '--no-clean-infojson',
1382 action
='store_false', dest
='clean_infojson',
1383 help='Write all fields to the infojson')
1384 filesystem
.add_option(
1385 '--write-comments', '--get-comments',
1386 action
='store_true', dest
='getcomments', default
=False,
1388 'Retrieve video comments to be placed in the infojson. '
1389 'The comments are fetched even without this option if the extraction is known to be quick (Alias: --get-comments)'))
1390 filesystem
.add_option(
1391 '--no-write-comments', '--no-get-comments',
1392 action
='store_false', dest
='getcomments',
1393 help='Do not retrieve video comments unless the extraction is known to be quick (Alias: --no-get-comments)')
1394 filesystem
.add_option(
1395 '--load-info-json', '--load-info',
1396 dest
='load_info_filename', metavar
='FILE',
1397 help='JSON file containing the video information (created with the "--write-info-json" option)')
1398 filesystem
.add_option(
1400 dest
='cookiefile', metavar
='FILE',
1401 help='Netscape formatted file to read cookies from and dump cookie jar in')
1402 filesystem
.add_option(
1404 action
='store_const', const
=None, dest
='cookiefile', metavar
='FILE',
1405 help='Do not read/dump cookies from/to file (default)')
1406 filesystem
.add_option(
1407 '--cookies-from-browser',
1408 dest
='cookiesfrombrowser', metavar
='BROWSER[+KEYRING][:PROFILE][::CONTAINER]',
1410 'The name of the browser to load cookies from. '
1411 f
'Currently supported browsers are: {", ".join(sorted(SUPPORTED_BROWSERS))}. '
1412 'Optionally, the KEYRING used for decrypting Chromium cookies on Linux, '
1413 'the name/path of the PROFILE to load cookies from, '
1414 'and the CONTAINER name (if Firefox) ("none" for no container) '
1415 'can be given with their respective seperators. '
1416 'By default, all containers of the most recently accessed profile are used. '
1417 f
'Currently supported keyrings are: {", ".join(map(str.lower, sorted(SUPPORTED_KEYRINGS)))}'))
1418 filesystem
.add_option(
1419 '--no-cookies-from-browser',
1420 action
='store_const', const
=None, dest
='cookiesfrombrowser',
1421 help='Do not load cookies from browser (default)')
1422 filesystem
.add_option(
1423 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
1425 'Location in the filesystem where yt-dlp can store some downloaded information '
1426 '(such as client ids and signatures) permanently. By default ${XDG_CACHE_HOME}/yt-dlp'))
1427 filesystem
.add_option(
1428 '--no-cache-dir', action
='store_false', dest
='cachedir',
1429 help='Disable filesystem caching')
1430 filesystem
.add_option(
1432 action
='store_true', dest
='rm_cachedir',
1433 help='Delete all filesystem cache files')
1435 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail Options')
1436 thumbnail
.add_option(
1437 '--write-thumbnail',
1438 action
='callback', dest
='writethumbnail', default
=False,
1439 # Should override --no-write-thumbnail, but not --write-all-thumbnail
1440 callback
=lambda option
, _
, __
, parser
: setattr(
1441 parser
.values
, option
.dest
, getattr(parser
.values
, option
.dest
) or True),
1442 help='Write thumbnail image to disk')
1443 thumbnail
.add_option(
1444 '--no-write-thumbnail',
1445 action
='store_false', dest
='writethumbnail',
1446 help='Do not write thumbnail image to disk (default)')
1447 thumbnail
.add_option(
1448 '--write-all-thumbnails',
1449 action
='store_const', dest
='writethumbnail', const
='all',
1450 help='Write all thumbnail image formats to disk')
1451 thumbnail
.add_option(
1452 '--list-thumbnails',
1453 action
='store_true', dest
='list_thumbnails', default
=False,
1454 help='List available thumbnails of each video. Simulate unless --no-simulate is used')
1456 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
1459 action
='store_true', dest
='writelink', default
=False,
1460 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
1463 action
='store_true', dest
='writeurllink', default
=False,
1464 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
1466 '--write-webloc-link',
1467 action
='store_true', dest
='writewebloclink', default
=False,
1468 help='Write a .webloc macOS internet shortcut')
1470 '--write-desktop-link',
1471 action
='store_true', dest
='writedesktoplink', default
=False,
1472 help='Write a .desktop Linux internet shortcut')
1474 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
1475 postproc
.add_option(
1476 '-x', '--extract-audio',
1477 action
='store_true', dest
='extractaudio', default
=False,
1478 help='Convert video files to audio-only files (requires ffmpeg and ffprobe)')
1479 postproc
.add_option(
1480 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
1482 'Format to convert the audio to when -x is used. '
1483 f
'(currently supported: best (default), {", ".join(sorted(FFmpegExtractAudioPP.SUPPORTED_EXTS))}). '
1484 'You can specify multiple rules using similar syntax as --remux-video'))
1485 postproc
.add_option(
1486 '--audio-quality', metavar
='QUALITY',
1487 dest
='audioquality', default
='5',
1489 'Specify ffmpeg audio quality to use when converting the audio with -x. '
1490 'Insert a value between 0 (best) and 10 (worst) for VBR or a specific bitrate like 128K (default %default)'))
1491 postproc
.add_option(
1493 metavar
='FORMAT', dest
='remuxvideo', default
=None,
1495 'Remux the video into another container if necessary '
1496 f
'(currently supported: {", ".join(FFmpegVideoRemuxerPP.SUPPORTED_EXTS)}). '
1497 'If target container does not support the video/audio codec, remuxing will fail. You can specify multiple rules; '
1498 'e.g. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 and anything else to mkv'))
1499 postproc
.add_option(
1501 metavar
='FORMAT', dest
='recodevideo', default
=None,
1502 help='Re-encode the video into another format if necessary. The syntax and supported formats are the same as --remux-video')
1503 postproc
.add_option(
1504 '--postprocessor-args', '--ppa',
1505 metavar
='NAME:ARGS', dest
='postprocessor_args', default
={}, type='str',
1506 action
='callback', callback
=_dict_from_options_callback
,
1508 'allowed_keys': r
'\w+(?:\+\w+)?',
1509 'default_key': 'default-compat',
1510 'process': shlex
.split
,
1511 'multiple_keys': False
1513 'Give these arguments to the postprocessors. '
1514 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
1515 'to give the argument to the specified postprocessor/executable. Supported PP are: '
1516 'Merger, ModifyChapters, SplitChapters, ExtractAudio, VideoRemuxer, VideoConvertor, '
1517 'Metadata, EmbedSubtitle, EmbedThumbnail, SubtitlesConvertor, ThumbnailsConvertor, '
1518 'FixupStretched, FixupM4a, FixupM3u8, FixupTimestamp and FixupDuration. '
1519 'The supported executables are: AtomicParsley, FFmpeg and FFprobe. '
1520 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
1521 'only when being used by the specified postprocessor. Additionally, for ffmpeg/ffprobe, '
1522 '"_i"/"_o" can be appended to the prefix optionally followed by a number to pass the argument '
1523 'before the specified input/output file, e.g. --ppa "Merger+ffmpeg_i1:-v quiet". '
1524 'You can use this option multiple times to give different arguments to different '
1525 'postprocessors. (Alias: --ppa)'))
1526 postproc
.add_option(
1527 '-k', '--keep-video',
1528 action
='store_true', dest
='keepvideo', default
=False,
1529 help='Keep the intermediate video file on disk after post-processing')
1530 postproc
.add_option(
1532 action
='store_false', dest
='keepvideo',
1533 help='Delete the intermediate video file after post-processing (default)')
1534 postproc
.add_option(
1535 '--post-overwrites',
1536 action
='store_false', dest
='nopostoverwrites',
1537 help='Overwrite post-processed files (default)')
1538 postproc
.add_option(
1539 '--no-post-overwrites',
1540 action
='store_true', dest
='nopostoverwrites', default
=False,
1541 help='Do not overwrite post-processed files')
1542 postproc
.add_option(
1544 action
='store_true', dest
='embedsubtitles', default
=False,
1545 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1546 postproc
.add_option(
1548 action
='store_false', dest
='embedsubtitles',
1549 help='Do not embed subtitles (default)')
1550 postproc
.add_option(
1551 '--embed-thumbnail',
1552 action
='store_true', dest
='embedthumbnail', default
=False,
1553 help='Embed thumbnail in the video as cover art')
1554 postproc
.add_option(
1555 '--no-embed-thumbnail',
1556 action
='store_false', dest
='embedthumbnail',
1557 help='Do not embed thumbnail (default)')
1558 postproc
.add_option(
1559 '--embed-metadata', '--add-metadata',
1560 action
='store_true', dest
='addmetadata', default
=False,
1562 'Embed metadata to the video file. Also embeds chapters/infojson if present '
1563 'unless --no-embed-chapters/--no-embed-info-json are used (Alias: --add-metadata)'))
1564 postproc
.add_option(
1565 '--no-embed-metadata', '--no-add-metadata',
1566 action
='store_false', dest
='addmetadata',
1567 help='Do not add metadata to file (default) (Alias: --no-add-metadata)')
1568 postproc
.add_option(
1569 '--embed-chapters', '--add-chapters',
1570 action
='store_true', dest
='addchapters', default
=None,
1571 help='Add chapter markers to the video file (Alias: --add-chapters)')
1572 postproc
.add_option(
1573 '--no-embed-chapters', '--no-add-chapters',
1574 action
='store_false', dest
='addchapters',
1575 help='Do not add chapter markers (default) (Alias: --no-add-chapters)')
1576 postproc
.add_option(
1577 '--embed-info-json',
1578 action
='store_true', dest
='embed_infojson', default
=None,
1579 help='Embed the infojson as an attachment to mkv/mka video files')
1580 postproc
.add_option(
1581 '--no-embed-info-json',
1582 action
='store_false', dest
='embed_infojson',
1583 help='Do not embed the infojson as an attachment to the video file')
1584 postproc
.add_option(
1585 '--metadata-from-title',
1586 metavar
='FORMAT', dest
='metafromtitle',
1587 help=optparse
.SUPPRESS_HELP
)
1588 postproc
.add_option(
1590 metavar
='[WHEN:]FROM:TO', dest
='parse_metadata', **when_prefix('pre_process'),
1592 'Parse additional metadata like title/artist from other fields; see "MODIFYING METADATA" for details. '
1593 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
1594 postproc
.add_option(
1595 '--replace-in-metadata',
1596 dest
='parse_metadata', metavar
='[WHEN:]FIELDS REGEX REPLACE', nargs
=3, **when_prefix('pre_process'),
1598 'Replace text in a metadata field using the given regex. This option can be used multiple times. '
1599 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: pre_process)'))
1600 postproc
.add_option(
1601 '--xattrs', '--xattr',
1602 action
='store_true', dest
='xattrs', default
=False,
1603 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1604 postproc
.add_option(
1605 '--concat-playlist',
1606 metavar
='POLICY', dest
='concat_playlist', default
='multi_video',
1607 choices
=('never', 'always', 'multi_video'),
1609 'Concatenate videos in a playlist. One of "never", "always", or '
1610 '"multi_video" (default; only when the videos form a single show). '
1611 'All the video files must have same codecs and number of streams to be concatable. '
1612 'The "pl_video:" prefix can be used with "--paths" and "--output" to '
1613 'set the output filename for the concatenated files. See "OUTPUT TEMPLATE" for details'))
1614 postproc
.add_option(
1616 metavar
='POLICY', dest
='fixup', default
=None,
1617 choices
=('never', 'ignore', 'warn', 'detect_or_warn', 'force'),
1619 'Automatically correct known faults of the file. '
1620 'One of never (do nothing), warn (only emit a warning), '
1621 'detect_or_warn (the default; fix file if we can, warn otherwise), '
1622 'force (try fixing even if file already exists)'))
1623 postproc
.add_option(
1624 '--prefer-avconv', '--no-prefer-ffmpeg',
1625 action
='store_false', dest
='prefer_ffmpeg',
1626 help=optparse
.SUPPRESS_HELP
)
1627 postproc
.add_option(
1628 '--prefer-ffmpeg', '--no-prefer-avconv',
1629 action
='store_true', dest
='prefer_ffmpeg', default
=True,
1630 help=optparse
.SUPPRESS_HELP
)
1631 postproc
.add_option(
1632 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
1633 dest
='ffmpeg_location',
1634 help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
1635 postproc
.add_option(
1637 metavar
='[WHEN:]CMD', dest
='exec_cmd', **when_prefix('after_move'),
1639 'Execute a command, optionally prefixed with when to execute it, separated by a ":". '
1640 'Supported values of "WHEN" are the same as that of --use-postprocessor (default: after_move). '
1641 'Same syntax as the output template can be used to pass any field as arguments to the command. '
1642 'After download, an additional field "filepath" that contains the final path of the downloaded file '
1643 'is also available, and if no fields are passed, %(filepath,_filename|)q is appended to the end of the command. '
1644 'This option can be used multiple times'))
1645 postproc
.add_option(
1647 action
='store_const', dest
='exec_cmd', const
={},
1648 help='Remove any previously defined --exec')
1649 postproc
.add_option(
1650 '--exec-before-download', metavar
='CMD',
1651 action
='append', dest
='exec_before_dl_cmd',
1652 help=optparse
.SUPPRESS_HELP
)
1653 postproc
.add_option(
1654 '--no-exec-before-download',
1655 action
='store_const', dest
='exec_before_dl_cmd', const
=None,
1656 help=optparse
.SUPPRESS_HELP
)
1657 postproc
.add_option(
1658 '--convert-subs', '--convert-sub', '--convert-subtitles',
1659 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
1661 'Convert the subtitles to another format (currently supported: %s) '
1662 '(Alias: --convert-subtitles)' % ', '.join(sorted(FFmpegSubtitlesConvertorPP
.SUPPORTED_EXTS
))))
1663 postproc
.add_option(
1664 '--convert-thumbnails',
1665 metavar
='FORMAT', dest
='convertthumbnails', default
=None,
1667 'Convert the thumbnails to another format '
1668 f
'(currently supported: {", ".join(sorted(FFmpegThumbnailsConvertorPP.SUPPORTED_EXTS))}). '
1669 'You can specify multiple rules using similar syntax as --remux-video'))
1670 postproc
.add_option(
1671 '--split-chapters', '--split-tracks',
1672 dest
='split_chapters', action
='store_true', default
=False,
1674 'Split video into multiple files based on internal chapters. '
1675 'The "chapter:" prefix can be used with "--paths" and "--output" to '
1676 'set the output filename for the split files. See "OUTPUT TEMPLATE" for details'))
1677 postproc
.add_option(
1678 '--no-split-chapters', '--no-split-tracks',
1679 dest
='split_chapters', action
='store_false',
1680 help='Do not split video based on chapters (default)')
1681 postproc
.add_option(
1682 '--remove-chapters',
1683 metavar
='REGEX', dest
='remove_chapters', action
='append',
1685 'Remove chapters whose title matches the given regular expression. '
1686 'The syntax is the same as --download-sections. This option can be used multiple times'))
1687 postproc
.add_option(
1688 '--no-remove-chapters', dest
='remove_chapters', action
='store_const', const
=None,
1689 help='Do not remove any chapters from the file (default)')
1690 postproc
.add_option(
1691 '--force-keyframes-at-cuts',
1692 action
='store_true', dest
='force_keyframes_at_cuts', default
=False,
1694 'Force keyframes at cuts when downloading/splitting/removing sections. '
1695 'This is slow due to needing a re-encode, but the resulting video may have fewer artifacts around the cuts'))
1696 postproc
.add_option(
1697 '--no-force-keyframes-at-cuts',
1698 action
='store_false', dest
='force_keyframes_at_cuts',
1699 help='Do not force keyframes around the chapters when cutting/splitting (default)')
1700 _postprocessor_opts_parser
= lambda key
, val
='': (
1701 *(item
.split('=', 1) for item
in (val
.split(';') if val
else [])),
1702 ('key', remove_end(key
, 'PP')))
1703 postproc
.add_option(
1704 '--use-postprocessor',
1705 metavar
='NAME[:ARGS]', dest
='add_postprocessors', default
=[], type='str',
1706 action
='callback', callback
=_list_from_options_callback
,
1709 'process': lambda val
: dict(_postprocessor_opts_parser(*val
.split(':', 1)))
1711 'The (case sensitive) name of plugin postprocessors to be enabled, '
1712 'and (optionally) arguments to be passed to it, separated by a colon ":". '
1713 'ARGS are a semicolon ";" delimited list of NAME=VALUE. '
1714 'The "when" argument determines when the postprocessor is invoked. '
1715 'It can be one of "pre_process" (after video extraction), "after_filter" (after video passes filter), '
1716 '"video" (after --format; before --print/--output), "before_dl" (before each video download), '
1717 '"post_process" (after each video download; default), '
1718 '"after_move" (after moving video file to it\'s final locations), '
1719 '"after_video" (after downloading and processing all formats of a video), '
1720 'or "playlist" (at end of playlist). '
1721 'This option can be used multiple times to add different postprocessors'))
1723 sponsorblock
= optparse
.OptionGroup(parser
, 'SponsorBlock Options', description
=(
1724 'Make chapter entries for, or remove various segments (sponsor, introductions, etc.) '
1725 'from downloaded YouTube videos using the SponsorBlock API (https://sponsor.ajay.app)'))
1726 sponsorblock
.add_option(
1727 '--sponsorblock-mark', metavar
='CATS',
1728 dest
='sponsorblock_mark', default
=set(), action
='callback', type='str',
1729 callback
=_set_from_options_callback
, callback_kwargs
={
1730 'allowed_values': SponsorBlockPP
.CATEGORIES
.keys(),
1731 'aliases': {'default': ['all']}
1733 'SponsorBlock categories to create chapters for, separated by commas. '
1734 f
'Available categories are {", ".join(SponsorBlockPP.CATEGORIES.keys())}, all and default (=all). '
1735 'You can prefix the category with a "-" to exclude it. See [1] for description of the categories. '
1736 'E.g. --sponsorblock-mark all,-preview [1] https://wiki.sponsor.ajay.app/w/Segment_Categories'))
1737 sponsorblock
.add_option(
1738 '--sponsorblock-remove', metavar
='CATS',
1739 dest
='sponsorblock_remove', default
=set(), action
='callback', type='str',
1740 callback
=_set_from_options_callback
, callback_kwargs
={
1741 'allowed_values': set(SponsorBlockPP
.CATEGORIES
.keys()) - set(SponsorBlockPP
.NON_SKIPPABLE_CATEGORIES
.keys()),
1742 # Note: From https://wiki.sponsor.ajay.app/w/Types:
1743 # The filler category is very aggressive.
1744 # It is strongly recommended to not use this in a client by default.
1745 'aliases': {'default': ['all', '-filler']}
1747 'SponsorBlock categories to be removed from the video file, separated by commas. '
1748 'If a category is present in both mark and remove, remove takes precedence. '
1749 'The syntax and available categories are the same as for --sponsorblock-mark '
1750 'except that "default" refers to "all,-filler" '
1751 f
'and {", ".join(SponsorBlockPP.NON_SKIPPABLE_CATEGORIES.keys())} are not available'))
1752 sponsorblock
.add_option(
1753 '--sponsorblock-chapter-title', metavar
='TEMPLATE',
1754 default
=DEFAULT_SPONSORBLOCK_CHAPTER_TITLE
, dest
='sponsorblock_chapter_title',
1756 'An output template for the title of the SponsorBlock chapters created by --sponsorblock-mark. '
1757 'The only available fields are start_time, end_time, category, categories, name, category_names. '
1758 'Defaults to "%default"'))
1759 sponsorblock
.add_option(
1760 '--no-sponsorblock', default
=False,
1761 action
='store_true', dest
='no_sponsorblock',
1762 help='Disable both --sponsorblock-mark and --sponsorblock-remove')
1763 sponsorblock
.add_option(
1764 '--sponsorblock-api', metavar
='URL',
1765 default
='https://sponsor.ajay.app', dest
='sponsorblock_api',
1766 help='SponsorBlock API location, defaults to %default')
1768 sponsorblock
.add_option(
1770 action
='store_true', dest
='sponskrub', default
=False,
1771 help=optparse
.SUPPRESS_HELP
)
1772 sponsorblock
.add_option(
1774 action
='store_false', dest
='sponskrub',
1775 help=optparse
.SUPPRESS_HELP
)
1776 sponsorblock
.add_option(
1777 '--sponskrub-cut', default
=False,
1778 action
='store_true', dest
='sponskrub_cut',
1779 help=optparse
.SUPPRESS_HELP
)
1780 sponsorblock
.add_option(
1781 '--no-sponskrub-cut',
1782 action
='store_false', dest
='sponskrub_cut',
1783 help=optparse
.SUPPRESS_HELP
)
1784 sponsorblock
.add_option(
1785 '--sponskrub-force', default
=False,
1786 action
='store_true', dest
='sponskrub_force',
1787 help=optparse
.SUPPRESS_HELP
)
1788 sponsorblock
.add_option(
1789 '--no-sponskrub-force',
1790 action
='store_true', dest
='sponskrub_force',
1791 help=optparse
.SUPPRESS_HELP
)
1792 sponsorblock
.add_option(
1793 '--sponskrub-location', metavar
='PATH',
1794 dest
='sponskrub_path', default
='',
1795 help=optparse
.SUPPRESS_HELP
)
1796 sponsorblock
.add_option(
1797 '--sponskrub-args', dest
='sponskrub_args', metavar
='ARGS',
1798 help=optparse
.SUPPRESS_HELP
)
1800 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
1801 extractor
.add_option(
1802 '--extractor-retries',
1803 dest
='extractor_retries', metavar
='RETRIES', default
=3,
1804 help='Number of retries for known extractor errors (default is %default), or "infinite"')
1805 extractor
.add_option(
1806 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1807 action
='store_true', dest
='dynamic_mpd', default
=True,
1808 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
1809 extractor
.add_option(
1810 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1811 action
='store_false', dest
='dynamic_mpd',
1812 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
1813 extractor
.add_option(
1814 '--hls-split-discontinuity',
1815 dest
='hls_split_discontinuity', action
='store_true', default
=False,
1816 help='Split HLS playlists to different formats at discontinuities such as ad breaks'
1818 extractor
.add_option(
1819 '--no-hls-split-discontinuity',
1820 dest
='hls_split_discontinuity', action
='store_false',
1821 help='Do not split HLS playlists to different formats at discontinuities such as ad breaks (default)')
1822 _extractor_arg_parser
= lambda key
, vals
='': (key
.strip().lower().replace('-', '_'), [
1823 val
.replace(r
'\,', ',').strip() for val
in re
.split(r
'(?<!\\),', vals
)])
1824 extractor
.add_option(
1826 metavar
='IE_KEY:ARGS', dest
='extractor_args', default
={}, type='str',
1827 action
='callback', callback
=_dict_from_options_callback
,
1829 'multiple_keys': False,
1830 'process': lambda val
: dict(
1831 _extractor_arg_parser(*arg
.split('=', 1)) for arg
in val
.split(';'))
1833 'Pass ARGS arguments to the IE_KEY extractor. See "EXTRACTOR ARGUMENTS" for details. '
1834 'You can use this option multiple times to give arguments for different extractors'))
1835 extractor
.add_option(
1836 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
1837 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
1838 help=optparse
.SUPPRESS_HELP
)
1839 extractor
.add_option(
1840 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
1841 action
='store_false', dest
='youtube_include_dash_manifest',
1842 help=optparse
.SUPPRESS_HELP
)
1843 extractor
.add_option(
1844 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
1845 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
1846 help=optparse
.SUPPRESS_HELP
)
1847 extractor
.add_option(
1848 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
1849 action
='store_false', dest
='youtube_include_hls_manifest',
1850 help=optparse
.SUPPRESS_HELP
)
1852 parser
.add_option_group(general
)
1853 parser
.add_option_group(network
)
1854 parser
.add_option_group(geo
)
1855 parser
.add_option_group(selection
)
1856 parser
.add_option_group(downloader
)
1857 parser
.add_option_group(filesystem
)
1858 parser
.add_option_group(thumbnail
)
1859 parser
.add_option_group(link
)
1860 parser
.add_option_group(verbosity
)
1861 parser
.add_option_group(workarounds
)
1862 parser
.add_option_group(video_format
)
1863 parser
.add_option_group(subtitles
)
1864 parser
.add_option_group(authentication
)
1865 parser
.add_option_group(postproc
)
1866 parser
.add_option_group(sponsorblock
)
1867 parser
.add_option_group(extractor
)
1872 def _hide_login_info(opts
):
1873 deprecation_warning(f
'"{__name__}._hide_login_info" is deprecated and may be removed '
1874 'in a future version. Use "yt_dlp.utils.Config.hide_login_info" instead')
1875 return Config
.hide_login_info(opts
)