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