1 from __future__
import unicode_literals
8 from .downloader
.external
import list_external_downloaders
11 compat_get_terminal_size
,
24 from .version
import __version__
27 def _hide_login_info(opts
):
28 PRIVATE_OPTS
= set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
29 eqre
= re
.compile('^(?P<key>' + ('|'.join(re
.escape(po
) for po
in PRIVATE_OPTS
)) + ')=.+$')
34 return m
.group('key') + '=PRIVATE'
38 opts
= list(map(_scrub_eq
, opts
))
39 for idx
, opt
in enumerate(opts
):
40 if opt
in PRIVATE_OPTS
and idx
+ 1 < len(opts
):
41 opts
[idx
+ 1] = 'PRIVATE'
45 def parseOpts(overrideArguments
=None):
46 def _readOptions(filename_bytes
, default
=[]):
48 optionf
= open(filename_bytes
)
50 return default
# silently skip if file is not present
52 # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
53 contents
= optionf
.read()
54 if sys
.version_info
< (3,):
55 contents
= contents
.decode(preferredencoding())
56 res
= compat_shlex_split(contents
, comments
=True)
61 def _readUserConf(package_name
, default
=[]):
63 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME') or compat_expanduser('~/.config')
64 userConfFile
= os
.path
.join(xdg_config_home
, package_name
, 'config')
65 if not os
.path
.isfile(userConfFile
):
66 userConfFile
= os
.path
.join(xdg_config_home
, '%s.conf' % package_name
)
67 userConf
= _readOptions(userConfFile
, default
=None)
68 if userConf
is not None:
69 return userConf
, userConfFile
72 appdata_dir
= compat_getenv('appdata')
74 userConfFile
= os
.path
.join(appdata_dir
, package_name
, 'config')
75 userConf
= _readOptions(userConfFile
, default
=None)
77 userConfFile
+= '.txt'
78 userConf
= _readOptions(userConfFile
, default
=None)
79 if userConf
is not None:
80 return userConf
, userConfFile
83 userConfFile
= os
.path
.join(compat_expanduser('~'), '%s.conf' % package_name
)
84 userConf
= _readOptions(userConfFile
, default
=None)
86 userConfFile
+= '.txt'
87 userConf
= _readOptions(userConfFile
, default
=None)
88 if userConf
is not None:
89 return userConf
, userConfFile
93 def _format_option_string(option
):
94 ''' ('-o', '--option') -> -o, --format METAVAR'''
98 if option
._short
_opts
:
99 opts
.append(option
._short
_opts
[0])
100 if option
._long
_opts
:
101 opts
.append(option
._long
_opts
[0])
105 if option
.takes_value():
106 opts
.append(' %s' % option
.metavar
)
110 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
, prepend
=True):
112 parser
.values
, option
.dest
,
113 value
.split(',') if not prepend
114 else value
.split(',') + getattr(parser
.values
, option
.dest
))
116 def _dict_from_multiple_values_options_callback(
117 option
, opt_str
, value
, parser
,
118 allowed_keys
=r
'[\w-]+', delimiter
=':', default_key
=None, process
=None, multiple_keys
=True):
120 out_dict
= getattr(parser
.values
, option
.dest
)
122 allowed_keys
= r
'(%s)(,(%s))*' % (allowed_keys
, allowed_keys
)
123 mobj
= re
.match(r
'(?i)(?P<keys>%s)%s(?P<val>.*)$' % (allowed_keys
, delimiter
), value
)
125 keys
= [k
.strip() for k
in mobj
.group('keys').lower().split(',')]
126 val
= mobj
.group('val')
127 elif default_key
is not None:
128 keys
, val
= [default_key
], value
130 raise optparse
.OptionValueError(
131 'wrong %s formatting; it should be %s, not "%s"' % (opt_str
, option
.metavar
, value
))
132 val
= process(val
) if callable(process
) else val
136 # No need to wrap help messages if we're on a wide console
137 columns
= compat_get_terminal_size().columns
138 max_width
= columns
if columns
else 80
139 max_help_position
= 80
141 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
142 fmt
.format_option_strings
= _format_option_string
145 'version': __version__
,
147 'usage': '%prog [OPTIONS] URL [URL...]',
148 'conflict_handler': 'resolve',
151 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
153 general
= optparse
.OptionGroup(parser
, 'General Options')
157 help='Print this help text and exit')
161 help='Print program version and exit')
164 action
='store_true', dest
='update_self',
165 help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
167 '-i', '--ignore-errors', '--no-abort-on-error',
168 action
='store_true', dest
='ignoreerrors', default
=None,
169 help='Continue on download errors, for example to skip unavailable videos in a playlist (default) (Alias: --no-abort-on-error)')
171 '--abort-on-error', '--no-ignore-errors',
172 action
='store_false', dest
='ignoreerrors',
173 help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
176 action
='store_true', dest
='dump_user_agent', default
=False,
177 help='Display the current browser identification')
180 action
='store_true', dest
='list_extractors', default
=False,
181 help='List all supported extractors')
183 '--extractor-descriptions',
184 action
='store_true', dest
='list_extractor_descriptions', default
=False,
185 help='Output descriptions of all supported extractors')
187 '--force-generic-extractor',
188 action
='store_true', dest
='force_generic_extractor', default
=False,
189 help='Force extraction to use the generic extractor')
192 dest
='default_search', metavar
='PREFIX',
193 help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching')
195 '--ignore-config', '--no-config',
198 'Disable loading any configuration files except the one provided by --config-location. '
199 'When given inside a configuration file, no further configuration files are loaded. '
200 'Additionally, (for backward compatibility) if this option is found inside the '
201 'system configuration file, the user configuration is not loaded'))
204 dest
='config_location', metavar
='PATH',
205 help='Location of the main configuration file; either the path to the config or its containing directory')
208 action
='store_const', dest
='extract_flat', const
='in_playlist', default
=False,
209 help='Do not extract the videos of a playlist, only list them')
212 action
='store_true', dest
='extract_flat',
213 # help='Do not resolve the video urls')
215 help=optparse
.SUPPRESS_HELP
)
217 '--no-flat-playlist',
218 action
='store_false', dest
='extract_flat',
219 help='Extract the videos of a playlist')
222 action
='store_true', dest
='mark_watched', default
=False,
223 help='Mark videos watched (YouTube only)')
226 action
='store_false', dest
='mark_watched',
227 help='Do not mark videos watched (default)')
230 action
='store_true', dest
='no_color', default
=False,
231 help='Do not emit color codes in output')
234 metavar
='OPTS', dest
='compat_opts', default
=[],
235 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
237 'Options that can help keep compatibility with youtube-dl and youtube-dlc '
238 'configurations by reverting some of the changes made in yt-dlp. '
239 'See "Differences in default behavior" for details'))
241 network
= optparse
.OptionGroup(parser
, 'Network Options')
243 '--proxy', dest
='proxy',
244 default
=None, metavar
='URL',
246 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
247 'SOCKS proxy, specify a proper scheme. For example '
248 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
249 'for direct connection'))
252 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
253 help='Time to wait before giving up, in seconds')
256 metavar
='IP', dest
='source_address', default
=None,
257 help='Client-side IP address to bind to',
260 '-4', '--force-ipv4',
261 action
='store_const', const
='0.0.0.0', dest
='source_address',
262 help='Make all connections via IPv4',
265 '-6', '--force-ipv6',
266 action
='store_const', const
='::', dest
='source_address',
267 help='Make all connections via IPv6',
270 geo
= optparse
.OptionGroup(parser
, 'Geo-restriction')
272 '--geo-verification-proxy',
273 dest
='geo_verification_proxy', default
=None, metavar
='URL',
275 'Use this proxy to verify the IP address for some geo-restricted sites. '
276 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
278 '--cn-verification-proxy',
279 dest
='cn_verification_proxy', default
=None, metavar
='URL',
280 help=optparse
.SUPPRESS_HELP
)
283 action
='store_true', dest
='geo_bypass', default
=True,
284 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
287 action
='store_false', dest
='geo_bypass', default
=True,
288 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
290 '--geo-bypass-country', metavar
='CODE',
291 dest
='geo_bypass_country', default
=None,
292 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
294 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
295 dest
='geo_bypass_ip_block', default
=None,
296 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
298 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
299 selection
.add_option(
301 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
302 help='Playlist video to start at (default is %default)')
303 selection
.add_option(
305 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
306 help='Playlist video to end at (default is last)')
307 selection
.add_option(
309 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
310 help='Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13')
311 selection
.add_option(
313 dest
='matchtitle', metavar
='REGEX',
314 help='Download only matching titles (regex or caseless sub-string)')
315 selection
.add_option(
317 dest
='rejecttitle', metavar
='REGEX',
318 help='Skip download for matching titles (regex or caseless sub-string)')
319 selection
.add_option(
321 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
322 help='Abort after downloading NUMBER files')
323 selection
.add_option(
325 metavar
='SIZE', dest
='min_filesize', default
=None,
326 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
327 selection
.add_option(
329 metavar
='SIZE', dest
='max_filesize', default
=None,
330 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
331 selection
.add_option(
333 metavar
='DATE', dest
='date', default
=None,
335 'Download only videos uploaded in this date. '
336 'The date can be "YYYYMMDD" or in the format '
337 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
338 selection
.add_option(
340 metavar
='DATE', dest
='datebefore', default
=None,
342 'Download only videos uploaded on or before this date. '
343 'The date formats accepted is the same as --date'))
344 selection
.add_option(
346 metavar
='DATE', dest
='dateafter', default
=None,
348 'Download only videos uploaded on or after this date. '
349 'The date formats accepted is the same as --date'))
350 selection
.add_option(
352 metavar
='COUNT', dest
='min_views', default
=None, type=int,
353 help='Do not download any videos with less than COUNT views')
354 selection
.add_option(
356 metavar
='COUNT', dest
='max_views', default
=None, type=int,
357 help='Do not download any videos with more than COUNT views')
358 selection
.add_option(
360 metavar
='FILTER', dest
='match_filter', default
=None,
362 'Generic video filter. '
363 'Specify any key (see "OUTPUT TEMPLATE" for a list of available keys) to '
364 'match if the key is present, '
365 '!key to check if the key is not present, '
366 'key>NUMBER (like "view_count > 12", also works with '
367 '>=, <, <=, !=, =) to compare against a number, '
368 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
369 'to match against a string literal '
370 'and & to require multiple matches. '
371 'Values which are not known are excluded unless you '
372 'put a question mark (?) after the operator. '
373 'For example, to only match videos that have been liked more than '
374 '100 times and disliked less than 50 times (or the dislike '
375 'functionality is not available at the given service), but who '
376 'also have a description, use --match-filter '
377 '"like_count > 100 & dislike_count <? 50 & description"'))
378 selection
.add_option(
380 metavar
='FILTER', dest
='match_filter', action
='store_const', const
=None,
381 help='Do not use generic video filter (default)')
382 selection
.add_option(
384 action
='store_true', dest
='noplaylist', default
=False,
385 help='Download only the video, if the URL refers to a video and a playlist')
386 selection
.add_option(
388 action
='store_false', dest
='noplaylist',
389 help='Download the playlist, if the URL refers to a video and a playlist')
390 selection
.add_option(
392 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
393 help='Download only videos suitable for the given age')
394 selection
.add_option(
395 '--download-archive', metavar
='FILE',
396 dest
='download_archive',
397 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
398 selection
.add_option(
399 '--break-on-existing',
400 action
='store_true', dest
='break_on_existing', default
=False,
401 help='Stop the download process when encountering a file that is in the archive')
402 selection
.add_option(
404 action
='store_true', dest
='break_on_reject', default
=False,
405 help='Stop the download process when encountering a file that has been filtered out')
406 selection
.add_option(
407 '--skip-playlist-after-errors', metavar
='N',
408 dest
='skip_playlist_after_errors', default
=None, type=int,
409 help='Number of allowed failures until the rest of the playlist is skipped')
410 selection
.add_option(
411 '--no-download-archive',
412 dest
='download_archive', action
="store_const", const
=None,
413 help='Do not use archive file (default)')
414 selection
.add_option(
416 dest
='include_ads', action
='store_true',
417 help=optparse
.SUPPRESS_HELP
)
418 selection
.add_option(
420 dest
='include_ads', action
='store_false',
421 help=optparse
.SUPPRESS_HELP
)
423 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
424 authentication
.add_option(
426 dest
='username', metavar
='USERNAME',
427 help='Login with this account ID')
428 authentication
.add_option(
430 dest
='password', metavar
='PASSWORD',
431 help='Account password. If this option is left out, yt-dlp will ask interactively')
432 authentication
.add_option(
434 dest
='twofactor', metavar
='TWOFACTOR',
435 help='Two-factor authentication code')
436 authentication
.add_option(
438 action
='store_true', dest
='usenetrc', default
=False,
439 help='Use .netrc authentication data')
440 authentication
.add_option(
442 dest
='videopassword', metavar
='PASSWORD',
443 help='Video password (vimeo, youku)')
444 authentication
.add_option(
446 dest
='ap_mso', metavar
='MSO',
447 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
448 authentication
.add_option(
450 dest
='ap_username', metavar
='USERNAME',
451 help='Multiple-system operator account login')
452 authentication
.add_option(
454 dest
='ap_password', metavar
='PASSWORD',
455 help='Multiple-system operator account password. If this option is left out, yt-dlp will ask interactively')
456 authentication
.add_option(
458 action
='store_true', dest
='ap_list_mso', default
=False,
459 help='List all supported multiple-system operators')
461 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
462 video_format
.add_option(
464 action
='store', dest
='format', metavar
='FORMAT', default
=None,
465 help='Video format code, see "FORMAT SELECTION" for more details')
466 video_format
.add_option(
467 '-S', '--format-sort', metavar
='SORTORDER',
468 dest
='format_sort', default
=[],
469 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
470 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
471 video_format
.add_option(
472 '--format-sort-force', '--S-force',
473 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
475 'Force user specified sort order to have precedence over all fields, '
476 'see "Sorting Formats" for more details'))
477 video_format
.add_option(
478 '--no-format-sort-force',
479 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
481 'Some fields have precedence over the user specified sort order (default), '
482 'see "Sorting Formats" for more details'))
483 video_format
.add_option(
484 '--video-multistreams',
485 action
='store_true', dest
='allow_multiple_video_streams', default
=None,
486 help='Allow multiple video streams to be merged into a single file')
487 video_format
.add_option(
488 '--no-video-multistreams',
489 action
='store_false', dest
='allow_multiple_video_streams',
490 help='Only one video stream is downloaded for each output file (default)')
491 video_format
.add_option(
492 '--audio-multistreams',
493 action
='store_true', dest
='allow_multiple_audio_streams', default
=None,
494 help='Allow multiple audio streams to be merged into a single file')
495 video_format
.add_option(
496 '--no-audio-multistreams',
497 action
='store_false', dest
='allow_multiple_audio_streams',
498 help='Only one audio stream is downloaded for each output file (default)')
499 video_format
.add_option(
501 action
='store_const', dest
='format', const
='all',
502 help=optparse
.SUPPRESS_HELP
)
503 video_format
.add_option(
504 '--prefer-free-formats',
505 action
='store_true', dest
='prefer_free_formats', default
=False,
507 'Prefer video formats with free containers over non-free ones of same quality. '
508 'Use with "-S ext" to strictly prefer free containers irrespective of quality'))
509 video_format
.add_option(
510 '--no-prefer-free-formats',
511 action
='store_true', dest
='prefer_free_formats', default
=False,
512 help="Don't give any special preference to free containers (default)")
513 video_format
.add_option(
515 action
='store_true', dest
='check_formats', default
=False,
516 help="Check that the formats selected are actually downloadable (Experimental)")
517 video_format
.add_option(
518 '-F', '--list-formats',
519 action
='store_true', dest
='listformats',
520 help='List all available formats of requested videos')
521 video_format
.add_option(
522 '--list-formats-as-table',
523 action
='store_true', dest
='listformats_table', default
=True,
524 help=optparse
.SUPPRESS_HELP
)
525 video_format
.add_option(
526 '--list-formats-old', '--no-list-formats-as-table',
527 action
='store_false', dest
='listformats_table',
528 help=optparse
.SUPPRESS_HELP
)
529 video_format
.add_option(
530 '--merge-output-format',
531 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
533 'If a merge is required (e.g. bestvideo+bestaudio), '
534 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
535 'Ignored if no merge is required'))
536 video_format
.add_option(
537 '--allow-unplayable-formats',
538 action
='store_true', dest
='allow_unplayable_formats', default
=False,
540 'Allow unplayable formats to be listed and downloaded. '
541 'All video post-processing will also be turned off'))
542 video_format
.add_option(
543 '--no-allow-unplayable-formats',
544 action
='store_false', dest
='allow_unplayable_formats',
545 help='Do not allow unplayable formats to be listed or downloaded (default)')
547 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
548 subtitles
.add_option(
549 '--write-subs', '--write-srt',
550 action
='store_true', dest
='writesubtitles', default
=False,
551 help='Write subtitle file')
552 subtitles
.add_option(
553 '--no-write-subs', '--no-write-srt',
554 action
='store_false', dest
='writesubtitles',
555 help='Do not write subtitle file (default)')
556 subtitles
.add_option(
557 '--write-auto-subs', '--write-automatic-subs',
558 action
='store_true', dest
='writeautomaticsub', default
=False,
559 help='Write automatically generated subtitle file (Alias: --write-automatic-subs)')
560 subtitles
.add_option(
561 '--no-write-auto-subs', '--no-write-automatic-subs',
562 action
='store_false', dest
='writeautomaticsub', default
=False,
563 help='Do not write auto-generated subtitles (default) (Alias: --no-write-automatic-subs)')
564 subtitles
.add_option(
566 action
='store_true', dest
='allsubtitles', default
=False,
567 help=optparse
.SUPPRESS_HELP
)
568 subtitles
.add_option(
570 action
='store_true', dest
='listsubtitles', default
=False,
571 help='List all available subtitles for the video')
572 subtitles
.add_option(
574 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
575 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
576 subtitles
.add_option(
577 '--sub-langs', '--srt-langs',
578 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
579 default
=[], callback
=_comma_separated_values_options_callback
,
581 'Languages of the subtitles to download (can be regex) or "all" separated by commas. (Eg: --sub-langs en.*,ja) '
582 'You can prefix the language code with a "-" to exempt it from the requested languages. (Eg: --sub-langs all,-live_chat) '
583 'Use --list-subs for a list of available language tags'))
585 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
586 downloader
.add_option(
587 '-N', '--concurrent-fragments',
588 dest
='concurrent_fragment_downloads', metavar
='N', default
=1, type=int,
589 help='Number of fragments of a dash/hlsnative video that should be download concurrently (default is %default)')
590 downloader
.add_option(
591 '-r', '--limit-rate', '--rate-limit',
592 dest
='ratelimit', metavar
='RATE',
593 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
594 downloader
.add_option(
596 dest
='retries', metavar
='RETRIES', default
=10,
597 help='Number of retries (default is %default), or "infinite"')
598 downloader
.add_option(
599 '--fragment-retries',
600 dest
='fragment_retries', metavar
='RETRIES', default
=10,
601 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
602 downloader
.add_option(
603 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
604 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
605 help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)')
606 downloader
.add_option(
607 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
608 action
='store_false', dest
='skip_unavailable_fragments',
609 help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
610 downloader
.add_option(
612 action
='store_true', dest
='keep_fragments', default
=False,
613 help='Keep downloaded fragments on disk after downloading is finished')
614 downloader
.add_option(
615 '--no-keep-fragments',
616 action
='store_false', dest
='keep_fragments',
617 help='Delete downloaded fragments after downloading is finished (default)')
618 downloader
.add_option(
620 dest
='buffersize', metavar
='SIZE', default
='1024',
621 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
622 downloader
.add_option(
624 action
='store_false', dest
='noresizebuffer',
625 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
626 downloader
.add_option(
627 '--no-resize-buffer',
628 action
='store_true', dest
='noresizebuffer', default
=False,
629 help='Do not automatically adjust the buffer size')
630 downloader
.add_option(
632 dest
='http_chunk_size', metavar
='SIZE', default
=None,
634 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
635 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
636 downloader
.add_option(
638 action
='store_true', dest
='test', default
=False,
639 help=optparse
.SUPPRESS_HELP
)
640 downloader
.add_option(
641 '--playlist-reverse',
643 help='Download playlist videos in reverse order')
644 downloader
.add_option(
645 '--no-playlist-reverse',
646 action
='store_false', dest
='playlist_reverse',
647 help='Download playlist videos in default order (default)')
648 downloader
.add_option(
651 help='Download playlist videos in random order')
652 downloader
.add_option(
653 '--xattr-set-filesize',
654 dest
='xattr_set_filesize', action
='store_true',
655 help='Set file xattribute ytdl.filesize with expected file size')
656 downloader
.add_option(
657 '--hls-prefer-native',
658 dest
='hls_prefer_native', action
='store_true', default
=None,
659 help=optparse
.SUPPRESS_HELP
)
660 downloader
.add_option(
661 '--hls-prefer-ffmpeg',
662 dest
='hls_prefer_native', action
='store_false', default
=None,
663 help=optparse
.SUPPRESS_HELP
)
664 downloader
.add_option(
666 dest
='hls_use_mpegts', action
='store_true', default
=None,
668 'Use the mpegts container for HLS videos; '
669 'allowing some players to play the video while downloading, '
670 'and reducing the chance of file corruption if download is interrupted. '
671 'This is enabled by default for live streams'))
672 downloader
.add_option(
673 '--no-hls-use-mpegts',
674 dest
='hls_use_mpegts', action
='store_false',
676 'Do not use the mpegts container for HLS videos. '
677 'This is default when not downloading live streams'))
678 downloader
.add_option(
679 '--downloader', '--external-downloader',
680 dest
='external_downloader', metavar
='[PROTO:]NAME', default
={}, type='str',
681 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
683 'allowed_keys': 'http|ftp|m3u8|dash|rtsp|rtmp|mms',
684 'default_key': 'default',
685 'process': lambda x
: x
.strip()
688 'Name or path of the external downloader to use (optionally) prefixed by '
689 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. '
690 'Currently supports native, %s (Recommended: aria2c). '
691 'You can use this option multiple times to set different downloaders for different protocols. '
692 'For example, --downloader aria2c --downloader "dash,m3u8:native" will use '
693 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads '
694 '(Alias: --external-downloader)' % ', '.join(list_external_downloaders())))
695 downloader
.add_option(
696 '--downloader-args', '--external-downloader-args',
697 metavar
='NAME:ARGS', dest
='external_downloader_args', default
={}, type='str',
698 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
700 'allowed_keys': '|'.join(list_external_downloaders()),
701 'default_key': 'default',
702 'process': compat_shlex_split
705 'Give these arguments to the external downloader. '
706 'Specify the downloader name and the arguments separated by a colon ":". '
707 'You can use this option multiple times (Alias: --external-downloader-args)'))
709 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
710 workarounds
.add_option(
712 dest
='encoding', metavar
='ENCODING',
713 help='Force the specified encoding (experimental)')
714 workarounds
.add_option(
715 '--no-check-certificate',
716 action
='store_true', dest
='no_check_certificate', default
=False,
717 help='Suppress HTTPS certificate validation')
718 workarounds
.add_option(
719 '--prefer-insecure', '--prefer-unsecure',
720 action
='store_true', dest
='prefer_insecure',
721 help='Use an unencrypted connection to retrieve information about the video (Currently supported only for YouTube)')
722 workarounds
.add_option(
724 metavar
='UA', dest
='user_agent',
725 help='Specify a custom user agent')
726 workarounds
.add_option(
728 metavar
='URL', dest
='referer', default
=None,
729 help='Specify a custom referer, use if the video access is restricted to one domain',
731 workarounds
.add_option(
733 metavar
='FIELD:VALUE', dest
='headers', default
={}, type='str',
734 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
735 callback_kwargs
={'multiple_keys': False}
,
736 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
738 workarounds
.add_option(
740 dest
='bidi_workaround', action
='store_true',
741 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
742 workarounds
.add_option(
743 '--sleep-requests', metavar
='SECONDS',
744 dest
='sleep_interval_requests', type=float,
745 help='Number of seconds to sleep between requests during data extraction')
746 workarounds
.add_option(
747 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
748 dest
='sleep_interval', type=float,
750 'Number of seconds to sleep before each download. '
751 'This is the minimum time to sleep when used along with --max-sleep-interval '
752 '(Alias: --min-sleep-interval)'))
753 workarounds
.add_option(
754 '--max-sleep-interval', metavar
='SECONDS',
755 dest
='max_sleep_interval', type=float,
756 help='Maximum number of seconds to sleep. Can only be used along with --min-sleep-interval')
757 workarounds
.add_option(
758 '--sleep-subtitles', metavar
='SECONDS',
759 dest
='sleep_interval_subtitles', default
=0, type=int,
760 help='Number of seconds to sleep before each subtitle download')
762 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity and Simulation Options')
763 verbosity
.add_option(
765 action
='store_true', dest
='quiet', default
=False,
766 help='Activate quiet mode')
767 verbosity
.add_option(
769 dest
='no_warnings', action
='store_true', default
=False,
770 help='Ignore warnings')
771 verbosity
.add_option(
773 action
='store_true', dest
='simulate', default
=False,
774 help='Do not download the video and do not write anything to disk')
775 verbosity
.add_option(
776 '--ignore-no-formats-error',
777 action
='store_true', dest
='ignore_no_formats_error', default
=False,
779 'Ignore "No video formats" error. Usefull for extracting metadata '
780 'even if the video is not actually available for download (experimental)'))
781 verbosity
.add_option(
782 '--no-ignore-no-formats-error',
783 action
='store_false', dest
='ignore_no_formats_error',
784 help='Throw error when no downloadable video formats are found (default)')
785 verbosity
.add_option(
786 '--skip-download', '--no-download',
787 action
='store_true', dest
='skip_download', default
=False,
788 help='Do not download the video but write all related files (Alias: --no-download)')
789 verbosity
.add_option(
791 action
='store_true', dest
='geturl', default
=False,
792 help='Simulate, quiet but print URL')
793 verbosity
.add_option(
795 action
='store_true', dest
='gettitle', default
=False,
796 help='Simulate, quiet but print title')
797 verbosity
.add_option(
799 action
='store_true', dest
='getid', default
=False,
800 help='Simulate, quiet but print id')
801 verbosity
.add_option(
803 action
='store_true', dest
='getthumbnail', default
=False,
804 help='Simulate, quiet but print thumbnail URL')
805 verbosity
.add_option(
807 action
='store_true', dest
='getdescription', default
=False,
808 help='Simulate, quiet but print video description')
809 verbosity
.add_option(
811 action
='store_true', dest
='getduration', default
=False,
812 help='Simulate, quiet but print video length')
813 verbosity
.add_option(
815 action
='store_true', dest
='getfilename', default
=False,
816 help='Simulate, quiet but print output filename')
817 verbosity
.add_option(
819 action
='store_true', dest
='getformat', default
=False,
820 help='Simulate, quiet but print output format')
821 verbosity
.add_option(
823 action
='store_true', dest
='dumpjson', default
=False,
824 help='Simulate, quiet but print JSON information. See "OUTPUT TEMPLATE" for a description of available keys')
825 verbosity
.add_option(
826 '-J', '--dump-single-json',
827 action
='store_true', dest
='dump_single_json', default
=False,
829 'Simulate, quiet but print JSON information for each command-line argument. '
830 'If the URL refers to a playlist, dump the whole playlist information in a single line'))
831 verbosity
.add_option(
833 action
='store_true', dest
='print_json', default
=False,
834 help='Be quiet and print the video information as JSON (video is still being downloaded)')
835 verbosity
.add_option(
836 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
837 action
='store_true', dest
='force_write_download_archive', default
=False,
839 'Force download archive entries to be written as far as no errors occur, '
840 'even if -s or another simulation option is used (Alias: --force-download-archive)'))
841 verbosity
.add_option(
843 action
='store_true', dest
='progress_with_newline', default
=False,
844 help='Output progress bar as new lines')
845 verbosity
.add_option(
847 action
='store_true', dest
='noprogress', default
=False,
848 help='Do not print progress bar')
849 verbosity
.add_option(
851 action
='store_true', dest
='consoletitle', default
=False,
852 help='Display progress in console titlebar')
853 verbosity
.add_option(
855 action
='store_true', dest
='verbose', default
=False,
856 help='Print various debugging information')
857 verbosity
.add_option(
858 '--dump-pages', '--dump-intermediate-pages',
859 action
='store_true', dest
='dump_intermediate_pages', default
=False,
860 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
861 verbosity
.add_option(
863 action
='store_true', dest
='write_pages', default
=False,
864 help='Write downloaded intermediary pages to files in the current directory to debug problems')
865 verbosity
.add_option(
866 '--youtube-print-sig-code',
867 action
='store_true', dest
='youtube_print_sig_code', default
=False,
868 help=optparse
.SUPPRESS_HELP
)
869 verbosity
.add_option(
870 '--print-traffic', '--dump-headers',
871 dest
='debug_printtraffic', action
='store_true', default
=False,
872 help='Display sent and read HTTP traffic')
873 verbosity
.add_option(
875 dest
='call_home', action
='store_true', default
=False,
876 # help='[Broken] Contact the yt-dlp server for debugging')
877 help=optparse
.SUPPRESS_HELP
)
878 verbosity
.add_option(
880 dest
='call_home', action
='store_false',
881 # help='Do not contact the yt-dlp server for debugging (default)')
882 help=optparse
.SUPPRESS_HELP
)
884 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
885 filesystem
.add_option(
886 '-a', '--batch-file',
887 dest
='batchfile', metavar
='FILE',
888 help="File containing URLs to download ('-' for stdin), one URL per line. "
889 "Lines starting with '#', ';' or ']' are considered as comments and ignored")
890 filesystem
.add_option(
891 '--id', default
=False,
892 action
='store_true', dest
='useid', help=optparse
.SUPPRESS_HELP
)
893 filesystem
.add_option(
895 metavar
='TYPES:PATH', dest
='paths', default
={}, type='str',
896 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
897 callback_kwargs
={'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys())}
,
899 'The paths where the files should be downloaded. '
900 'Specify the type of file and the path separated by a colon ":". '
901 'All the same types as --output are supported. '
902 'Additionally, you can also provide "home" and "temp" paths. '
903 'All intermediary files are first downloaded to the temp path and '
904 'then the final files are moved over to the home path after download is finished. '
905 'This option is ignored if --output is an absolute path'))
906 filesystem
.add_option(
908 metavar
='[TYPES:]TEMPLATE', dest
='outtmpl', default
={}, type='str',
909 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
911 'allowed_keys': '|'.join(OUTTMPL_TYPES
.keys()),
912 'default_key': 'default'
914 help='Output filename template; see "OUTPUT TEMPLATE" for details')
915 filesystem
.add_option(
916 '--output-na-placeholder',
917 dest
='outtmpl_na_placeholder', metavar
='TEXT', default
='NA',
918 help=('Placeholder value for unavailable meta fields in output filename template (default: "%default")'))
919 filesystem
.add_option(
921 dest
='autonumber_size', metavar
='NUMBER', type=int,
922 help=optparse
.SUPPRESS_HELP
)
923 filesystem
.add_option(
924 '--autonumber-start',
925 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
926 help=optparse
.SUPPRESS_HELP
)
927 filesystem
.add_option(
928 '--restrict-filenames',
929 action
='store_true', dest
='restrictfilenames', default
=False,
930 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
931 filesystem
.add_option(
932 '--no-restrict-filenames',
933 action
='store_false', dest
='restrictfilenames',
934 help='Allow Unicode characters, "&" and spaces in filenames (default)')
935 filesystem
.add_option(
936 '--windows-filenames',
937 action
='store_true', dest
='windowsfilenames', default
=False,
938 help='Force filenames to be windows compatible')
939 filesystem
.add_option(
940 '--no-windows-filenames',
941 action
='store_false', dest
='windowsfilenames',
942 help='Make filenames windows compatible only if using windows (default)')
943 filesystem
.add_option(
944 '--trim-filenames', '--trim-file-names', metavar
='LENGTH',
945 dest
='trim_file_name', default
=0, type=int,
946 help='Limit the filename length (excluding extension) to the specified number of characters')
947 filesystem
.add_option(
949 action
='store_true', dest
='autonumber', default
=False,
950 help=optparse
.SUPPRESS_HELP
)
951 filesystem
.add_option(
953 action
='store_true', dest
='usetitle', default
=False,
954 help=optparse
.SUPPRESS_HELP
)
955 filesystem
.add_option(
956 '--literal', default
=False,
957 action
='store_true', dest
='usetitle',
958 help=optparse
.SUPPRESS_HELP
)
959 filesystem
.add_option(
960 '-w', '--no-overwrites',
961 action
='store_false', dest
='overwrites', default
=None,
962 help='Do not overwrite any files')
963 filesystem
.add_option(
964 '--force-overwrites', '--yes-overwrites',
965 action
='store_true', dest
='overwrites',
966 help='Overwrite all video and metadata files. This option includes --no-continue')
967 filesystem
.add_option(
968 '--no-force-overwrites',
969 action
='store_const', dest
='overwrites', const
=None,
970 help='Do not overwrite the video, but overwrite related files (default)')
971 filesystem
.add_option(
973 action
='store_true', dest
='continue_dl', default
=True,
974 help='Resume partially downloaded files/fragments (default)')
975 filesystem
.add_option(
977 action
='store_false', dest
='continue_dl',
979 'Do not resume partially downloaded fragments. '
980 'If the file is not fragmented, restart download of the entire file'))
981 filesystem
.add_option(
983 action
='store_false', dest
='nopart', default
=False,
984 help='Use .part files instead of writing directly into output file (default)')
985 filesystem
.add_option(
987 action
='store_true', dest
='nopart',
988 help='Do not use .part files - write directly into output file')
989 filesystem
.add_option(
991 action
='store_true', dest
='updatetime', default
=True,
992 help='Use the Last-modified header to set the file modification time (default)')
993 filesystem
.add_option(
995 action
='store_false', dest
='updatetime',
996 help='Do not use the Last-modified header to set the file modification time')
997 filesystem
.add_option(
998 '--write-description',
999 action
='store_true', dest
='writedescription', default
=False,
1000 help='Write video description to a .description file')
1001 filesystem
.add_option(
1002 '--no-write-description',
1003 action
='store_false', dest
='writedescription',
1004 help='Do not write video description (default)')
1005 filesystem
.add_option(
1006 '--write-info-json',
1007 action
='store_true', dest
='writeinfojson', default
=False,
1008 help='Write video metadata to a .info.json file (this may contain personal information)')
1009 filesystem
.add_option(
1010 '--no-write-info-json',
1011 action
='store_false', dest
='writeinfojson',
1012 help='Do not write video metadata (default)')
1013 filesystem
.add_option(
1014 '--write-annotations',
1015 action
='store_true', dest
='writeannotations', default
=False,
1016 help='Write video annotations to a .annotations.xml file')
1017 filesystem
.add_option(
1018 '--no-write-annotations',
1019 action
='store_false', dest
='writeannotations',
1020 help='Do not write video annotations (default)')
1021 filesystem
.add_option(
1022 '--write-playlist-metafiles',
1023 action
='store_true', dest
='allow_playlist_files', default
=None,
1025 'Write playlist metadata in addition to the video metadata '
1026 'when using --write-info-json, --write-description etc. (default)'))
1027 filesystem
.add_option(
1028 '--no-write-playlist-metafiles',
1029 action
='store_false', dest
='allow_playlist_files',
1030 help='Do not write playlist metadata when using --write-info-json, --write-description etc.')
1031 filesystem
.add_option(
1033 action
='store_true', dest
='clean_infojson', default
=True,
1035 'Remove some private fields such as filenames from the infojson. '
1036 'Note that it could still contain some personal information (default)'))
1037 filesystem
.add_option(
1038 '--no-clean-infojson',
1039 action
='store_false', dest
='clean_infojson',
1040 help='Write all fields to the infojson')
1041 filesystem
.add_option(
1043 action
='store_true', dest
='getcomments', default
=False,
1045 'Retrieve video comments to be placed in the .info.json file. '
1046 'The comments are fetched even without this option if the extraction is known to be quick'))
1047 filesystem
.add_option(
1048 '--load-info-json', '--load-info',
1049 dest
='load_info_filename', metavar
='FILE',
1050 help='JSON file containing the video information (created with the "--write-info-json" option)')
1051 filesystem
.add_option(
1053 dest
='cookiefile', metavar
='FILE',
1054 help='File to read cookies from and dump cookie jar in')
1055 filesystem
.add_option(
1057 action
='store_const', const
=None, dest
='cookiefile', metavar
='FILE',
1058 help='Do not read/dump cookies (default)')
1059 filesystem
.add_option(
1060 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
1061 help='Location in the filesystem where youtube-dl can store some downloaded information permanently. By default $XDG_CACHE_HOME/youtube-dl or ~/.cache/youtube-dl . At the moment, only YouTube player files (for videos with obfuscated signatures) are cached, but that may change')
1062 filesystem
.add_option(
1063 '--no-cache-dir', action
='store_false', dest
='cachedir',
1064 help='Disable filesystem caching')
1065 filesystem
.add_option(
1067 action
='store_true', dest
='rm_cachedir',
1068 help='Delete all filesystem cache files')
1070 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail Options')
1071 thumbnail
.add_option(
1072 '--write-thumbnail',
1073 action
='store_true', dest
='writethumbnail', default
=False,
1074 help='Write thumbnail image to disk')
1075 thumbnail
.add_option(
1076 '--no-write-thumbnail',
1077 action
='store_false', dest
='writethumbnail',
1078 help='Do not write thumbnail image to disk (default)')
1079 thumbnail
.add_option(
1080 '--write-all-thumbnails',
1081 action
='store_true', dest
='write_all_thumbnails', default
=False,
1082 help='Write all thumbnail image formats to disk')
1083 thumbnail
.add_option(
1084 '--list-thumbnails',
1085 action
='store_true', dest
='list_thumbnails', default
=False,
1086 help='Simulate and list all available thumbnail formats')
1088 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
1091 action
='store_true', dest
='writelink', default
=False,
1092 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
1095 action
='store_true', dest
='writeurllink', default
=False,
1096 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
1098 '--write-webloc-link',
1099 action
='store_true', dest
='writewebloclink', default
=False,
1100 help='Write a .webloc macOS internet shortcut')
1102 '--write-desktop-link',
1103 action
='store_true', dest
='writedesktoplink', default
=False,
1104 help='Write a .desktop Linux internet shortcut')
1106 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
1107 postproc
.add_option(
1108 '-x', '--extract-audio',
1109 action
='store_true', dest
='extractaudio', default
=False,
1110 help='Convert video files to audio-only files (requires ffmpeg and ffprobe)')
1111 postproc
.add_option(
1112 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
1113 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
1114 postproc
.add_option(
1115 '--audio-quality', metavar
='QUALITY',
1116 dest
='audioquality', default
='5',
1117 help='Specify ffmpeg audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
1118 postproc
.add_option(
1120 metavar
='FORMAT', dest
='remuxvideo', default
=None,
1122 'Remux the video into another container if necessary (currently supported: %s). '
1123 'If target container does not support the video/audio codec, remuxing will fail. '
1124 'You can specify multiple rules; eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 '
1125 'and anything else to mkv.' % '|'.join(REMUX_EXTENSIONS
)))
1126 postproc
.add_option(
1128 metavar
='FORMAT', dest
='recodevideo', default
=None,
1130 'Re-encode the video into another format if re-encoding is necessary. '
1131 'The supported formats are the same as --remux-video'))
1132 postproc
.add_option(
1133 '--postprocessor-args', '--ppa',
1134 metavar
='NAME:ARGS', dest
='postprocessor_args', default
={}, type='str',
1135 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
1137 'allowed_keys': r
'\w+(?:\+\w+)?', 'default_key': 'default-compat',
1138 'process': compat_shlex_split
,
1139 'multiple_keys': False
1142 'Give these arguments to the postprocessors. '
1143 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
1144 'to give the argument to the specified postprocessor/executable. Supported PP are: '
1145 'Merger, ExtractAudio, SplitChapters, Metadata, EmbedSubtitle, EmbedThumbnail, '
1146 'SubtitlesConvertor, ThumbnailsConvertor, VideoRemuxer, VideoConvertor, '
1147 'SponSkrub, FixupStretched, FixupM4a and FixupM3u8. '
1148 'The supported executables are: AtomicParsley, FFmpeg, FFprobe, and SponSkrub. '
1149 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
1150 'only when being used by the specified postprocessor. Additionally, for ffmpeg/ffprobe, '
1151 '"_i"/"_o" can be appended to the prefix optionally followed by a number to pass the argument '
1152 'before the specified input/output file. Eg: --ppa "Merger+ffmpeg_i1:-v quiet". '
1153 'You can use this option multiple times to give different arguments to different '
1154 'postprocessors. (Alias: --ppa)'))
1155 postproc
.add_option(
1156 '-k', '--keep-video',
1157 action
='store_true', dest
='keepvideo', default
=False,
1158 help='Keep the intermediate video file on disk after post-processing')
1159 postproc
.add_option(
1161 action
='store_false', dest
='keepvideo',
1162 help='Delete the intermediate video file after post-processing (default)')
1163 postproc
.add_option(
1164 '--post-overwrites',
1165 action
='store_false', dest
='nopostoverwrites',
1166 help='Overwrite post-processed files (default)')
1167 postproc
.add_option(
1168 '--no-post-overwrites',
1169 action
='store_true', dest
='nopostoverwrites', default
=False,
1170 help='Do not overwrite post-processed files')
1171 postproc
.add_option(
1173 action
='store_true', dest
='embedsubtitles', default
=False,
1174 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1175 postproc
.add_option(
1177 action
='store_false', dest
='embedsubtitles',
1178 help='Do not embed subtitles (default)')
1179 postproc
.add_option(
1180 '--embed-thumbnail',
1181 action
='store_true', dest
='embedthumbnail', default
=False,
1182 help='Embed thumbnail in the audio as cover art')
1183 postproc
.add_option(
1184 '--no-embed-thumbnail',
1185 action
='store_false', dest
='embedthumbnail',
1186 help='Do not embed thumbnail (default)')
1187 postproc
.add_option(
1189 action
='store_true', dest
='addmetadata', default
=False,
1190 help='Write metadata to the video file')
1191 postproc
.add_option(
1192 '--no-add-metadata',
1193 action
='store_false', dest
='addmetadata',
1194 help='Do not write metadata (default)')
1195 postproc
.add_option(
1196 '--metadata-from-title',
1197 metavar
='FORMAT', dest
='metafromtitle',
1198 help=optparse
.SUPPRESS_HELP
)
1199 postproc
.add_option(
1201 metavar
='FROM:TO', dest
='metafromfield', action
='append',
1203 'Parse additional metadata like title/artist from other fields; '
1204 'see "MODIFYING METADATA" for details'))
1205 postproc
.add_option(
1207 action
='store_true', dest
='xattrs', default
=False,
1208 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1209 postproc
.add_option(
1211 metavar
='POLICY', dest
='fixup', default
=None,
1213 'Automatically correct known faults of the file. '
1214 'One of never (do nothing), warn (only emit a warning), '
1215 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
1216 postproc
.add_option(
1217 '--prefer-avconv', '--no-prefer-ffmpeg',
1218 action
='store_false', dest
='prefer_ffmpeg',
1219 help=optparse
.SUPPRESS_HELP
)
1220 postproc
.add_option(
1221 '--prefer-ffmpeg', '--no-prefer-avconv',
1222 action
='store_true', dest
='prefer_ffmpeg', default
=True,
1223 help=optparse
.SUPPRESS_HELP
)
1224 postproc
.add_option(
1225 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
1226 dest
='ffmpeg_location',
1227 help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
1228 postproc
.add_option(
1230 metavar
='CMD', dest
='exec_cmd',
1232 'Execute a command on the file after downloading and post-processing. '
1233 'Similar syntax to the output template can be used to pass any field as arguments to the command. '
1234 'An additional field "filepath" that contains the final path of the downloaded file is also available. '
1235 'If no fields are passed, "%(filepath)s" is appended to the end of the command'))
1236 postproc
.add_option(
1237 '--convert-subs', '--convert-sub', '--convert-subtitles',
1238 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
1239 help='Convert the subtitles to another format (currently supported: srt|ass|vtt|lrc) (Alias: --convert-subtitles)')
1240 postproc
.add_option(
1241 '--convert-thumbnails',
1242 metavar
='FORMAT', dest
='convertthumbnails', default
=None,
1243 help='Convert the thumbnails to another format (currently supported: jpg)')
1244 postproc
.add_option(
1245 '--split-chapters', '--split-tracks',
1246 dest
='split_chapters', action
='store_true', default
=False,
1248 'Split video into multiple files based on internal chapters. '
1249 'The "chapter:" prefix can be used with "--paths" and "--output" to '
1250 'set the output filename for the split files. See "OUTPUT TEMPLATE" for details'))
1251 postproc
.add_option(
1252 '--no-split-chapters', '--no-split-tracks',
1253 dest
='split_chapters', action
='store_false',
1254 help='Do not split video based on chapters (default)')
1256 sponskrub
= optparse
.OptionGroup(parser
, 'SponSkrub (SponsorBlock) Options', description
=(
1257 'SponSkrub (https://github.com/yt-dlp/SponSkrub) is a utility to mark/remove sponsor segments '
1258 'from downloaded YouTube videos using SponsorBlock API (https://sponsor.ajay.app)'))
1259 sponskrub
.add_option(
1261 action
='store_true', dest
='sponskrub', default
=None,
1263 'Use sponskrub to mark sponsored sections. '
1264 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
1265 sponskrub
.add_option(
1267 action
='store_false', dest
='sponskrub',
1268 help='Do not use sponskrub')
1269 sponskrub
.add_option(
1270 '--sponskrub-cut', default
=False,
1271 action
='store_true', dest
='sponskrub_cut',
1272 help='Cut out the sponsor sections instead of simply marking them')
1273 sponskrub
.add_option(
1274 '--no-sponskrub-cut',
1275 action
='store_false', dest
='sponskrub_cut',
1276 help='Simply mark the sponsor sections, not cut them out (default)')
1277 sponskrub
.add_option(
1278 '--sponskrub-force', default
=False,
1279 action
='store_true', dest
='sponskrub_force',
1280 help='Run sponskrub even if the video was already downloaded')
1281 sponskrub
.add_option(
1282 '--no-sponskrub-force',
1283 action
='store_true', dest
='sponskrub_force',
1284 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
1285 sponskrub
.add_option(
1286 '--sponskrub-location', metavar
='PATH',
1287 dest
='sponskrub_path', default
='',
1288 help='Location of the sponskrub binary; either the path to the binary or its containing directory')
1289 sponskrub
.add_option(
1290 '--sponskrub-args', dest
='sponskrub_args', metavar
='ARGS',
1291 help=optparse
.SUPPRESS_HELP
)
1293 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
1294 extractor
.add_option(
1295 '--extractor-retries',
1296 dest
='extractor_retries', metavar
='RETRIES', default
=3,
1297 help='Number of retries for known extractor errors (default is %default), or "infinite"')
1298 extractor
.add_option(
1299 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1300 action
='store_true', dest
='dynamic_mpd', default
=True,
1301 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
1302 extractor
.add_option(
1303 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1304 action
='store_false', dest
='dynamic_mpd',
1305 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
1306 extractor
.add_option(
1307 '--hls-split-discontinuity',
1308 dest
='hls_split_discontinuity', action
='store_true', default
=False,
1309 help='Split HLS playlists to different formats at discontinuities such as ad breaks'
1311 extractor
.add_option(
1312 '--no-hls-split-discontinuity',
1313 dest
='hls_split_discontinuity', action
='store_false',
1314 help='Do not split HLS playlists to different formats at discontinuities such as ad breaks (default)')
1315 extractor
.add_option(
1316 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
1317 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
1318 help='Download the DASH manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-dash-manifest)')
1319 extractor
.add_option(
1320 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
1321 action
='store_false', dest
='youtube_include_dash_manifest',
1322 help='Do not download the DASH manifests and related data on YouTube videos (Alias: --no-youtube-include-dash-manifest)')
1323 extractor
.add_option(
1324 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
1325 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
1326 help='Download the HLS manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-hls-manifest)')
1327 extractor
.add_option(
1328 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
1329 action
='store_false', dest
='youtube_include_hls_manifest',
1330 help='Do not download the HLS manifests and related data on YouTube videos (Alias: --no-youtube-include-hls-manifest)')
1332 parser
.add_option_group(general
)
1333 parser
.add_option_group(network
)
1334 parser
.add_option_group(geo
)
1335 parser
.add_option_group(selection
)
1336 parser
.add_option_group(downloader
)
1337 parser
.add_option_group(filesystem
)
1338 parser
.add_option_group(thumbnail
)
1339 parser
.add_option_group(link
)
1340 parser
.add_option_group(verbosity
)
1341 parser
.add_option_group(workarounds
)
1342 parser
.add_option_group(video_format
)
1343 parser
.add_option_group(subtitles
)
1344 parser
.add_option_group(authentication
)
1345 parser
.add_option_group(postproc
)
1346 parser
.add_option_group(sponskrub
)
1347 parser
.add_option_group(extractor
)
1349 if overrideArguments
is not None:
1350 opts
, args
= parser
.parse_args(overrideArguments
)
1352 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
1354 def compat_conf(conf
):
1355 if sys
.version_info
< (3,):
1356 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
1360 'command-line': compat_conf(sys
.argv
[1:]),
1361 'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []}
1362 paths
= {'command-line': False}
1363 opts
, args
= parser
.parse_args(configs
['command-line'])
1366 if '--config-location' in configs
['command-line']:
1367 location
= compat_expanduser(opts
.config_location
)
1368 if os
.path
.isdir(location
):
1369 location
= os
.path
.join(location
, 'yt-dlp.conf')
1370 if not os
.path
.exists(location
):
1371 parser
.error('config-location %s does not exist.' % location
)
1372 configs
['custom'] = _readOptions(location
, default
=None)
1373 if configs
['custom'] is None:
1374 configs
['custom'] = []
1376 paths
['custom'] = location
1377 if '--ignore-config' in configs
['command-line']:
1379 if '--ignore-config' in configs
['custom']:
1382 def read_options(path
, user
=False):
1383 # Multiple package names can be given here
1384 # Eg: ('yt-dlp', 'youtube-dlc', 'youtube-dl') will look for
1385 # the configuration file of any of these three packages
1386 for package
in ('yt-dlp',):
1388 config
, current_path
= _readUserConf(package
, default
=None)
1390 current_path
= os
.path
.join(path
, '%s.conf' % package
)
1391 config
= _readOptions(current_path
, default
=None)
1392 if config
is not None:
1393 return config
, current_path
1396 configs
['portable'], paths
['portable'] = read_options(get_executable_path())
1397 if '--ignore-config' in configs
['portable']:
1400 def get_home_path():
1401 opts
= parser
.parse_args(configs
['portable'] + configs
['custom'] + configs
['command-line'])[0]
1402 return expand_path(opts
.paths
.get('home', '')).strip()
1404 configs
['home'], paths
['home'] = read_options(get_home_path())
1405 if '--ignore-config' in configs
['home']:
1408 configs
['system'], paths
['system'] = read_options('/etc')
1409 if '--ignore-config' in configs
['system']:
1412 configs
['user'], paths
['user'] = read_options('', True)
1413 if '--ignore-config' in configs
['user']:
1414 configs
['system'], paths
['system'] = [], None
1417 argv
= configs
['system'] + configs
['user'] + configs
['home'] + configs
['portable'] + configs
['custom'] + configs
['command-line']
1418 opts
, args
= parser
.parse_args(argv
)
1420 for label
in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
1422 if paths
.get(key
) is None:
1425 write_string('[debug] %s config file: %s\n' % (label
, paths
[key
]))
1426 write_string('[debug] %s config: %s\n' % (label
, repr(_hide_login_info(configs
[key
]))))
1428 return parser
, opts
, args