]> jfr.im git - yt-dlp.git/blame - youtube_dlc/options.py
Release 2021.02.04
[yt-dlp.git] / youtube_dlc / options.py
CommitLineData
2daabe49
PH
1from __future__ import unicode_literals
2
34a741a8
PH
3import os.path
4import optparse
3aa9a735 5import re
34a741a8
PH
6import sys
7
222516d9 8from .downloader.external import list_external_downloaders
8c25f81b 9from .compat import (
4644ac55 10 compat_expanduser,
003c69a8 11 compat_get_terminal_size,
4644ac55 12 compat_getenv,
c7b0add8 13 compat_kwargs,
cab792ab 14 compat_shlex_split,
8c25f81b
PH
15)
16from .utils import (
0202b52a 17 expand_path,
f74980cb 18 get_executable_path,
de6000d9 19 OUTTMPL_TYPES,
ff556f5c 20 preferredencoding,
34a741a8
PH
21 write_string,
22)
23from .version import __version__
24
25
17912249 26_remux_formats = ('mp4', 'mkv', 'flv', 'webm', 'mov', 'avi', 'mp3', 'mka', 'm4a', 'ogg', 'opus')
27
28
905d18a7
YCH
29def _hide_login_info(opts):
30 PRIVATE_OPTS = set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
31 eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
32
33 def _scrub_eq(o):
34 m = eqre.match(o)
35 if m:
36 return m.group('key') + '=PRIVATE'
37 else:
38 return o
39
40 opts = list(map(_scrub_eq, opts))
41 for idx, opt in enumerate(opts):
42 if opt in PRIVATE_OPTS and idx + 1 < len(opts):
43 opts[idx + 1] = 'PRIVATE'
44 return opts
45
46
34a741a8
PH
47def parseOpts(overrideArguments=None):
48 def _readOptions(filename_bytes, default=[]):
49 try:
50 optionf = open(filename_bytes)
51 except IOError:
52 return default # silently skip if file is not present
53 try:
067aa17e 54 # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
1251565e
S
55 contents = optionf.read()
56 if sys.version_info < (3,):
57 contents = contents.decode(preferredencoding())
58 res = compat_shlex_split(contents, comments=True)
34a741a8
PH
59 finally:
60 optionf.close()
61 return res
62
e2e43aea 63 def _readUserConf(package_name, default=[]):
64 # .config
65 xdg_config_home = compat_getenv('XDG_CONFIG_HOME') or compat_expanduser('~/.config')
66 userConfFile = os.path.join(xdg_config_home, package_name, 'config')
67 if not os.path.isfile(userConfFile):
68 userConfFile = os.path.join(xdg_config_home, '%s.conf' % package_name)
69 userConf = _readOptions(userConfFile, default=None)
70 if userConf is not None:
0202b52a 71 return userConf, userConfFile
34a741a8 72
e2e43aea 73 # appdata
74 appdata_dir = compat_getenv('appdata')
75 if appdata_dir:
76 userConfFile = os.path.join(appdata_dir, package_name, 'config')
77 userConf = _readOptions(userConfFile, default=None)
78 if userConf is None:
0202b52a 79 userConfFile += '.txt'
80 userConf = _readOptions(userConfFile, default=None)
e2e43aea 81 if userConf is not None:
0202b52a 82 return userConf, userConfFile
34a741a8 83
e2e43aea 84 # home
85 userConfFile = os.path.join(compat_expanduser('~'), '%s.conf' % package_name)
86 userConf = _readOptions(userConfFile, default=None)
34a741a8 87 if userConf is None:
0202b52a 88 userConfFile += '.txt'
89 userConf = _readOptions(userConfFile, default=None)
e2e43aea 90 if userConf is not None:
0202b52a 91 return userConf, userConfFile
34a741a8 92
0202b52a 93 return default, None
34a741a8
PH
94
95 def _format_option_string(option):
96 ''' ('-o', '--option') -> -o, --format METAVAR'''
97
98 opts = []
99
100 if option._short_opts:
101 opts.append(option._short_opts[0])
102 if option._long_opts:
103 opts.append(option._long_opts[0])
104 if len(opts) > 1:
105 opts.insert(1, ', ')
106
8450c15c
PH
107 if option.takes_value():
108 opts.append(' %s' % option.metavar)
34a741a8 109
611c1dd9 110 return ''.join(opts)
34a741a8
PH
111
112 def _comma_separated_values_options_callback(option, opt_str, value, parser):
113 setattr(parser.values, option.dest, value.split(','))
114
45016689 115 def _dict_from_multiple_values_options_callback(
116 option, opt_str, value, parser, allowed_keys=r'[\w-]+', delimiter=':', default_key=None, process=None):
117
118 out_dict = getattr(parser.values, option.dest)
119 mobj = re.match(r'(?i)(?P<key>%s)%s(?P<val>.*)$' % (allowed_keys, delimiter), value)
120 if mobj is not None:
121 key, val = mobj.group('key').lower(), mobj.group('val')
122 elif default_key is not None:
123 key, val = default_key, value
124 else:
125 raise optparse.OptionValueError(
126 'wrong %s formatting; it should be %s, not "%s"' % (opt_str, option.metavar, value))
127 out_dict[key] = process(val) if callable(process) else val
128
34a741a8 129 # No need to wrap help messages if we're on a wide console
003c69a8 130 columns = compat_get_terminal_size().columns
8450c15c
PH
131 max_width = columns if columns else 80
132 max_help_position = 80
34a741a8
PH
133
134 fmt = optparse.IndentedHelpFormatter(width=max_width, max_help_position=max_help_position)
135 fmt.format_option_strings = _format_option_string
136
137 kw = {
8450c15c
PH
138 'version': __version__,
139 'formatter': fmt,
a42419da 140 'usage': '%prog [OPTIONS] URL [URL...]',
8450c15c 141 'conflict_handler': 'resolve',
34a741a8
PH
142 }
143
c7b0add8 144 parser = optparse.OptionParser(**compat_kwargs(kw))
34a741a8 145
8450c15c
PH
146 general = optparse.OptionGroup(parser, 'General Options')
147 general.add_option(
148 '-h', '--help',
149 action='help',
17941321 150 help='Print this help text and exit')
8450c15c 151 general.add_option(
b76f0e58 152 '--version',
8450c15c 153 action='version',
17941321 154 help='Print program version and exit')
8450c15c
PH
155 general.add_option(
156 '-U', '--update',
157 action='store_true', dest='update_self',
c76eb41b 158 help='[BROKEN] Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
8450c15c 159 general.add_option(
6623ac34 160 '-i', '--ignore-errors', '--no-abort-on-error',
91ebc640 161 action='store_true', dest='ignoreerrors', default=True,
8a51f564 162 help='Continue on download errors, for example to skip unavailable videos in a playlist (default) (Alias: --no-abort-on-error)')
8450c15c 163 general.add_option(
6623ac34 164 '--abort-on-error', '--no-ignore-errors',
8450c15c 165 action='store_false', dest='ignoreerrors',
8a51f564 166 help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
8450c15c
PH
167 general.add_option(
168 '--dump-user-agent',
169 action='store_true', dest='dump_user_agent', default=False,
17941321 170 help='Display the current browser identification')
34a741a8 171 general.add_option(
8450c15c
PH
172 '--list-extractors',
173 action='store_true', dest='list_extractors', default=False,
9836cfb8 174 help='List all supported extractors')
8450c15c
PH
175 general.add_option(
176 '--extractor-descriptions',
177 action='store_true', dest='list_extractor_descriptions', default=False,
178 help='Output descriptions of all supported extractors')
d22dec74
S
179 general.add_option(
180 '--force-generic-extractor',
181 action='store_true', dest='force_generic_extractor', default=False,
182 help='Force extraction to use the generic extractor')
34a741a8
PH
183 general.add_option(
184 '--default-search',
185 dest='default_search', metavar='PREFIX',
8a51f564 186 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')
34a741a8 187 general.add_option(
6623ac34 188 '--ignore-config', '--no-config',
34a741a8 189 action='store_true',
6623ac34 190 help=(
298f597b 191 'Disable loading any configuration files except the one provided by --config-location. '
192 'When given inside a configuration file, no further configuration files are loaded. '
193 'Additionally, (for backward compatibility) if this option is found inside the '
8a51f564 194 'system configuration file, the user configuration is not loaded'))
e66dca5e 195 general.add_option(
b6ee45e9
S
196 '--config-location',
197 dest='config_location', metavar='PATH',
0202b52a 198 help='Location of the main configuration file; either the path to the config or its containing directory')
057a5206
PH
199 general.add_option(
200 '--flat-playlist',
6623ac34 201 action='store_const', dest='extract_flat', const='in_playlist', default=False,
8a51f564 202 help='Do not extract the videos of a playlist, only list them')
6623ac34 203 general.add_option(
204 '--flat-videos',
205 action='store_true', dest='extract_flat',
206 help='Do not resolve the video urls')
207 general.add_option(
208 '--no-flat-playlist',
209 action='store_false', dest='extract_flat',
210 help='Extract the videos of a playlist')
d77ab8e2
S
211 general.add_option(
212 '--mark-watched',
213 action='store_true', dest='mark_watched', default=False,
214 help='Mark videos watched (YouTube only)')
90f794c6
S
215 general.add_option(
216 '--no-mark-watched',
217 action='store_false', dest='mark_watched', default=False,
6623ac34 218 help='Do not mark videos watched')
7e5db8c9 219 general.add_option(
8a51f564 220 '--no-colors',
7e5db8c9
PH
221 action='store_true', dest='no_color',
222 default=False,
17941321 223 help='Do not emit color codes in output')
34a741a8 224
be4a824d
PH
225 network = optparse.OptionGroup(parser, 'Network Options')
226 network.add_option(
227 '--proxy', dest='proxy',
228 default=None, metavar='URL',
6623ac34 229 help=(
230 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
231 'SOCKS proxy, specify a proper scheme. For example '
232 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
233 'for direct connection'))
be4a824d
PH
234 network.add_option(
235 '--socket-timeout',
236 dest='socket_timeout', type=float, default=None, metavar='SECONDS',
237 help='Time to wait before giving up, in seconds')
238 network.add_option(
239 '--source-address',
240 metavar='IP', dest='source_address', default=None,
24ee6b97 241 help='Client-side IP address to bind to',
be4a824d 242 )
500b8b41
PH
243 network.add_option(
244 '-4', '--force-ipv4',
245 action='store_const', const='0.0.0.0', dest='source_address',
24ee6b97 246 help='Make all connections via IPv4',
500b8b41
PH
247 )
248 network.add_option(
249 '-6', '--force-ipv6',
250 action='store_const', const='::', dest='source_address',
24ee6b97 251 help='Make all connections via IPv6',
500b8b41 252 )
0aa10994
S
253
254 geo = optparse.OptionGroup(parser, 'Geo Restriction')
255 geo.add_option(
38cce791
YCH
256 '--geo-verification-proxy',
257 dest='geo_verification_proxy', default=None, metavar='URL',
6623ac34 258 help=(
259 'Use this proxy to verify the IP address for some geo-restricted sites. '
8a51f564 260 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
0aa10994 261 geo.add_option(
91410c9b
PH
262 '--cn-verification-proxy',
263 dest='cn_verification_proxy', default=None, metavar='URL',
0aa10994
S
264 help=optparse.SUPPRESS_HELP)
265 geo.add_option(
266 '--geo-bypass',
267 action='store_true', dest='geo_bypass', default=True,
504f20dd 268 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
0aa10994
S
269 geo.add_option(
270 '--no-geo-bypass',
271 action='store_false', dest='geo_bypass', default=True,
504f20dd 272 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
0aa10994
S
273 geo.add_option(
274 '--geo-bypass-country', metavar='CODE',
275 dest='geo_bypass_country', default=None,
504f20dd 276 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
5f95927a
S
277 geo.add_option(
278 '--geo-bypass-ip-block', metavar='IP_BLOCK',
279 dest='geo_bypass_ip_block', default=None,
504f20dd 280 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
be4a824d 281
8450c15c 282 selection = optparse.OptionGroup(parser, 'Video Selection')
34a741a8
PH
283 selection.add_option(
284 '--playlist-start',
285 dest='playliststart', metavar='NUMBER', default=1, type=int,
17941321 286 help='Playlist video to start at (default is %default)')
34a741a8
PH
287 selection.add_option(
288 '--playlist-end',
289 dest='playlistend', metavar='NUMBER', default=None, type=int,
17941321 290 help='Playlist video to end at (default is last)')
c14e88f0
PH
291 selection.add_option(
292 '--playlist-items',
293 dest='playlist_items', metavar='ITEM_SPEC', default=None,
8a51f564 294 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')
34a741a8 295 selection.add_option(
8450c15c
PH
296 '--match-title',
297 dest='matchtitle', metavar='REGEX',
17941321 298 help='Download only matching titles (regex or caseless sub-string)')
8450c15c
PH
299 selection.add_option(
300 '--reject-title',
301 dest='rejecttitle', metavar='REGEX',
17941321 302 help='Skip download for matching titles (regex or caseless sub-string)')
8450c15c
PH
303 selection.add_option(
304 '--max-downloads',
305 dest='max_downloads', metavar='NUMBER', type=int, default=None,
306 help='Abort after downloading NUMBER files')
307 selection.add_option(
308 '--min-filesize',
309 metavar='SIZE', dest='min_filesize', default=None,
310 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
311 selection.add_option(
312 '--max-filesize',
313 metavar='SIZE', dest='max_filesize', default=None,
314 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
315 selection.add_option(
316 '--date',
317 metavar='DATE', dest='date', default=None,
c76eb41b 318 help=(
8a51f564 319 'Download only videos uploaded in this date. '
320 'The date can be "YYYYMMDD" or in the format '
c76eb41b 321 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
8450c15c
PH
322 selection.add_option(
323 '--datebefore',
324 metavar='DATE', dest='datebefore', default=None,
c76eb41b 325 help=(
326 'Download only videos uploaded on or before this date. '
327 'The date formats accepted is the same as --date'))
34a741a8 328 selection.add_option(
8450c15c
PH
329 '--dateafter',
330 metavar='DATE', dest='dateafter', default=None,
c76eb41b 331 help=(
332 'Download only videos uploaded on or after this date. '
333 'The date formats accepted is the same as --date'))
34a741a8 334 selection.add_option(
8450c15c
PH
335 '--min-views',
336 metavar='COUNT', dest='min_views', default=None, type=int,
17941321 337 help='Do not download any videos with less than COUNT views')
34a741a8 338 selection.add_option(
8450c15c
PH
339 '--max-views',
340 metavar='COUNT', dest='max_views', default=None, type=int,
341 help='Do not download any videos with more than COUNT views')
347de493
PH
342 selection.add_option(
343 '--match-filter',
344 metavar='FILTER', dest='match_filter', default=None,
345 help=(
24ee6b97 346 'Generic video filter. '
8a51f564 347 'Specify any key (see "OUTPUT TEMPLATE" for a list of available keys) to '
2c1f442c
S
348 'match if the key is present, '
349 '!key to check if the key is not present, '
8a51f564 350 'key>NUMBER (like "comment_count > 12", also works with '
ac33accd
S
351 '>=, <, <=, !=, =) to compare against a number, '
352 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
353 'to match against a string literal '
354 'and & to require multiple matches. '
2c1f442c
S
355 'Values which are not known are excluded unless you '
356 'put a question mark (?) after the operator. '
347de493
PH
357 'For example, to only match videos that have been liked more than '
358 '100 times and disliked less than 50 times (or the dislike '
359 'functionality is not available at the given service), but who '
5495937f 360 'also have a description, use --match-filter '
8a51f564 361 '"like_count > 100 & dislike_count <? 50 & description"'))
6623ac34 362 selection.add_option(
363 '--no-match-filter',
364 metavar='FILTER', dest='match_filter', action='store_const', const=None,
365 help='Do not use generic video filter (default)')
34a741a8 366 selection.add_option(
8450c15c
PH
367 '--no-playlist',
368 action='store_true', dest='noplaylist', default=False,
8a51f564 369 help='Download only the video, if the URL refers to a video and a playlist')
df4bd0d5
PH
370 selection.add_option(
371 '--yes-playlist',
372 action='store_false', dest='noplaylist', default=False,
8a51f564 373 help='Download the playlist, if the URL refers to a video and a playlist')
8450c15c
PH
374 selection.add_option(
375 '--age-limit',
376 metavar='YEARS', dest='age_limit', default=None, type=int,
17941321 377 help='Download only videos suitable for the given age')
8450c15c
PH
378 selection.add_option(
379 '--download-archive', metavar='FILE',
380 dest='download_archive',
8a51f564 381 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
ea6e0c2b 382 selection.add_option(
383 '--break-on-existing',
384 action='store_true', dest='break_on_existing', default=False,
8a51f564 385 help='Stop the download process when encountering a file that is in the archive')
8b0d7497 386 selection.add_option(
387 '--break-on-reject',
388 action='store_true', dest='break_on_reject', default=False,
8a51f564 389 help='Stop the download process when encountering a file that has been filtered out')
6623ac34 390 selection.add_option(
391 '--no-download-archive',
392 dest='download_archive', action="store_const", const=None,
393 help='Do not use archive file (default)')
8450c15c
PH
394 selection.add_option(
395 '--include-ads',
396 dest='include_ads', action='store_true',
34a741a8 397 help='Download advertisements as well (experimental)')
6623ac34 398 selection.add_option(
399 '--no-include-ads',
400 dest='include_ads', action='store_false',
401 help='Do not download advertisements (default)')
34a741a8 402
8450c15c
PH
403 authentication = optparse.OptionGroup(parser, 'Authentication Options')
404 authentication.add_option(
405 '-u', '--username',
406 dest='username', metavar='USERNAME',
17941321 407 help='Login with this account ID')
8450c15c
PH
408 authentication.add_option(
409 '-p', '--password',
410 dest='password', metavar='PASSWORD',
8a51f564 411 help='Account password. If this option is left out, youtube-dlc will ask interactively')
8450c15c
PH
412 authentication.add_option(
413 '-2', '--twofactor',
414 dest='twofactor', metavar='TWOFACTOR',
3540fe26 415 help='Two-factor authentication code')
8450c15c
PH
416 authentication.add_option(
417 '-n', '--netrc',
418 action='store_true', dest='usenetrc', default=False,
17941321 419 help='Use .netrc authentication data')
8450c15c
PH
420 authentication.add_option(
421 '--video-password',
422 dest='videopassword', metavar='PASSWORD',
29f7c58a 423 help='Video password (vimeo, youku)')
1b6712ab
RA
424
425 adobe_pass = optparse.OptionGroup(parser, 'Adobe Pass Options')
426 adobe_pass.add_option(
797c636b
RA
427 '--ap-mso',
428 dest='ap_mso', metavar='MSO',
537f7533 429 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
1b6712ab
RA
430 adobe_pass.add_option(
431 '--ap-username',
797c636b 432 dest='ap_username', metavar='USERNAME',
537f7533 433 help='Multiple-system operator account login')
1b6712ab
RA
434 adobe_pass.add_option(
435 '--ap-password',
797c636b 436 dest='ap_password', metavar='PASSWORD',
8a51f564 437 help='Multiple-system operator account password. If this option is left out, youtube-dlc will ask interactively')
1b6712ab 438 adobe_pass.add_option(
87148bb7
RA
439 '--ap-list-mso',
440 action='store_true', dest='ap_list_mso', default=False,
537f7533 441 help='List all supported multiple-system operators')
8450c15c
PH
442
443 video_format = optparse.OptionGroup(parser, 'Video Format Options')
444 video_format.add_option(
445 '-f', '--format',
446 action='store', dest='format', metavar='FORMAT', default=None,
eb8a4433 447 help='Video format code, see "FORMAT SELECTION" for more details')
448 video_format.add_option(
c76eb41b 449 '-S', '--format-sort', metavar='SORTORDER',
eb8a4433 450 dest='format_sort', default=[],
451 action='callback', callback=_comma_separated_values_options_callback, type='str',
452 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
453 video_format.add_option(
454 '--format-sort-force', '--S-force',
455 action='store_true', dest='format_sort_force', metavar='FORMAT', default=False,
456 help=(
457 'Force user specified sort order to have precedence over all fields, '
458 'see "Sorting Formats" for more details'))
459 video_format.add_option(
460 '--no-format-sort-force',
461 action='store_false', dest='format_sort_force', metavar='FORMAT', default=False,
462 help=(
463 'Some fields have precedence over the user specified sort order (default), '
464 'see "Sorting Formats" for more details'))
909d24dd 465 video_format.add_option(
466 '--video-multistreams',
91ebc640 467 action='store_true', dest='allow_multiple_video_streams', default=False,
468 help='Allow multiple video streams to be merged into a single file')
909d24dd 469 video_format.add_option(
470 '--no-video-multistreams',
471 action='store_false', dest='allow_multiple_video_streams',
91ebc640 472 help='Only one video stream is downloaded for each output file (default)')
909d24dd 473 video_format.add_option(
474 '--audio-multistreams',
91ebc640 475 action='store_true', dest='allow_multiple_audio_streams', default=False,
476 help='Allow multiple audio streams to be merged into a single file')
909d24dd 477 video_format.add_option(
478 '--no-audio-multistreams',
479 action='store_false', dest='allow_multiple_audio_streams',
91ebc640 480 help='Only one audio stream is downloaded for each output file (default)')
8450c15c
PH
481 video_format.add_option(
482 '--all-formats',
483 action='store_const', dest='format', const='all',
17941321 484 help='Download all available video formats')
8450c15c
PH
485 video_format.add_option(
486 '--prefer-free-formats',
487 action='store_true', dest='prefer_free_formats', default=False,
6fd35a11 488 help='Prefer free video formats over non-free formats of same quality')
8450c15c
PH
489 video_format.add_option(
490 '-F', '--list-formats',
491 action='store_true', dest='listformats',
4b3fbafd 492 help='List all available formats of requested videos')
76d321f6 493 video_format.add_option(
494 '--list-formats-as-table',
91ebc640 495 action='store_true', dest='listformats_table', default=True,
8a51f564 496 help='Present the output of -F in tabular form (default)')
76d321f6 497 video_format.add_option(
6623ac34 498 '--list-formats-old', '--no-list-formats-as-table',
76d321f6 499 action='store_false', dest='listformats_table',
8a51f564 500 help='Present the output of -F in the old form (Alias: --no-list-formats-as-table)')
203fb43f 501 video_format.add_option(
6623ac34 502 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
203fb43f 503 action='store_true', dest='youtube_include_dash_manifest', default=True,
8a51f564 504 help='Download the DASH manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-dash-manifest)')
203fb43f 505 video_format.add_option(
6623ac34 506 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
203fb43f 507 action='store_false', dest='youtube_include_dash_manifest',
8a51f564 508 help='Do not download the DASH manifests and related data on YouTube videos (Alias: --no-youtube-include-dash-manifest)')
78895bd3 509 video_format.add_option(
6623ac34 510 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
78895bd3 511 action='store_true', dest='youtube_include_hls_manifest', default=True,
8a51f564 512 help='Download the HLS manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-hls-manifest)')
78895bd3 513 video_format.add_option(
6623ac34 514 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
78895bd3 515 action='store_false', dest='youtube_include_hls_manifest',
8a51f564 516 help='Do not download the HLS manifests and related data on YouTube videos (Alias: --no-youtube-include-hls-manifest)')
d120e901 517 video_format.add_option(
bd1a281e
PH
518 '--merge-output-format',
519 action='store', dest='merge_output_format', metavar='FORMAT', default=None,
d120e901 520 help=(
00334d0d
S
521 'If a merge is required (e.g. bestvideo+bestaudio), '
522 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
d120e901 523 'Ignored if no merge is required'))
8450c15c
PH
524
525 subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
526 subtitles.add_option(
6623ac34 527 '--write-subs', '--write-srt',
8450c15c 528 action='store_true', dest='writesubtitles', default=False,
17941321 529 help='Write subtitle file')
8450c15c 530 subtitles.add_option(
6623ac34 531 '--no-write-subs', '--no-write-srt',
532 action='store_false', dest='writesubtitles',
533 help='Do not write subtitle file (default)')
534 subtitles.add_option(
535 '--write-auto-subs', '--write-automatic-subs',
8450c15c 536 action='store_true', dest='writeautomaticsub', default=False,
741dd8ea 537 help='Write automatically generated subtitle file (YouTube only)')
6623ac34 538 subtitles.add_option(
539 '--no-write-auto-subs', '--no-write-automatic-subs',
540 action='store_false', dest='writeautomaticsub', default=False,
541 help='Do not write automatically generated subtitle file (default)')
8450c15c
PH
542 subtitles.add_option(
543 '--all-subs',
544 action='store_true', dest='allsubtitles', default=False,
17941321 545 help='Download all the available subtitles of the video')
8450c15c
PH
546 subtitles.add_option(
547 '--list-subs',
548 action='store_true', dest='listsubtitles', default=False,
17941321 549 help='List all available subtitles for the video')
8450c15c
PH
550 subtitles.add_option(
551 '--sub-format',
a504ced0 552 action='store', dest='subtitlesformat', metavar='FORMAT', default='best',
4a3cdf81 553 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
8450c15c
PH
554 subtitles.add_option(
555 '--sub-lang', '--sub-langs', '--srt-lang',
556 action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
557 default=[], callback=_comma_separated_values_options_callback,
1ca59dac 558 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
8450c15c
PH
559
560 downloader = optparse.OptionGroup(parser, 'Download Options')
561 downloader.add_option(
8ec2b2c4
S
562 '-r', '--limit-rate', '--rate-limit',
563 dest='ratelimit', metavar='RATE',
17941321 564 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
8450c15c
PH
565 downloader.add_option(
566 '-R', '--retries',
567 dest='retries', metavar='RETRIES', default=10,
8a51f564 568 help='Number of retries (default is %default), or "infinite"')
52bb437e
S
569 downloader.add_option(
570 '--fragment-retries',
571 dest='fragment_retries', metavar='RETRIES', default=10,
12ee65ea 572 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
9603b660 573 downloader.add_option(
c76eb41b 574 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
9603b660 575 action='store_true', dest='skip_unavailable_fragments', default=True,
8a51f564 576 help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)')
732fb3f8 577 downloader.add_option(
6623ac34 578 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
9603b660 579 action='store_false', dest='skip_unavailable_fragments',
8a51f564 580 help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
0eee52f3
S
581 downloader.add_option(
582 '--keep-fragments',
583 action='store_true', dest='keep_fragments', default=False,
6623ac34 584 help='Keep downloaded fragments on disk after downloading is finished')
585 downloader.add_option(
586 '--no-keep-fragments',
587 action='store_false', dest='keep_fragments',
588 help='Delete downloaded fragments after downloading is finished (default)')
8450c15c
PH
589 downloader.add_option(
590 '--buffer-size',
591 dest='buffersize', metavar='SIZE', default='1024',
17941321 592 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
6623ac34 593 downloader.add_option(
594 '--resize-buffer',
595 action='store_false', dest='noresizebuffer',
596 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
8450c15c
PH
597 downloader.add_option(
598 '--no-resize-buffer',
599 action='store_true', dest='noresizebuffer', default=False,
6623ac34 600 help='Do not automatically adjust the buffer size')
ba515388
S
601 downloader.add_option(
602 '--http-chunk-size',
603 dest='http_chunk_size', metavar='SIZE', default=None,
6623ac34 604 help=(
605 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
606 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
8450c15c
PH
607 downloader.add_option(
608 '--test',
609 action='store_true', dest='test', default=False,
610 help=optparse.SUPPRESS_HELP)
ff815fe6
MS
611 downloader.add_option(
612 '--playlist-reverse',
613 action='store_true',
614 help='Download playlist videos in reverse order')
6623ac34 615 downloader.add_option(
616 '--no-playlist-reverse',
c76eb41b 617 action='store_false', dest='playlist_reverse',
6623ac34 618 help='Download playlist videos in default order (default)')
75822ca7
TC
619 downloader.add_option(
620 '--playlist-random',
621 action='store_true',
622 help='Download playlist videos in random order')
881e6a1f
PH
623 downloader.add_option(
624 '--xattr-set-filesize',
625 dest='xattr_set_filesize', action='store_true',
504f20dd 626 help='Set file xattribute ytdl.filesize with expected file size')
85729c51
PH
627 downloader.add_option(
628 '--hls-prefer-native',
bf09af3a 629 dest='hls_prefer_native', action='store_true', default=None,
870d5258 630 help='Use the native HLS downloader instead of ffmpeg')
bf09af3a
S
631 downloader.add_option(
632 '--hls-prefer-ffmpeg',
633 dest='hls_prefer_native', action='store_false', default=None,
634 help='Use ffmpeg instead of the native HLS downloader')
7d106a65
JMF
635 downloader.add_option(
636 '--hls-use-mpegts',
637 dest='hls_use_mpegts', action='store_true',
6623ac34 638 help=(
639 'Use the mpegts container for HLS videos, allowing to play the '
640 'video while downloading (some players may not be able to play it)'))
222516d9
PH
641 downloader.add_option(
642 '--external-downloader',
46ee996e 643 dest='external_downloader', metavar='NAME',
6623ac34 644 help=(
645 'Use the specified external downloader. '
46ee996e 646 'Currently supports %s' % ', '.join(list_external_downloaders())))
c75f0b36 647 downloader.add_option(
46ee996e 648 '--downloader-args', '--external-downloader-args',
649 metavar='NAME:ARGS', dest='external_downloader_args', default={}, type='str',
650 action='callback', callback=_dict_from_multiple_values_options_callback,
b8f6bbe6 651 callback_kwargs={
0202b52a 652 'allowed_keys': '|'.join(list_external_downloaders()),
b8f6bbe6 653 'default_key': 'default', 'process': compat_shlex_split},
46ee996e 654 help=(
655 'Give these arguments to the external downloader. '
656 'Specify the downloader name and the arguments separated by a colon ":". '
657 'You can use this option multiple times (Alias: --external-downloader-args)'))
8450c15c
PH
658
659 workarounds = optparse.OptionGroup(parser, 'Workarounds')
34a741a8 660 workarounds.add_option(
8450c15c
PH
661 '--encoding',
662 dest='encoding', metavar='ENCODING',
34a741a8
PH
663 help='Force the specified encoding (experimental)')
664 workarounds.add_option(
8450c15c
PH
665 '--no-check-certificate',
666 action='store_true', dest='no_check_certificate', default=False,
17941321 667 help='Suppress HTTPS certificate validation')
34a741a8 668 workarounds.add_option(
6623ac34 669 '--prefer-insecure', '--prefer-unsecure',
670 action='store_true', dest='prefer_insecure',
0c3e5f49 671 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
34a741a8 672 workarounds.add_option(
8450c15c
PH
673 '--user-agent',
674 metavar='UA', dest='user_agent',
17941321 675 help='Specify a custom user agent')
34a741a8 676 workarounds.add_option(
8450c15c
PH
677 '--referer',
678 metavar='URL', dest='referer', default=None,
17941321 679 help='Specify a custom referer, use if the video access is restricted to one domain',
34a741a8
PH
680 )
681 workarounds.add_option(
8450c15c 682 '--add-header',
45016689 683 metavar='FIELD:VALUE', dest='headers', default={}, type='str',
684 action='callback', callback=_dict_from_multiple_values_options_callback,
685 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
34a741a8
PH
686 )
687 workarounds.add_option(
8450c15c
PH
688 '--bidi-workaround',
689 dest='bidi_workaround', action='store_true',
690 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
5f0d813d 691 workarounds.add_option(
065bc354 692 '--sleep-interval', '--min-sleep-interval', metavar='SECONDS',
649f7966 693 dest='sleep_interval', type=float,
7aa589a5
S
694 help=(
695 'Number of seconds to sleep before each download when used alone '
696 'or a lower bound of a range for randomized sleep before each download '
697 '(minimum possible number of seconds to sleep) when used along with '
8a51f564 698 '--max-sleep-interval'))
065bc354 699 workarounds.add_option(
700 '--max-sleep-interval', metavar='SECONDS',
701 dest='max_sleep_interval', type=float,
7aa589a5
S
702 help=(
703 'Upper bound of a range for randomized sleep before each download '
704 '(maximum possible number of seconds to sleep). Must only be used '
8a51f564 705 'along with --min-sleep-interval'))
0c9df79e 706 workarounds.add_option(
c76eb41b 707 '--sleep-subtitles', metavar='SECONDS',
31108ce9 708 dest='sleep_interval_subtitles', default=0, type=int,
0c9df79e 709 help='Enforce sleep interval on subtitles as well')
34a741a8 710
8450c15c
PH
711 verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
712 verbosity.add_option(
713 '-q', '--quiet',
714 action='store_true', dest='quiet', default=False,
17941321 715 help='Activate quiet mode')
34a741a8
PH
716 verbosity.add_option(
717 '--no-warnings',
718 dest='no_warnings', action='store_true', default=False,
719 help='Ignore warnings')
8450c15c
PH
720 verbosity.add_option(
721 '-s', '--simulate',
722 action='store_true', dest='simulate', default=False,
17941321 723 help='Do not download the video and do not write anything to disk')
8450c15c 724 verbosity.add_option(
6623ac34 725 '--skip-download', '--no-download',
8450c15c 726 action='store_true', dest='skip_download', default=False,
17941321 727 help='Do not download the video')
8450c15c
PH
728 verbosity.add_option(
729 '-g', '--get-url',
730 action='store_true', dest='geturl', default=False,
17941321 731 help='Simulate, quiet but print URL')
8450c15c
PH
732 verbosity.add_option(
733 '-e', '--get-title',
734 action='store_true', dest='gettitle', default=False,
17941321 735 help='Simulate, quiet but print title')
8450c15c
PH
736 verbosity.add_option(
737 '--get-id',
738 action='store_true', dest='getid', default=False,
17941321 739 help='Simulate, quiet but print id')
8450c15c
PH
740 verbosity.add_option(
741 '--get-thumbnail',
742 action='store_true', dest='getthumbnail', default=False,
17941321 743 help='Simulate, quiet but print thumbnail URL')
8450c15c
PH
744 verbosity.add_option(
745 '--get-description',
746 action='store_true', dest='getdescription', default=False,
17941321 747 help='Simulate, quiet but print video description')
8450c15c
PH
748 verbosity.add_option(
749 '--get-duration',
750 action='store_true', dest='getduration', default=False,
17941321 751 help='Simulate, quiet but print video length')
8450c15c
PH
752 verbosity.add_option(
753 '--get-filename',
754 action='store_true', dest='getfilename', default=False,
17941321 755 help='Simulate, quiet but print output filename')
8450c15c
PH
756 verbosity.add_option(
757 '--get-format',
758 action='store_true', dest='getformat', default=False,
17941321 759 help='Simulate, quiet but print output format')
8450c15c
PH
760 verbosity.add_option(
761 '-j', '--dump-json',
762 action='store_true', dest='dumpjson', default=False,
8a51f564 763 help='Simulate, quiet but print JSON information. See "OUTPUT TEMPLATE" for a description of available keys')
63e0be34
PH
764 verbosity.add_option(
765 '-J', '--dump-single-json',
766 action='store_true', dest='dump_single_json', default=False,
6623ac34 767 help=(
c76eb41b 768 'Simulate, quiet but print JSON information for each command-line argument. '
8a51f564 769 'If the URL refers to a playlist, dump the whole playlist information in a single line'))
c0bdf32a
PH
770 verbosity.add_option(
771 '--print-json',
772 action='store_true', dest='print_json', default=False,
8a51f564 773 help='Be quiet and print the video information as JSON (video is still being downloaded)')
2d30509f 774 verbosity.add_option(
c76eb41b 775 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
2d30509f 776 action='store_true', dest='force_write_download_archive', default=False,
777 help=(
778 'Force download archive entries to be written as far as no errors occur,'
8a51f564 779 'even if -s or another simulation switch is used (Alias: --force-download-archive)'))
8450c15c
PH
780 verbosity.add_option(
781 '--newline',
782 action='store_true', dest='progress_with_newline', default=False,
17941321 783 help='Output progress bar as new lines')
8450c15c
PH
784 verbosity.add_option(
785 '--no-progress',
786 action='store_true', dest='noprogress', default=False,
17941321 787 help='Do not print progress bar')
8450c15c
PH
788 verbosity.add_option(
789 '--console-title',
790 action='store_true', dest='consoletitle', default=False,
17941321 791 help='Display progress in console titlebar')
8450c15c
PH
792 verbosity.add_option(
793 '-v', '--verbose',
794 action='store_true', dest='verbose', default=False,
17941321 795 help='Print various debugging information')
8450c15c 796 verbosity.add_option(
8bba753c 797 '--dump-pages', '--dump-intermediate-pages',
8450c15c 798 action='store_true', dest='dump_intermediate_pages', default=False,
79979c68 799 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
8450c15c
PH
800 verbosity.add_option(
801 '--write-pages',
802 action='store_true', dest='write_pages', default=False,
803 help='Write downloaded intermediary pages to files in the current directory to debug problems')
804 verbosity.add_option(
805 '--youtube-print-sig-code',
806 action='store_true', dest='youtube_print_sig_code', default=False,
807 help=optparse.SUPPRESS_HELP)
808 verbosity.add_option(
2f543a21 809 '--print-traffic', '--dump-headers',
8450c15c
PH
810 dest='debug_printtraffic', action='store_true', default=False,
811 help='Display sent and read HTTP traffic')
58b1f00d
PH
812 verbosity.add_option(
813 '-C', '--call-home',
814 dest='call_home', action='store_true', default=False,
f5546c0b 815 help='[Broken] Contact the youtube-dlc server for debugging')
8bfa7545
PH
816 verbosity.add_option(
817 '--no-call-home',
6623ac34 818 dest='call_home', action='store_false',
819 help='Do not contact the youtube-dlc server for debugging (default)')
8450c15c
PH
820
821 filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
822 filesystem.add_option(
823 '-a', '--batch-file',
824 dest='batchfile', metavar='FILE',
5d60b997 825 help="File containing URLs to download ('-' for stdin), one URL per line. "
8a51f564 826 "Lines starting with '#', ';' or ']' are considered as comments and ignored")
8450c15c
PH
827 filesystem.add_option(
828 '--id', default=False,
6623ac34 829 action='store_true', dest='useid', help=optparse.SUPPRESS_HELP)
0202b52a 830 filesystem.add_option(
831 '-P', '--paths',
832 metavar='TYPE:PATH', dest='paths', default={}, type='str',
833 action='callback', callback=_dict_from_multiple_values_options_callback,
834 callback_kwargs={
de6000d9 835 'allowed_keys': 'home|temp|%s' % '|'.join(OUTTMPL_TYPES.keys()),
0202b52a 836 'process': lambda x: x.strip()},
837 help=(
838 'The paths where the files should be downloaded. '
de6000d9 839 'Specify the type of file and the path separated by a colon ":". '
840 'All the same types as --output are supported. '
0202b52a 841 'Additionally, you can also provide "home" and "temp" paths. '
842 'All intermediary files are first downloaded to the temp path and '
843 'then the final files are moved over to the home path after download is finished. '
de6000d9 844 'This option is ignored if --output is an absolute path'))
8450c15c
PH
845 filesystem.add_option(
846 '-o', '--output',
de6000d9 847 metavar='[TYPE:]TEMPLATE', dest='outtmpl', default={}, type='str',
848 action='callback', callback=_dict_from_multiple_values_options_callback,
849 callback_kwargs={
850 'allowed_keys': '|'.join(OUTTMPL_TYPES.keys()),
851 'default_key': 'default', 'process': lambda x: x.strip()},
8a51f564 852 help='Output filename template, see "OUTPUT TEMPLATE" for details')
a820dc72
RA
853 filesystem.add_option(
854 '--output-na-placeholder',
0bc0a322 855 dest='outtmpl_na_placeholder', metavar='TEXT', default='NA',
856 help=('Placeholder value for unavailable meta fields in output filename template (default: "%default")'))
8450c15c
PH
857 filesystem.add_option(
858 '--autonumber-size',
be5df5ee
S
859 dest='autonumber_size', metavar='NUMBER', type=int,
860 help=optparse.SUPPRESS_HELP)
acbb2374
CP
861 filesystem.add_option(
862 '--autonumber-start',
1a241a2d
S
863 dest='autonumber_start', metavar='NUMBER', default=1, type=int,
864 help='Specify the start value for %(autonumber)s (default is %default)')
8450c15c
PH
865 filesystem.add_option(
866 '--restrict-filenames',
867 action='store_true', dest='restrictfilenames', default=False,
868 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
6623ac34 869 filesystem.add_option(
870 '--no-restrict-filenames',
871 action='store_false', dest='restrictfilenames', default=False,
872 help='Allow Unicode characters, "&" and spaces in filenames (default)')
2865cf04
PH
873 filesystem.add_option(
874 '-A', '--auto-number',
875 action='store_true', dest='autonumber', default=False,
be5df5ee 876 help=optparse.SUPPRESS_HELP)
8450c15c
PH
877 filesystem.add_option(
878 '-t', '--title',
879 action='store_true', dest='usetitle', default=False,
be5df5ee 880 help=optparse.SUPPRESS_HELP)
8450c15c
PH
881 filesystem.add_option(
882 '-l', '--literal', default=False,
883 action='store_true', dest='usetitle',
be5df5ee 884 help=optparse.SUPPRESS_HELP)
8450c15c
PH
885 filesystem.add_option(
886 '-w', '--no-overwrites',
0c3d0f51 887 action='store_false', dest='overwrites', default=None,
888 help='Do not overwrite any files')
889 filesystem.add_option(
890 '--force-overwrites', '--yes-overwrites',
891 action='store_true', dest='overwrites',
892 help='Overwrite all video and metadata files. This option includes --no-continue')
893 filesystem.add_option(
894 '--no-force-overwrites',
895 action='store_const', dest='overwrites', const=None,
896 help='Do not overwrite the video, but overwrite related files (default)')
8450c15c
PH
897 filesystem.add_option(
898 '-c', '--continue',
899 action='store_true', dest='continue_dl', default=True,
c25228e5 900 help='Resume partially downloaded files/fragments (default)')
8450c15c
PH
901 filesystem.add_option(
902 '--no-continue',
903 action='store_false', dest='continue_dl',
c25228e5 904 help=(
905 'Do not resume partially downloaded fragments. '
906 'If the file is unfragmented, restart download of the entire file'))
6623ac34 907 filesystem.add_option(
908 '--part',
909 action='store_false', dest='nopart', default=False,
910 help='Use .part files instead of writing directly into output file (default)')
8450c15c
PH
911 filesystem.add_option(
912 '--no-part',
6623ac34 913 action='store_true', dest='nopart',
17941321 914 help='Do not use .part files - write directly into output file')
6623ac34 915 filesystem.add_option(
916 '--mtime',
917 action='store_true', dest='updatetime', default=True,
918 help='Use the Last-modified header to set the file modification time (default)')
8450c15c
PH
919 filesystem.add_option(
920 '--no-mtime',
6623ac34 921 action='store_false', dest='updatetime',
17941321 922 help='Do not use the Last-modified header to set the file modification time')
8450c15c
PH
923 filesystem.add_option(
924 '--write-description',
925 action='store_true', dest='writedescription', default=False,
17941321 926 help='Write video description to a .description file')
6623ac34 927 filesystem.add_option(
928 '--no-write-description',
929 action='store_false', dest='writedescription',
930 help='Do not write video description (default)')
8450c15c
PH
931 filesystem.add_option(
932 '--write-info-json',
933 action='store_true', dest='writeinfojson', default=False,
c25228e5 934 help='Write video metadata to a .info.json file (this may contain personal information)')
6623ac34 935 filesystem.add_option(
936 '--no-write-info-json',
937 action='store_false', dest='writeinfojson',
938 help='Do not write video metadata (default)')
8450c15c
PH
939 filesystem.add_option(
940 '--write-annotations',
941 action='store_true', dest='writeannotations', default=False,
0669c89c 942 help='Write video annotations to a .annotations.xml file')
6623ac34 943 filesystem.add_option(
944 '--no-write-annotations',
945 action='store_false', dest='writeannotations',
946 help='Do not write video annotations (default)')
cac96421 947 filesystem.add_option(
948 '--write-playlist-metafiles',
949 action='store_true', dest='allow_playlist_files', default=True,
950 help=(
951 'Write playlist metadata in addition to the video metadata '
952 'when using --write-info-json, --write-description etc. (default)'))
953 filesystem.add_option(
954 '--no-write-playlist-metafiles',
955 action='store_false', dest='allow_playlist_files',
956 help=(
957 'Do not write playlist metadata when using '
958 '--write-info-json, --write-description etc.'))
06167fbb 959 filesystem.add_option(
960 '--get-comments',
961 action='store_true', dest='getcomments', default=False,
962 help='Retrieve video comments to be placed in the .info.json file')
8450c15c 963 filesystem.add_option(
244fe977 964 '--load-info-json', '--load-info',
8450c15c 965 dest='load_info_filename', metavar='FILE',
1a48181a 966 help='JSON file containing the video information (created with the "--write-info-json" option)')
8450c15c
PH
967 filesystem.add_option(
968 '--cookies',
969 dest='cookiefile', metavar='FILE',
17941321 970 help='File to read cookies from and dump cookie jar in')
6623ac34 971 filesystem.add_option(
972 '--no-cookies',
973 action='store_const', const=None, dest='cookiefile', metavar='FILE',
974 help='Do not read/dump cookies (default)')
34a741a8
PH
975 filesystem.add_option(
976 '--cache-dir', dest='cachedir', default=None, metavar='DIR',
8a51f564 977 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')
34a741a8 978 filesystem.add_option(
6623ac34 979 '--no-cache-dir', action='store_false', dest='cachedir',
34a741a8
PH
980 help='Disable filesystem caching')
981 filesystem.add_option(
8450c15c
PH
982 '--rm-cache-dir',
983 action='store_true', dest='rm_cachedir',
34a741a8 984 help='Delete all filesystem cache files')
bdc3fd2f 985 filesystem.add_option(
c76eb41b 986 '--trim-file-name', metavar='LENGTH',
987 dest='trim_file_name', default=0, type=int,
bdc3fd2f 988 help='Limit the filename length (extension excluded)')
34a741a8 989
6623ac34 990 thumbnail = optparse.OptionGroup(parser, 'Thumbnail Images')
cfb56d1a
PH
991 thumbnail.add_option(
992 '--write-thumbnail',
993 action='store_true', dest='writethumbnail', default=False,
17941321 994 help='Write thumbnail image to disk')
6623ac34 995 thumbnail.add_option(
996 '--no-write-thumbnail',
997 action='store_false', dest='writethumbnail',
998 help='Do not write thumbnail image to disk (default)')
ec82d85a
PH
999 thumbnail.add_option(
1000 '--write-all-thumbnails',
1001 action='store_true', dest='write_all_thumbnails', default=False,
17941321 1002 help='Write all thumbnail image formats to disk')
cfb56d1a
PH
1003 thumbnail.add_option(
1004 '--list-thumbnails',
1005 action='store_true', dest='list_thumbnails', default=False,
1006 help='Simulate and list all available thumbnail formats')
1007
732044af 1008 link = optparse.OptionGroup(parser, 'Internet Shortcut Options')
1009 link.add_option(
1010 '--write-link',
1011 action='store_true', dest='writelink', default=False,
8a51f564 1012 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
732044af 1013 link.add_option(
1014 '--write-url-link',
1015 action='store_true', dest='writeurllink', default=False,
8a51f564 1016 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
732044af 1017 link.add_option(
1018 '--write-webloc-link',
1019 action='store_true', dest='writewebloclink', default=False,
8a51f564 1020 help='Write a .webloc macOS internet shortcut')
732044af 1021 link.add_option(
1022 '--write-desktop-link',
1023 action='store_true', dest='writedesktoplink', default=False,
8a51f564 1024 help='Write a .desktop Linux internet shortcut')
732044af 1025
1026 postproc = optparse.OptionGroup(parser, 'Post-Processing Options')
8450c15c
PH
1027 postproc.add_option(
1028 '-x', '--extract-audio',
1029 action='store_true', dest='extractaudio', default=False,
e4172ac9 1030 help='Convert video files to audio-only files (requires ffmpeg and ffprobe)')
8450c15c
PH
1031 postproc.add_option(
1032 '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
0efbc6b5 1033 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
8450c15c
PH
1034 postproc.add_option(
1035 '--audio-quality', metavar='QUALITY',
1036 dest='audioquality', default='5',
e4172ac9 1037 help='Specify ffmpeg audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
efe87a10
FS
1038 postproc.add_option(
1039 '--remux-video',
1040 metavar='FORMAT', dest='remuxvideo', default=None,
6623ac34 1041 help=(
17912249 1042 'Remux the video into another container if necessary (currently supported: %s). '
06167fbb 1043 'If target container does not support the video/audio codec, remuxing will fail. '
1044 'You can specify multiple rules; eg. "aac>m4a/mov>mp4/mkv" will remux aac to m4a, mov to mp4 '
17912249 1045 'and anything else to mkv.' % '|'.join(_remux_formats)))
8450c15c
PH
1046 postproc.add_option(
1047 '--recode-video',
1048 metavar='FORMAT', dest='recodevideo', default=None,
17912249 1049 help=(
1050 'Re-encode the video into another format if re-encoding is necessary. '
1051 'The supported formats are the same as --remux-video'))
d84f1d14 1052 postproc.add_option(
45016689 1053 '--postprocessor-args', '--ppa',
1054 metavar='NAME:ARGS', dest='postprocessor_args', default={}, type='str',
1055 action='callback', callback=_dict_from_multiple_values_options_callback,
1056 callback_kwargs={'default_key': 'default-compat', 'allowed_keys': r'\w+(?:\+\w+)?', 'process': compat_shlex_split},
1b77b347 1057 help=(
1058 'Give these arguments to the postprocessors. '
43820c03 1059 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
45016689 1060 'to give the argument to the specified postprocessor/executable. Supported postprocessors are: '
43820c03 1061 'SponSkrub, ExtractAudio, VideoRemuxer, VideoConvertor, EmbedSubtitle, Metadata, Merger, '
1062 'FixupStretched, FixupM4a, FixupM3u8, SubtitlesConvertor and EmbedThumbnail. '
e4172ac9 1063 'The supported executables are: SponSkrub, FFmpeg, FFprobe, and AtomicParsley. '
43820c03 1064 'You can use this option multiple times to give different arguments to different postprocessors. '
1065 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
45016689 1066 'only when being used by the specified postprocessor. '
1067 'You can use this option multiple times (Alias: --ppa)'))
8450c15c
PH
1068 postproc.add_option(
1069 '-k', '--keep-video',
1070 action='store_true', dest='keepvideo', default=False,
6623ac34 1071 help='Keep the intermediate video file on disk after post-processing')
1072 postproc.add_option(
1073 '--no-keep-video',
1074 action='store_false', dest='keepvideo',
1075 help='Delete the intermediate video file after post-processing (default)')
1076 postproc.add_option(
1077 '--post-overwrites',
1078 action='store_false', dest='nopostoverwrites',
1079 help='Overwrite post-processed files (default)')
8450c15c
PH
1080 postproc.add_option(
1081 '--no-post-overwrites',
1082 action='store_true', dest='nopostoverwrites', default=False,
6623ac34 1083 help='Do not overwrite post-processed files')
8450c15c
PH
1084 postproc.add_option(
1085 '--embed-subs',
1086 action='store_true', dest='embedsubtitles', default=False,
40025ee2 1087 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
6623ac34 1088 postproc.add_option(
1089 '--no-embed-subs',
1090 action='store_false', dest='embedsubtitles',
1091 help='Do not embed subtitles (default)')
8450c15c
PH
1092 postproc.add_option(
1093 '--embed-thumbnail',
1094 action='store_true', dest='embedthumbnail', default=False,
17941321 1095 help='Embed thumbnail in the audio as cover art')
6623ac34 1096 postproc.add_option(
1097 '--no-embed-thumbnail',
1098 action='store_false', dest='embedthumbnail',
1099 help='Do not embed thumbnail (default)')
8450c15c
PH
1100 postproc.add_option(
1101 '--add-metadata',
1102 action='store_true', dest='addmetadata', default=False,
17941321 1103 help='Write metadata to the video file')
6623ac34 1104 postproc.add_option(
1105 '--no-add-metadata',
1106 action='store_false', dest='addmetadata',
1107 help='Do not write metadata (default)')
e7db87f7 1108 postproc.add_option(
1109 '--metadata-from-title',
1110 metavar='FORMAT', dest='metafromtitle',
5bfa4862 1111 help=optparse.SUPPRESS_HELP)
1112 postproc.add_option(
1113 '--parse-metadata',
1114 metavar='FIELD:FORMAT', dest='metafromfield', action='append',
6623ac34 1115 help=(
5bfa4862 1116 'Parse additional metadata like title/artist from other fields. '
1117 'Give field name to extract data from, and format of the field seperated by a ":". '
29b6000e 1118 'Either regular expression with named capture groups or a '
1119 'similar syntax to the output template can also be used. '
1120 'The parsed parameters replace any existing values and can be use in output template'
5bfa4862 1121 'This option can be used multiple times. '
1122 'Example: --parse-metadata "title:%(artist)s - %(title)s" matches a title like '
6623ac34 1123 '"Coldplay - Paradise". '
5bfa4862 1124 'Example (regex): --parse-metadata "description:Artist - (?P<artist>.+?)"'))
8450c15c
PH
1125 postproc.add_option(
1126 '--xattrs',
1127 action='store_true', dest='xattrs', default=False,
17941321 1128 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
6271f1ca
PH
1129 postproc.add_option(
1130 '--fixup',
1131 metavar='POLICY', dest='fixup', default='detect_or_warn',
6623ac34 1132 help=(
1133 'Automatically correct known faults of the file. '
1134 'One of never (do nothing), warn (only emit a warning), '
1135 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
8450c15c 1136 postproc.add_option(
6623ac34 1137 '--prefer-avconv', '--no-prefer-ffmpeg',
8450c15c 1138 action='store_false', dest='prefer_ffmpeg',
e4172ac9 1139 help=optparse.SUPPRESS_HELP)
8450c15c 1140 postproc.add_option(
6623ac34 1141 '--prefer-ffmpeg', '--no-prefer-avconv',
e4172ac9 1142 action='store_true', dest='prefer_ffmpeg', default=True,
1143 help=optparse.SUPPRESS_HELP)
73fac4e9
PH
1144 postproc.add_option(
1145 '--ffmpeg-location', '--avconv-location', metavar='PATH',
1146 dest='ffmpeg_location',
e4172ac9 1147 help='Location of the ffmpeg binary; either the path to the binary or its containing directory')
34a741a8 1148 postproc.add_option(
8450c15c
PH
1149 '--exec',
1150 metavar='CMD', dest='exec_cmd',
46d0baf9 1151 help='Execute a command on the file after downloading and post-processing, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
e9fade72 1152 postproc.add_option(
f5bc4b5f 1153 '--convert-subs', '--convert-subtitles',
e9fade72 1154 metavar='FORMAT', dest='convertsubtitles', default=None,
8c289530 1155 help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
34a741a8 1156
8a51f564 1157 sponskrub = optparse.OptionGroup(parser, 'SponSkrub (SponsorBlock) Options', description=(
1158 'SponSkrub (https://github.com/pukkandan/SponSkrub) is a utility to mark/remove sponsor segments '
1159 'from downloaded YouTube videos using SponsorBlock API (https://sponsor.ajay.app)'))
c76eb41b 1160 sponskrub.add_option(
a9e7f546 1161 '--sponskrub',
1162 action='store_true', dest='sponskrub', default=None,
6623ac34 1163 help=(
8a51f564 1164 'Use sponskrub to mark sponsored sections. '
6623ac34 1165 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
c76eb41b 1166 sponskrub.add_option(
a9e7f546 1167 '--no-sponskrub',
1168 action='store_false', dest='sponskrub',
6623ac34 1169 help='Do not use sponskrub')
c76eb41b 1170 sponskrub.add_option(
a9e7f546 1171 '--sponskrub-cut', default=False,
1172 action='store_true', dest='sponskrub_cut',
1173 help='Cut out the sponsor sections instead of simply marking them')
c76eb41b 1174 sponskrub.add_option(
6623ac34 1175 '--no-sponskrub-cut',
1176 action='store_false', dest='sponskrub_cut',
1177 help='Simply mark the sponsor sections, not cut them out (default)')
c76eb41b 1178 sponskrub.add_option(
a9e7f546 1179 '--sponskrub-force', default=False,
1180 action='store_true', dest='sponskrub_force',
1181 help='Run sponskrub even if the video was already downloaded')
c76eb41b 1182 sponskrub.add_option(
6623ac34 1183 '--no-sponskrub-force',
1184 action='store_true', dest='sponskrub_force',
1185 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
c76eb41b 1186 sponskrub.add_option(
a9e7f546 1187 '--sponskrub-location', metavar='PATH',
1188 dest='sponskrub_path', default='',
8a51f564 1189 help='Location of the sponskrub binary; either the path to the binary or its containing directory')
c76eb41b 1190 sponskrub.add_option(
1191 '--sponskrub-args', dest='sponskrub_args', metavar='ARGS',
1b77b347 1192 help=optparse.SUPPRESS_HELP)
a9e7f546 1193
78895bd3
U
1194 extractor = optparse.OptionGroup(parser, 'Extractor Options')
1195 extractor.add_option(
6623ac34 1196 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
78895bd3 1197 action='store_true', dest='dynamic_mpd', default=True,
8a51f564 1198 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
78895bd3 1199 extractor.add_option(
6623ac34 1200 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
78895bd3 1201 action='store_false', dest='dynamic_mpd',
8a51f564 1202 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
78895bd3 1203
34a741a8 1204 parser.add_option_group(general)
be4a824d 1205 parser.add_option_group(network)
0aa10994 1206 parser.add_option_group(geo)
34a741a8
PH
1207 parser.add_option_group(selection)
1208 parser.add_option_group(downloader)
1209 parser.add_option_group(filesystem)
cfb56d1a 1210 parser.add_option_group(thumbnail)
732044af 1211 parser.add_option_group(link)
34a741a8
PH
1212 parser.add_option_group(verbosity)
1213 parser.add_option_group(workarounds)
1214 parser.add_option_group(video_format)
1215 parser.add_option_group(subtitles)
1216 parser.add_option_group(authentication)
d2522b86 1217 parser.add_option_group(adobe_pass)
34a741a8 1218 parser.add_option_group(postproc)
c76eb41b 1219 parser.add_option_group(sponskrub)
78895bd3 1220 parser.add_option_group(extractor)
34a741a8
PH
1221
1222 if overrideArguments is not None:
1223 opts, args = parser.parse_args(overrideArguments)
1224 if opts.verbose:
8450c15c 1225 write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
34a741a8 1226 else:
b04b94da
S
1227 def compat_conf(conf):
1228 if sys.version_info < (3,):
1229 return [a.decode(preferredencoding(), 'replace') for a in conf]
1230 return conf
1231
e2e43aea 1232 configs = {
0202b52a 1233 'command-line': compat_conf(sys.argv[1:]),
1234 'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []}
1235 paths = {'command-line': False}
1236 opts, args = parser.parse_args(configs['command-line'])
f5e2efbb 1237
e2e43aea 1238 def get_configs():
0202b52a 1239 if '--config-location' in configs['command-line']:
e2e43aea 1240 location = compat_expanduser(opts.config_location)
1241 if os.path.isdir(location):
1242 location = os.path.join(location, 'youtube-dlc.conf')
1243 if not os.path.exists(location):
1244 parser.error('config-location %s does not exist.' % location)
0202b52a 1245 configs['custom'] = _readOptions(location, default=None)
1246 if configs['custom'] is None:
1247 configs['custom'] = []
1248 else:
1249 paths['custom'] = location
1250 if '--ignore-config' in configs['command-line']:
e2e43aea 1251 return
1252 if '--ignore-config' in configs['custom']:
1253 return
1254
0202b52a 1255 def read_options(path, user=False):
b5d26563 1256 for package in ('yt-dlp', 'youtube-dlc'):
0202b52a 1257 if user:
b5d26563 1258 config, current_path = _readUserConf(package, default=None)
1259 else:
1260 current_path = os.path.join(path, '%s.conf' % package)
1261 config = _readOptions(current_path, default=None)
1262 if config is not None:
1263 return config, current_path
1264 return [], None
0202b52a 1265
f74980cb 1266 configs['portable'], paths['portable'] = read_options(get_executable_path())
e2e43aea 1267 if '--ignore-config' in configs['portable']:
1268 return
e2e43aea 1269
0202b52a 1270 def get_home_path():
1271 opts = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line'])[0]
1272 return expand_path(opts.paths.get('home', '')).strip()
1273
1274 configs['home'], paths['home'] = read_options(get_home_path())
1275 if '--ignore-config' in configs['home']:
1276 return
1277
1278 configs['system'], paths['system'] = read_options('/etc')
e2e43aea 1279 if '--ignore-config' in configs['system']:
1280 return
0202b52a 1281
1282 configs['user'], paths['user'] = read_options('', True)
e2e43aea 1283 if '--ignore-config' in configs['user']:
0202b52a 1284 configs['system'], paths['system'] = [], None
e66dca5e 1285
e2e43aea 1286 get_configs()
0202b52a 1287 argv = configs['system'] + configs['user'] + configs['home'] + configs['portable'] + configs['custom'] + configs['command-line']
34a741a8
PH
1288 opts, args = parser.parse_args(argv)
1289 if opts.verbose:
0202b52a 1290 for label in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
1291 key = label.lower()
1292 if paths.get(key) is None:
1293 continue
1294 if paths[key]:
1295 write_string('[debug] %s config file: %s\n' % (label, paths[key]))
1296 write_string('[debug] %s config: %s\n' % (label, repr(_hide_login_info(configs[key]))))
34a741a8
PH
1297
1298 return parser, opts, args