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
=True,
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')
233 network
= optparse
.OptionGroup(parser
, 'Network Options')
235 '--proxy', dest
='proxy',
236 default
=None, metavar
='URL',
238 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
239 'SOCKS proxy, specify a proper scheme. For example '
240 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
241 'for direct connection'))
244 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
245 help='Time to wait before giving up, in seconds')
248 metavar
='IP', dest
='source_address', default
=None,
249 help='Client-side IP address to bind to',
252 '-4', '--force-ipv4',
253 action
='store_const', const
='0.0.0.0', dest
='source_address',
254 help='Make all connections via IPv4',
257 '-6', '--force-ipv6',
258 action
='store_const', const
='::', dest
='source_address',
259 help='Make all connections via IPv6',
262 geo
= optparse
.OptionGroup(parser
, 'Geo-restriction')
264 '--geo-verification-proxy',
265 dest
='geo_verification_proxy', default
=None, metavar
='URL',
267 'Use this proxy to verify the IP address for some geo-restricted sites. '
268 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
270 '--cn-verification-proxy',
271 dest
='cn_verification_proxy', default
=None, metavar
='URL',
272 help=optparse
.SUPPRESS_HELP
)
275 action
='store_true', dest
='geo_bypass', default
=True,
276 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
279 action
='store_false', dest
='geo_bypass', default
=True,
280 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
282 '--geo-bypass-country', metavar
='CODE',
283 dest
='geo_bypass_country', default
=None,
284 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
286 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
287 dest
='geo_bypass_ip_block', default
=None,
288 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
290 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
291 selection
.add_option(
293 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
294 help='Playlist video to start at (default is %default)')
295 selection
.add_option(
297 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
298 help='Playlist video to end at (default is last)')
299 selection
.add_option(
301 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
302 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')
303 selection
.add_option(
305 dest
='matchtitle', metavar
='REGEX',
306 help='Download only matching titles (regex or caseless sub-string)')
307 selection
.add_option(
309 dest
='rejecttitle', metavar
='REGEX',
310 help='Skip download for matching titles (regex or caseless sub-string)')
311 selection
.add_option(
313 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
314 help='Abort after downloading NUMBER files')
315 selection
.add_option(
317 metavar
='SIZE', dest
='min_filesize', default
=None,
318 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
319 selection
.add_option(
321 metavar
='SIZE', dest
='max_filesize', default
=None,
322 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
323 selection
.add_option(
325 metavar
='DATE', dest
='date', default
=None,
327 'Download only videos uploaded in this date. '
328 'The date can be "YYYYMMDD" or in the format '
329 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
330 selection
.add_option(
332 metavar
='DATE', dest
='datebefore', default
=None,
334 'Download only videos uploaded on or before this date. '
335 'The date formats accepted is the same as --date'))
336 selection
.add_option(
338 metavar
='DATE', dest
='dateafter', default
=None,
340 'Download only videos uploaded on or after this date. '
341 'The date formats accepted is the same as --date'))
342 selection
.add_option(
344 metavar
='COUNT', dest
='min_views', default
=None, type=int,
345 help='Do not download any videos with less than COUNT views')
346 selection
.add_option(
348 metavar
='COUNT', dest
='max_views', default
=None, type=int,
349 help='Do not download any videos with more than COUNT views')
350 selection
.add_option(
352 metavar
='FILTER', dest
='match_filter', default
=None,
354 'Generic video filter. '
355 'Specify any key (see "OUTPUT TEMPLATE" for a list of available keys) to '
356 'match if the key is present, '
357 '!key to check if the key is not present, '
358 'key>NUMBER (like "view_count > 12", also works with '
359 '>=, <, <=, !=, =) to compare against a number, '
360 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
361 'to match against a string literal '
362 'and & to require multiple matches. '
363 'Values which are not known are excluded unless you '
364 'put a question mark (?) after the operator. '
365 'For example, to only match videos that have been liked more than '
366 '100 times and disliked less than 50 times (or the dislike '
367 'functionality is not available at the given service), but who '
368 'also have a description, use --match-filter '
369 '"like_count > 100 & dislike_count <? 50 & description"'))
370 selection
.add_option(
372 metavar
='FILTER', dest
='match_filter', action
='store_const', const
=None,
373 help='Do not use generic video filter (default)')
374 selection
.add_option(
376 action
='store_true', dest
='noplaylist', default
=False,
377 help='Download only the video, if the URL refers to a video and a playlist')
378 selection
.add_option(
380 action
='store_false', dest
='noplaylist',
381 help='Download the playlist, if the URL refers to a video and a playlist')
382 selection
.add_option(
384 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
385 help='Download only videos suitable for the given age')
386 selection
.add_option(
387 '--download-archive', metavar
='FILE',
388 dest
='download_archive',
389 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
390 selection
.add_option(
391 '--break-on-existing',
392 action
='store_true', dest
='break_on_existing', default
=False,
393 help='Stop the download process when encountering a file that is in the archive')
394 selection
.add_option(
396 action
='store_true', dest
='break_on_reject', default
=False,
397 help='Stop the download process when encountering a file that has been filtered out')
398 selection
.add_option(
399 '--no-download-archive',
400 dest
='download_archive', action
="store_const", const
=None,
401 help='Do not use archive file (default)')
402 selection
.add_option(
404 dest
='include_ads', action
='store_true',
405 help=optparse
.SUPPRESS_HELP
)
406 selection
.add_option(
408 dest
='include_ads', action
='store_false',
409 help=optparse
.SUPPRESS_HELP
)
411 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
412 authentication
.add_option(
414 dest
='username', metavar
='USERNAME',
415 help='Login with this account ID')
416 authentication
.add_option(
418 dest
='password', metavar
='PASSWORD',
419 help='Account password. If this option is left out, yt-dlp will ask interactively')
420 authentication
.add_option(
422 dest
='twofactor', metavar
='TWOFACTOR',
423 help='Two-factor authentication code')
424 authentication
.add_option(
426 action
='store_true', dest
='usenetrc', default
=False,
427 help='Use .netrc authentication data')
428 authentication
.add_option(
430 dest
='videopassword', metavar
='PASSWORD',
431 help='Video password (vimeo, youku)')
432 authentication
.add_option(
434 dest
='ap_mso', metavar
='MSO',
435 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
436 authentication
.add_option(
438 dest
='ap_username', metavar
='USERNAME',
439 help='Multiple-system operator account login')
440 authentication
.add_option(
442 dest
='ap_password', metavar
='PASSWORD',
443 help='Multiple-system operator account password. If this option is left out, yt-dlp will ask interactively')
444 authentication
.add_option(
446 action
='store_true', dest
='ap_list_mso', default
=False,
447 help='List all supported multiple-system operators')
449 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
450 video_format
.add_option(
452 action
='store', dest
='format', metavar
='FORMAT', default
=None,
453 help='Video format code, see "FORMAT SELECTION" for more details')
454 video_format
.add_option(
455 '-S', '--format-sort', metavar
='SORTORDER',
456 dest
='format_sort', default
=[],
457 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
458 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
459 video_format
.add_option(
460 '--format-sort-force', '--S-force',
461 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
463 'Force user specified sort order to have precedence over all fields, '
464 'see "Sorting Formats" for more details'))
465 video_format
.add_option(
466 '--no-format-sort-force',
467 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
469 'Some fields have precedence over the user specified sort order (default), '
470 'see "Sorting Formats" for more details'))
471 video_format
.add_option(
472 '--video-multistreams',
473 action
='store_true', dest
='allow_multiple_video_streams', default
=False,
474 help='Allow multiple video streams to be merged into a single file')
475 video_format
.add_option(
476 '--no-video-multistreams',
477 action
='store_false', dest
='allow_multiple_video_streams',
478 help='Only one video stream is downloaded for each output file (default)')
479 video_format
.add_option(
480 '--audio-multistreams',
481 action
='store_true', dest
='allow_multiple_audio_streams', default
=False,
482 help='Allow multiple audio streams to be merged into a single file')
483 video_format
.add_option(
484 '--no-audio-multistreams',
485 action
='store_false', dest
='allow_multiple_audio_streams',
486 help='Only one audio stream is downloaded for each output file (default)')
487 video_format
.add_option(
489 action
='store_const', dest
='format', const
='all',
490 help=optparse
.SUPPRESS_HELP
)
491 video_format
.add_option(
492 '--prefer-free-formats',
493 action
='store_true', dest
='prefer_free_formats', default
=False,
495 'Prefer video formats with free containers over non-free ones of same quality. '
496 'Use with "-S ext" to strictly prefer free containers irrespective of quality'))
497 video_format
.add_option(
498 '--no-prefer-free-formats',
499 action
='store_true', dest
='prefer_free_formats', default
=False,
500 help="Don't give any special preference to free containers (default)")
501 video_format
.add_option(
502 '-F', '--list-formats',
503 action
='store_true', dest
='listformats',
504 help='List all available formats of requested videos')
505 video_format
.add_option(
506 '--list-formats-as-table',
507 action
='store_true', dest
='listformats_table', default
=True,
508 help='Present the output of -F in tabular form (default)')
509 video_format
.add_option(
510 '--list-formats-old', '--no-list-formats-as-table',
511 action
='store_false', dest
='listformats_table',
512 help='Present the output of -F in the old form (Alias: --no-list-formats-as-table)')
513 video_format
.add_option(
514 '--merge-output-format',
515 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
517 'If a merge is required (e.g. bestvideo+bestaudio), '
518 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
519 'Ignored if no merge is required'))
520 video_format
.add_option(
521 '--allow-unplayable-formats',
522 action
='store_true', dest
='allow_unplayable_formats', default
=False,
524 'Allow unplayable formats to be listed and downloaded. '
525 'All video postprocessing will also be turned off'))
526 video_format
.add_option(
527 '--no-allow-unplayable-formats',
528 action
='store_false', dest
='allow_unplayable_formats',
529 help='Do not allow unplayable formats to be listed or downloaded (default)')
531 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
532 subtitles
.add_option(
533 '--write-subs', '--write-srt',
534 action
='store_true', dest
='writesubtitles', default
=False,
535 help='Write subtitle file')
536 subtitles
.add_option(
537 '--no-write-subs', '--no-write-srt',
538 action
='store_false', dest
='writesubtitles',
539 help='Do not write subtitle file (default)')
540 subtitles
.add_option(
541 '--write-auto-subs', '--write-automatic-subs',
542 action
='store_true', dest
='writeautomaticsub', default
=False,
543 help='Write automatically generated subtitle file (Alias: --write-automatic-subs)')
544 subtitles
.add_option(
545 '--no-write-auto-subs', '--no-write-automatic-subs',
546 action
='store_false', dest
='writeautomaticsub', default
=False,
547 help='Do not write auto-generated subtitles (default) (Alias: --no-write-automatic-subs)')
548 subtitles
.add_option(
550 action
='store_true', dest
='allsubtitles', default
=False,
551 help='Download all the available subtitles of the video')
552 subtitles
.add_option(
554 action
='store_true', dest
='listsubtitles', default
=False,
555 help='List all available subtitles for the video')
556 subtitles
.add_option(
558 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
559 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
560 subtitles
.add_option(
561 '--sub-langs', '--srt-langs',
562 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
563 default
=[], callback
=_comma_separated_values_options_callback
,
564 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
566 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
567 downloader
.add_option(
568 '-N', '--concurrent-fragments',
569 dest
='concurrent_fragment_downloads', metavar
='N', default
=1, type=int,
570 help='Number of fragments of a dash/hlsnative video that should be download concurrently (default is %default)')
571 downloader
.add_option(
572 '-r', '--limit-rate', '--rate-limit',
573 dest
='ratelimit', metavar
='RATE',
574 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
575 downloader
.add_option(
577 dest
='retries', metavar
='RETRIES', default
=10,
578 help='Number of retries (default is %default), or "infinite"')
579 downloader
.add_option(
580 '--fragment-retries',
581 dest
='fragment_retries', metavar
='RETRIES', default
=10,
582 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
583 downloader
.add_option(
584 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
585 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
586 help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)')
587 downloader
.add_option(
588 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
589 action
='store_false', dest
='skip_unavailable_fragments',
590 help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
591 downloader
.add_option(
593 action
='store_true', dest
='keep_fragments', default
=False,
594 help='Keep downloaded fragments on disk after downloading is finished')
595 downloader
.add_option(
596 '--no-keep-fragments',
597 action
='store_false', dest
='keep_fragments',
598 help='Delete downloaded fragments after downloading is finished (default)')
599 downloader
.add_option(
601 dest
='buffersize', metavar
='SIZE', default
='1024',
602 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
603 downloader
.add_option(
605 action
='store_false', dest
='noresizebuffer',
606 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
607 downloader
.add_option(
608 '--no-resize-buffer',
609 action
='store_true', dest
='noresizebuffer', default
=False,
610 help='Do not automatically adjust the buffer size')
611 downloader
.add_option(
613 dest
='http_chunk_size', metavar
='SIZE', default
=None,
615 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
616 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
617 downloader
.add_option(
619 action
='store_true', dest
='test', default
=False,
620 help=optparse
.SUPPRESS_HELP
)
621 downloader
.add_option(
622 '--playlist-reverse',
624 help='Download playlist videos in reverse order')
625 downloader
.add_option(
626 '--no-playlist-reverse',
627 action
='store_false', dest
='playlist_reverse',
628 help='Download playlist videos in default order (default)')
629 downloader
.add_option(
632 help='Download playlist videos in random order')
633 downloader
.add_option(
634 '--xattr-set-filesize',
635 dest
='xattr_set_filesize', action
='store_true',
636 help='Set file xattribute ytdl.filesize with expected file size')
637 downloader
.add_option(
638 '--hls-prefer-native',
639 dest
='hls_prefer_native', action
='store_true', default
=None,
640 help=optparse
.SUPPRESS_HELP
)
641 downloader
.add_option(
642 '--hls-prefer-ffmpeg',
643 dest
='hls_prefer_native', action
='store_false', default
=None,
644 help=optparse
.SUPPRESS_HELP
)
645 downloader
.add_option(
647 dest
='hls_use_mpegts', action
='store_true', default
=None,
649 'Use the mpegts container for HLS videos; '
650 'allowing some players to play the video while downloading, '
651 'and reducing the chance of file corruption if download is interrupted. '
652 'This is enabled by default for live streams'))
653 downloader
.add_option(
654 '--no-hls-use-mpegts',
655 dest
='hls_use_mpegts', action
='store_false',
657 'Do not use the mpegts container for HLS videos. '
658 'This is default when not downloading live streams'))
659 downloader
.add_option(
660 '--downloader', '--external-downloader',
661 dest
='external_downloader', metavar
='[PROTO:]NAME', default
={}, type='str',
662 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
664 'allowed_keys': 'http|ftp|m3u8|dash|rtsp|rtmp|mms',
665 'default_key': 'default', 'process': lambda x
: x
.strip()},
667 'Name or path of the external downloader to use (optionally) prefixed by '
668 'the protocols (http, ftp, m3u8, dash, rstp, rtmp, mms) to use it for. '
669 'Currently supports native, %s (Recommended: aria2c). '
670 'You can use this option multiple times to set different downloaders for different protocols. '
671 'For example, --downloader aria2c --downloader "dash,m3u8:native" will use '
672 'aria2c for http/ftp downloads, and the native downloader for dash/m3u8 downloads '
673 '(Alias: --external-downloader)' % ', '.join(list_external_downloaders())))
674 downloader
.add_option(
675 '--downloader-args', '--external-downloader-args',
676 metavar
='NAME:ARGS', dest
='external_downloader_args', default
={}, type='str',
677 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
679 'allowed_keys': '|'.join(list_external_downloaders()),
680 'default_key': 'default', 'process': compat_shlex_split
},
682 'Give these arguments to the external downloader. '
683 'Specify the downloader name and the arguments separated by a colon ":". '
684 'You can use this option multiple times (Alias: --external-downloader-args)'))
686 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
687 workarounds
.add_option(
689 dest
='encoding', metavar
='ENCODING',
690 help='Force the specified encoding (experimental)')
691 workarounds
.add_option(
692 '--no-check-certificate',
693 action
='store_true', dest
='no_check_certificate', default
=False,
694 help='Suppress HTTPS certificate validation')
695 workarounds
.add_option(
696 '--prefer-insecure', '--prefer-unsecure',
697 action
='store_true', dest
='prefer_insecure',
698 help='Use an unencrypted connection to retrieve information about the video (Currently supported only for YouTube)')
699 workarounds
.add_option(
701 metavar
='UA', dest
='user_agent',
702 help='Specify a custom user agent')
703 workarounds
.add_option(
705 metavar
='URL', dest
='referer', default
=None,
706 help='Specify a custom referer, use if the video access is restricted to one domain',
708 workarounds
.add_option(
710 metavar
='FIELD:VALUE', dest
='headers', default
={}, type='str',
711 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
712 callback_kwargs
={'multiple_keys': False}
,
713 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
715 workarounds
.add_option(
717 dest
='bidi_workaround', action
='store_true',
718 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
719 workarounds
.add_option(
720 '--sleep-requests', metavar
='SECONDS',
721 dest
='sleep_interval_requests', type=float,
722 help='Number of seconds to sleep between requests during data extraction')
723 workarounds
.add_option(
724 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
725 dest
='sleep_interval', type=float,
727 'Number of seconds to sleep before each download. '
728 'This is the minimum time to sleep when used along with --max-sleep-interval '
729 '(Alias: --min-sleep-interval)'))
730 workarounds
.add_option(
731 '--max-sleep-interval', metavar
='SECONDS',
732 dest
='max_sleep_interval', type=float,
733 help='Maximum number of seconds to sleep. Can only be used along with --min-sleep-interval')
734 workarounds
.add_option(
735 '--sleep-subtitles', metavar
='SECONDS',
736 dest
='sleep_interval_subtitles', default
=0, type=int,
737 help='Number of seconds to sleep before each subtitle download')
739 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity and Simulation Options')
740 verbosity
.add_option(
742 action
='store_true', dest
='quiet', default
=False,
743 help='Activate quiet mode')
744 verbosity
.add_option(
746 dest
='no_warnings', action
='store_true', default
=False,
747 help='Ignore warnings')
748 verbosity
.add_option(
750 action
='store_true', dest
='simulate', default
=False,
751 help='Do not download the video and do not write anything to disk')
752 verbosity
.add_option(
753 '--skip-download', '--no-download',
754 action
='store_true', dest
='skip_download', default
=False,
755 help='Do not download the video but write all related files (Alias: --no-download)')
756 verbosity
.add_option(
758 action
='store_true', dest
='geturl', default
=False,
759 help='Simulate, quiet but print URL')
760 verbosity
.add_option(
762 action
='store_true', dest
='gettitle', default
=False,
763 help='Simulate, quiet but print title')
764 verbosity
.add_option(
766 action
='store_true', dest
='getid', default
=False,
767 help='Simulate, quiet but print id')
768 verbosity
.add_option(
770 action
='store_true', dest
='getthumbnail', default
=False,
771 help='Simulate, quiet but print thumbnail URL')
772 verbosity
.add_option(
774 action
='store_true', dest
='getdescription', default
=False,
775 help='Simulate, quiet but print video description')
776 verbosity
.add_option(
778 action
='store_true', dest
='getduration', default
=False,
779 help='Simulate, quiet but print video length')
780 verbosity
.add_option(
782 action
='store_true', dest
='getfilename', default
=False,
783 help='Simulate, quiet but print output filename')
784 verbosity
.add_option(
786 action
='store_true', dest
='getformat', default
=False,
787 help='Simulate, quiet but print output format')
788 verbosity
.add_option(
790 action
='store_true', dest
='dumpjson', default
=False,
791 help='Simulate, quiet but print JSON information. See "OUTPUT TEMPLATE" for a description of available keys')
792 verbosity
.add_option(
793 '-J', '--dump-single-json',
794 action
='store_true', dest
='dump_single_json', default
=False,
796 'Simulate, quiet but print JSON information for each command-line argument. '
797 'If the URL refers to a playlist, dump the whole playlist information in a single line'))
798 verbosity
.add_option(
800 action
='store_true', dest
='print_json', default
=False,
801 help='Be quiet and print the video information as JSON (video is still being downloaded)')
802 verbosity
.add_option(
803 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
804 action
='store_true', dest
='force_write_download_archive', default
=False,
806 'Force download archive entries to be written as far as no errors occur,'
807 'even if -s or another simulation switch is used (Alias: --force-download-archive)'))
808 verbosity
.add_option(
810 action
='store_true', dest
='progress_with_newline', default
=False,
811 help='Output progress bar as new lines')
812 verbosity
.add_option(
814 action
='store_true', dest
='noprogress', default
=False,
815 help='Do not print progress bar')
816 verbosity
.add_option(
818 action
='store_true', dest
='consoletitle', default
=False,
819 help='Display progress in console titlebar')
820 verbosity
.add_option(
822 action
='store_true', dest
='verbose', default
=False,
823 help='Print various debugging information')
824 verbosity
.add_option(
825 '--dump-pages', '--dump-intermediate-pages',
826 action
='store_true', dest
='dump_intermediate_pages', default
=False,
827 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
828 verbosity
.add_option(
830 action
='store_true', dest
='write_pages', default
=False,
831 help='Write downloaded intermediary pages to files in the current directory to debug problems')
832 verbosity
.add_option(
833 '--youtube-print-sig-code',
834 action
='store_true', dest
='youtube_print_sig_code', default
=False,
835 help=optparse
.SUPPRESS_HELP
)
836 verbosity
.add_option(
837 '--print-traffic', '--dump-headers',
838 dest
='debug_printtraffic', action
='store_true', default
=False,
839 help='Display sent and read HTTP traffic')
840 verbosity
.add_option(
842 dest
='call_home', action
='store_true', default
=False,
843 # help='[Broken] Contact the yt-dlp server for debugging')
844 help=optparse
.SUPPRESS_HELP
)
845 verbosity
.add_option(
847 dest
='call_home', action
='store_false',
848 # help='Do not contact the yt-dlp server for debugging (default)')
849 help=optparse
.SUPPRESS_HELP
)
851 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
852 filesystem
.add_option(
853 '-a', '--batch-file',
854 dest
='batchfile', metavar
='FILE',
855 help="File containing URLs to download ('-' for stdin), one URL per line. "
856 "Lines starting with '#', ';' or ']' are considered as comments and ignored")
857 filesystem
.add_option(
858 '--id', default
=False,
859 action
='store_true', dest
='useid', help=optparse
.SUPPRESS_HELP
)
860 filesystem
.add_option(
862 metavar
='TYPES:PATH', dest
='paths', default
={}, type='str',
863 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
865 'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES
.keys()),
866 'process': lambda x
: x
.strip()},
868 'The paths where the files should be downloaded. '
869 'Specify the type of file and the path separated by a colon ":". '
870 'All the same types as --output are supported. '
871 'Additionally, you can also provide "home" and "temp" paths. '
872 'All intermediary files are first downloaded to the temp path and '
873 'then the final files are moved over to the home path after download is finished. '
874 'This option is ignored if --output is an absolute path'))
875 filesystem
.add_option(
877 metavar
='[TYPES:]TEMPLATE', dest
='outtmpl', default
={}, type='str',
878 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
880 'allowed_keys': '|'.join(OUTTMPL_TYPES
.keys()),
881 'default_key': 'default', 'process': lambda x
: x
.strip()},
882 help='Output filename template; see "OUTPUT TEMPLATE" for details')
883 filesystem
.add_option(
884 '--output-na-placeholder',
885 dest
='outtmpl_na_placeholder', metavar
='TEXT', default
='NA',
886 help=('Placeholder value for unavailable meta fields in output filename template (default: "%default")'))
887 filesystem
.add_option(
889 dest
='autonumber_size', metavar
='NUMBER', type=int,
890 help=optparse
.SUPPRESS_HELP
)
891 filesystem
.add_option(
892 '--autonumber-start',
893 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
894 help='Specify the start value for %(autonumber)s (default is %default)')
895 filesystem
.add_option(
896 '--restrict-filenames',
897 action
='store_true', dest
='restrictfilenames', default
=False,
898 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
899 filesystem
.add_option(
900 '--no-restrict-filenames',
901 action
='store_false', dest
='restrictfilenames',
902 help='Allow Unicode characters, "&" and spaces in filenames (default)')
903 filesystem
.add_option(
904 '--windows-filenames',
905 action
='store_true', dest
='windowsfilenames', default
=False,
906 help='Force filenames to be windows compatible')
907 filesystem
.add_option(
908 '--no-windows-filenames',
909 action
='store_false', dest
='windowsfilenames',
910 help='Make filenames windows compatible only if using windows (default)')
911 filesystem
.add_option(
912 '--trim-filenames', '--trim-file-names', metavar
='LENGTH',
913 dest
='trim_file_name', default
=0, type=int,
914 help='Limit the filename length (excluding extension) to the specified number of characters')
915 filesystem
.add_option(
916 '-A', '--auto-number',
917 action
='store_true', dest
='autonumber', default
=False,
918 help=optparse
.SUPPRESS_HELP
)
919 filesystem
.add_option(
921 action
='store_true', dest
='usetitle', default
=False,
922 help=optparse
.SUPPRESS_HELP
)
923 filesystem
.add_option(
924 '-l', '--literal', default
=False,
925 action
='store_true', dest
='usetitle',
926 help=optparse
.SUPPRESS_HELP
)
927 filesystem
.add_option(
928 '-w', '--no-overwrites',
929 action
='store_false', dest
='overwrites', default
=None,
930 help='Do not overwrite any files')
931 filesystem
.add_option(
932 '--force-overwrites', '--yes-overwrites',
933 action
='store_true', dest
='overwrites',
934 help='Overwrite all video and metadata files. This option includes --no-continue')
935 filesystem
.add_option(
936 '--no-force-overwrites',
937 action
='store_const', dest
='overwrites', const
=None,
938 help='Do not overwrite the video, but overwrite related files (default)')
939 filesystem
.add_option(
941 action
='store_true', dest
='continue_dl', default
=True,
942 help='Resume partially downloaded files/fragments (default)')
943 filesystem
.add_option(
945 action
='store_false', dest
='continue_dl',
947 'Do not resume partially downloaded fragments. '
948 'If the file is unfragmented, restart download of the entire file'))
949 filesystem
.add_option(
951 action
='store_false', dest
='nopart', default
=False,
952 help='Use .part files instead of writing directly into output file (default)')
953 filesystem
.add_option(
955 action
='store_true', dest
='nopart',
956 help='Do not use .part files - write directly into output file')
957 filesystem
.add_option(
959 action
='store_true', dest
='updatetime', default
=True,
960 help='Use the Last-modified header to set the file modification time (default)')
961 filesystem
.add_option(
963 action
='store_false', dest
='updatetime',
964 help='Do not use the Last-modified header to set the file modification time')
965 filesystem
.add_option(
966 '--write-description',
967 action
='store_true', dest
='writedescription', default
=False,
968 help='Write video description to a .description file')
969 filesystem
.add_option(
970 '--no-write-description',
971 action
='store_false', dest
='writedescription',
972 help='Do not write video description (default)')
973 filesystem
.add_option(
975 action
='store_true', dest
='writeinfojson', default
=False,
976 help='Write video metadata to a .info.json file (this may contain personal information)')
977 filesystem
.add_option(
978 '--no-write-info-json',
979 action
='store_false', dest
='writeinfojson',
980 help='Do not write video metadata (default)')
981 filesystem
.add_option(
982 '--write-annotations',
983 action
='store_true', dest
='writeannotations', default
=False,
984 help='Write video annotations to a .annotations.xml file')
985 filesystem
.add_option(
986 '--no-write-annotations',
987 action
='store_false', dest
='writeannotations',
988 help='Do not write video annotations (default)')
989 filesystem
.add_option(
990 '--write-playlist-metafiles',
991 action
='store_true', dest
='allow_playlist_files', default
=True,
993 'Write playlist metadata in addition to the video metadata '
994 'when using --write-info-json, --write-description etc. (default)'))
995 filesystem
.add_option(
996 '--no-write-playlist-metafiles',
997 action
='store_false', dest
='allow_playlist_files',
998 help='Do not write playlist metadata when using --write-info-json, --write-description etc.')
999 filesystem
.add_option(
1001 action
='store_true', dest
='clean_infojson', default
=True,
1003 'Remove some private fields such as filenames from the infojson. '
1004 'Note that it could still contain some personal information (default)'))
1005 filesystem
.add_option(
1006 '--no-clean-infojson',
1007 action
='store_false', dest
='clean_infojson',
1008 help='Write all fields to the infojson')
1009 filesystem
.add_option(
1011 action
='store_true', dest
='getcomments', default
=False,
1013 'Retrieve video comments to be placed in the .info.json file. '
1014 'The comments are fetched even without this option if the extraction is known to be quick'))
1015 filesystem
.add_option(
1016 '--load-info-json', '--load-info',
1017 dest
='load_info_filename', metavar
='FILE',
1018 help='JSON file containing the video information (created with the "--write-info-json" option)')
1019 filesystem
.add_option(
1021 dest
='cookiefile', metavar
='FILE',
1022 help='File to read cookies from and dump cookie jar in')
1023 filesystem
.add_option(
1025 action
='store_const', const
=None, dest
='cookiefile', metavar
='FILE',
1026 help='Do not read/dump cookies (default)')
1027 filesystem
.add_option(
1028 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
1029 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')
1030 filesystem
.add_option(
1031 '--no-cache-dir', action
='store_false', dest
='cachedir',
1032 help='Disable filesystem caching')
1033 filesystem
.add_option(
1035 action
='store_true', dest
='rm_cachedir',
1036 help='Delete all filesystem cache files')
1038 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail Options')
1039 thumbnail
.add_option(
1040 '--write-thumbnail',
1041 action
='store_true', dest
='writethumbnail', default
=False,
1042 help='Write thumbnail image to disk')
1043 thumbnail
.add_option(
1044 '--no-write-thumbnail',
1045 action
='store_false', dest
='writethumbnail',
1046 help='Do not write thumbnail image to disk (default)')
1047 thumbnail
.add_option(
1048 '--write-all-thumbnails',
1049 action
='store_true', dest
='write_all_thumbnails', default
=False,
1050 help='Write all thumbnail image formats to disk')
1051 thumbnail
.add_option(
1052 '--list-thumbnails',
1053 action
='store_true', dest
='list_thumbnails', default
=False,
1054 help='Simulate and list all available thumbnail formats')
1056 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
1059 action
='store_true', dest
='writelink', default
=False,
1060 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
1063 action
='store_true', dest
='writeurllink', default
=False,
1064 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
1066 '--write-webloc-link',
1067 action
='store_true', dest
='writewebloclink', default
=False,
1068 help='Write a .webloc macOS internet shortcut')
1070 '--write-desktop-link',
1071 action
='store_true', dest
='writedesktoplink', default
=False,
1072 help='Write a .desktop Linux internet shortcut')
1074 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
1075 postproc
.add_option(
1076 '-x', '--extract-audio',
1077 action
='store_true', dest
='extractaudio', default
=False,
1078 help='Convert video files to audio-only files (requires ffmpeg and ffprobe)')
1079 postproc
.add_option(
1080 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
1081 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
1082 postproc
.add_option(
1083 '--audio-quality', metavar
='QUALITY',
1084 dest
='audioquality', default
='5',
1085 help='Specify ffmpeg audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
1086 postproc
.add_option(
1088 metavar
='FORMAT', dest
='remuxvideo', default
=None,
1090 'Remux the video into another container if necessary (currently supported: %s). '
1091 'If target container does not support the video/audio codec, remuxing will fail. '
1092 'You can specify multiple rules; eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 '
1093 'and anything else to mkv.' % '|'.join(REMUX_EXTENSIONS
)))
1094 postproc
.add_option(
1096 metavar
='FORMAT', dest
='recodevideo', default
=None,
1098 'Re-encode the video into another format if re-encoding is necessary. '
1099 'The supported formats are the same as --remux-video'))
1100 postproc
.add_option(
1101 '--postprocessor-args', '--ppa',
1102 metavar
='NAME:ARGS', dest
='postprocessor_args', default
={}, type='str',
1103 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
1105 'allowed_keys': r
'\w+(?:\+\w+)?', 'default_key': 'default-compat',
1106 'process': compat_shlex_split
, 'multiple_keys': False},
1108 'Give these arguments to the postprocessors. '
1109 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
1110 'to give the argument to the specified postprocessor/executable. Supported PP are: '
1111 'Merger, ExtractAudio, SplitChapters, Metadata, EmbedSubtitle, EmbedThumbnail, '
1112 'SubtitlesConvertor, ThumbnailsConvertor, VideoRemuxer, VideoConvertor, '
1113 'SponSkrub, FixupStretched, FixupM4a and FixupM3u8. '
1114 'The supported executables are: AtomicParsley, FFmpeg, FFprobe, and SponSkrub. '
1115 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
1116 'only when being used by the specified postprocessor. Additionally, for ffmpeg/ffprobe, '
1117 '"_i"/"_o" can be appended to the prefix optionally followed by a number to pass the argument '
1118 'before the specified input/output file. Eg: --ppa "Merger+ffmpeg_i1:-v quiet". '
1119 'You can use this option multiple times to give different arguments to different '
1120 'postprocessors. (Alias: --ppa)'))
1121 postproc
.add_option(
1122 '-k', '--keep-video',
1123 action
='store_true', dest
='keepvideo', default
=False,
1124 help='Keep the intermediate video file on disk after post-processing')
1125 postproc
.add_option(
1127 action
='store_false', dest
='keepvideo',
1128 help='Delete the intermediate video file after post-processing (default)')
1129 postproc
.add_option(
1130 '--post-overwrites',
1131 action
='store_false', dest
='nopostoverwrites',
1132 help='Overwrite post-processed files (default)')
1133 postproc
.add_option(
1134 '--no-post-overwrites',
1135 action
='store_true', dest
='nopostoverwrites', default
=False,
1136 help='Do not overwrite post-processed files')
1137 postproc
.add_option(
1139 action
='store_true', dest
='embedsubtitles', default
=False,
1140 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1141 postproc
.add_option(
1143 action
='store_false', dest
='embedsubtitles',
1144 help='Do not embed subtitles (default)')
1145 postproc
.add_option(
1146 '--embed-thumbnail',
1147 action
='store_true', dest
='embedthumbnail', default
=False,
1148 help='Embed thumbnail in the audio as cover art')
1149 postproc
.add_option(
1150 '--no-embed-thumbnail',
1151 action
='store_false', dest
='embedthumbnail',
1152 help='Do not embed thumbnail (default)')
1153 postproc
.add_option(
1155 action
='store_true', dest
='addmetadata', default
=False,
1156 help='Write metadata to the video file')
1157 postproc
.add_option(
1158 '--no-add-metadata',
1159 action
='store_false', dest
='addmetadata',
1160 help='Do not write metadata (default)')
1161 postproc
.add_option(
1162 '--metadata-from-title',
1163 metavar
='FORMAT', dest
='metafromtitle',
1164 help=optparse
.SUPPRESS_HELP
)
1165 postproc
.add_option(
1167 metavar
='FROM:TO', dest
='metafromfield', action
='append',
1169 'Parse additional metadata like title/artist from other fields; '
1170 'see "MODIFYING METADATA" for details'))
1171 postproc
.add_option(
1173 action
='store_true', dest
='xattrs', default
=False,
1174 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1175 postproc
.add_option(
1177 metavar
='POLICY', dest
='fixup', default
=None,
1179 'Automatically correct known faults of the file. '
1180 'One of never (do nothing), warn (only emit a warning), '
1181 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
1182 postproc
.add_option(
1183 '--prefer-avconv', '--no-prefer-ffmpeg',
1184 action
='store_false', dest
='prefer_ffmpeg',
1185 help=optparse
.SUPPRESS_HELP
)
1186 postproc
.add_option(
1187 '--prefer-ffmpeg', '--no-prefer-avconv',
1188 action
='store_true', dest
='prefer_ffmpeg', default
=True,
1189 help=optparse
.SUPPRESS_HELP
)
1190 postproc
.add_option(
1191 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
1192 dest
='ffmpeg_location',
1193 help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
1194 postproc
.add_option(
1196 metavar
='CMD', dest
='exec_cmd',
1198 'Execute a command on the file after downloading and post-processing. '
1199 'Similar syntax to the output template can be used to pass any field as arguments to the command. '
1200 'An additional field "filepath" that contains the final path of the downloaded file is also available. '
1201 'If no fields are passed, "%(filepath)s" is appended to the end of the command'))
1202 postproc
.add_option(
1203 '--convert-subs', '--convert-sub', '--convert-subtitles',
1204 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
1205 help='Convert the subtitles to another format (currently supported: srt|ass|vtt|lrc) (Alias: --convert-subtitles)')
1206 postproc
.add_option(
1207 '--convert-thumbnails',
1208 metavar
='FORMAT', dest
='convertthumbnails', default
=None,
1209 help='Convert the thumbnails to another format (currently supported: jpg)')
1210 postproc
.add_option(
1211 '--split-chapters', '--split-tracks',
1212 dest
='split_chapters', action
='store_true', default
=False,
1214 'Split video into multiple files based on internal chapters. '
1215 'The "chapter:" prefix can be used with "--paths" and "--output" to '
1216 'set the output filename for the split files. See "OUTPUT TEMPLATE" for details'))
1217 postproc
.add_option(
1218 '--no-split-chapters', '--no-split-tracks',
1219 dest
='split_chapters', action
='store_false',
1220 help='Do not split video based on chapters (default)')
1222 sponskrub
= optparse
.OptionGroup(parser
, 'SponSkrub (SponsorBlock) Options', description
=(
1223 'SponSkrub (https://github.com/yt-dlp/SponSkrub) is a utility to mark/remove sponsor segments '
1224 'from downloaded YouTube videos using SponsorBlock API (https://sponsor.ajay.app)'))
1225 sponskrub
.add_option(
1227 action
='store_true', dest
='sponskrub', default
=None,
1229 'Use sponskrub to mark sponsored sections. '
1230 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
1231 sponskrub
.add_option(
1233 action
='store_false', dest
='sponskrub',
1234 help='Do not use sponskrub')
1235 sponskrub
.add_option(
1236 '--sponskrub-cut', default
=False,
1237 action
='store_true', dest
='sponskrub_cut',
1238 help='Cut out the sponsor sections instead of simply marking them')
1239 sponskrub
.add_option(
1240 '--no-sponskrub-cut',
1241 action
='store_false', dest
='sponskrub_cut',
1242 help='Simply mark the sponsor sections, not cut them out (default)')
1243 sponskrub
.add_option(
1244 '--sponskrub-force', default
=False,
1245 action
='store_true', dest
='sponskrub_force',
1246 help='Run sponskrub even if the video was already downloaded')
1247 sponskrub
.add_option(
1248 '--no-sponskrub-force',
1249 action
='store_true', dest
='sponskrub_force',
1250 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
1251 sponskrub
.add_option(
1252 '--sponskrub-location', metavar
='PATH',
1253 dest
='sponskrub_path', default
='',
1254 help='Location of the sponskrub binary; either the path to the binary or its containing directory')
1255 sponskrub
.add_option(
1256 '--sponskrub-args', dest
='sponskrub_args', metavar
='ARGS',
1257 help=optparse
.SUPPRESS_HELP
)
1259 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
1260 extractor
.add_option(
1261 '--extractor-retries',
1262 dest
='extractor_retries', metavar
='RETRIES', default
=3,
1263 help='Number of retries for known extractor errors (default is %default), or "infinite"')
1264 extractor
.add_option(
1265 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1266 action
='store_true', dest
='dynamic_mpd', default
=True,
1267 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
1268 extractor
.add_option(
1269 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1270 action
='store_false', dest
='dynamic_mpd',
1271 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
1272 extractor
.add_option(
1273 '--hls-split-discontinuity',
1274 dest
='hls_split_discontinuity', action
='store_true', default
=False,
1275 help='Split HLS playlists to different formats at discontinuities such as ad breaks'
1277 extractor
.add_option(
1278 '--no-hls-split-discontinuity',
1279 dest
='hls_split_discontinuity', action
='store_false',
1280 help='Do not split HLS playlists to different formats at discontinuities such as ad breaks (default)')
1281 extractor
.add_option(
1282 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
1283 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
1284 help='Download the DASH manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-dash-manifest)')
1285 extractor
.add_option(
1286 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
1287 action
='store_false', dest
='youtube_include_dash_manifest',
1288 help='Do not download the DASH manifests and related data on YouTube videos (Alias: --no-youtube-include-dash-manifest)')
1289 extractor
.add_option(
1290 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
1291 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
1292 help='Download the HLS manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-hls-manifest)')
1293 extractor
.add_option(
1294 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
1295 action
='store_false', dest
='youtube_include_hls_manifest',
1296 help='Do not download the HLS manifests and related data on YouTube videos (Alias: --no-youtube-include-hls-manifest)')
1298 parser
.add_option_group(general
)
1299 parser
.add_option_group(network
)
1300 parser
.add_option_group(geo
)
1301 parser
.add_option_group(selection
)
1302 parser
.add_option_group(downloader
)
1303 parser
.add_option_group(filesystem
)
1304 parser
.add_option_group(thumbnail
)
1305 parser
.add_option_group(link
)
1306 parser
.add_option_group(verbosity
)
1307 parser
.add_option_group(workarounds
)
1308 parser
.add_option_group(video_format
)
1309 parser
.add_option_group(subtitles
)
1310 parser
.add_option_group(authentication
)
1311 parser
.add_option_group(postproc
)
1312 parser
.add_option_group(sponskrub
)
1313 parser
.add_option_group(extractor
)
1315 if overrideArguments
is not None:
1316 opts
, args
= parser
.parse_args(overrideArguments
)
1318 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
1320 def compat_conf(conf
):
1321 if sys
.version_info
< (3,):
1322 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
1326 'command-line': compat_conf(sys
.argv
[1:]),
1327 'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []}
1328 paths
= {'command-line': False}
1329 opts
, args
= parser
.parse_args(configs
['command-line'])
1332 if '--config-location' in configs
['command-line']:
1333 location
= compat_expanduser(opts
.config_location
)
1334 if os
.path
.isdir(location
):
1335 location
= os
.path
.join(location
, 'yt-dlp.conf')
1336 if not os
.path
.exists(location
):
1337 parser
.error('config-location %s does not exist.' % location
)
1338 configs
['custom'] = _readOptions(location
, default
=None)
1339 if configs
['custom'] is None:
1340 configs
['custom'] = []
1342 paths
['custom'] = location
1343 if '--ignore-config' in configs
['command-line']:
1345 if '--ignore-config' in configs
['custom']:
1348 def read_options(path
, user
=False):
1349 # Multiple package names can be given here
1350 # Eg: ('yt-dlp', 'youtube-dlc', 'youtube-dl') will look for
1351 # the configuration file of any of these three packages
1352 for package
in ('yt-dlp',):
1354 config
, current_path
= _readUserConf(package
, default
=None)
1356 current_path
= os
.path
.join(path
, '%s.conf' % package
)
1357 config
= _readOptions(current_path
, default
=None)
1358 if config
is not None:
1359 return config
, current_path
1362 configs
['portable'], paths
['portable'] = read_options(get_executable_path())
1363 if '--ignore-config' in configs
['portable']:
1366 def get_home_path():
1367 opts
= parser
.parse_args(configs
['portable'] + configs
['custom'] + configs
['command-line'])[0]
1368 return expand_path(opts
.paths
.get('home', '')).strip()
1370 configs
['home'], paths
['home'] = read_options(get_home_path())
1371 if '--ignore-config' in configs
['home']:
1374 configs
['system'], paths
['system'] = read_options('/etc')
1375 if '--ignore-config' in configs
['system']:
1378 configs
['user'], paths
['user'] = read_options('', True)
1379 if '--ignore-config' in configs
['user']:
1380 configs
['system'], paths
['system'] = [], None
1383 argv
= configs
['system'] + configs
['user'] + configs
['home'] + configs
['portable'] + configs
['custom'] + configs
['command-line']
1384 opts
, args
= parser
.parse_args(argv
)
1386 for label
in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
1388 if paths
.get(key
) is None:
1391 write_string('[debug] %s config file: %s\n' % (label
, paths
[key
]))
1392 write_string('[debug] %s config: %s\n' % (label
, repr(_hide_login_info(configs
[key
]))))
1394 return parser
, opts
, args