]> jfr.im git - yt-dlp.git/blame - youtube_dl/options.py
[rbmaradio] Improve, simplify and extract all formats (Closes #10242)
[yt-dlp.git] / youtube_dl / 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
23def parseOpts(overrideArguments=None):
24 def _readOptions(filename_bytes, default=[]):
25 try:
26 optionf = open(filename_bytes)
27 except IOError:
28 return default # silently skip if file is not present
29 try:
1251565e
S
30 # FIXME: https://github.com/rg3/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
31 contents = optionf.read()
32 if sys.version_info < (3,):
33 contents = contents.decode(preferredencoding())
34 res = compat_shlex_split(contents, comments=True)
34a741a8
PH
35 finally:
36 optionf.close()
37 return res
38
39 def _readUserConf():
4644ac55 40 xdg_config_home = compat_getenv('XDG_CONFIG_HOME')
34a741a8
PH
41 if xdg_config_home:
42 userConfFile = os.path.join(xdg_config_home, 'youtube-dl', 'config')
43 if not os.path.isfile(userConfFile):
44 userConfFile = os.path.join(xdg_config_home, 'youtube-dl.conf')
45 else:
4644ac55 46 userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dl', 'config')
34a741a8 47 if not os.path.isfile(userConfFile):
4644ac55 48 userConfFile = os.path.join(compat_expanduser('~'), '.config', 'youtube-dl.conf')
34a741a8
PH
49 userConf = _readOptions(userConfFile, None)
50
51 if userConf is None:
4644ac55 52 appdata_dir = compat_getenv('appdata')
34a741a8
PH
53 if appdata_dir:
54 userConf = _readOptions(
55 os.path.join(appdata_dir, 'youtube-dl', 'config'),
56 default=None)
57 if userConf is None:
58 userConf = _readOptions(
59 os.path.join(appdata_dir, 'youtube-dl', 'config.txt'),
60 default=None)
61
62 if userConf is None:
63 userConf = _readOptions(
4644ac55 64 os.path.join(compat_expanduser('~'), 'youtube-dl.conf'),
34a741a8
PH
65 default=None)
66 if userConf is None:
67 userConf = _readOptions(
4644ac55 68 os.path.join(compat_expanduser('~'), 'youtube-dl.conf.txt'),
34a741a8
PH
69 default=None)
70
71 if userConf is None:
72 userConf = []
73
74 return userConf
75
76 def _format_option_string(option):
77 ''' ('-o', '--option') -> -o, --format METAVAR'''
78
79 opts = []
80
81 if option._short_opts:
82 opts.append(option._short_opts[0])
83 if option._long_opts:
84 opts.append(option._long_opts[0])
85 if len(opts) > 1:
86 opts.insert(1, ', ')
87
8450c15c
PH
88 if option.takes_value():
89 opts.append(' %s' % option.metavar)
34a741a8 90
611c1dd9 91 return ''.join(opts)
34a741a8
PH
92
93 def _comma_separated_values_options_callback(option, opt_str, value, parser):
94 setattr(parser.values, option.dest, value.split(','))
95
96 def _hide_login_info(opts):
3aa9a735
PH
97 PRIVATE_OPTS = ['-p', '--password', '-u', '--username', '--video-password']
98 eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
99
100 def _scrub_eq(o):
101 m = eqre.match(o)
102 if m:
103 return m.group('key') + '=PRIVATE'
104 else:
105 return o
106
107 opts = list(map(_scrub_eq, opts))
108 for private_opt in PRIVATE_OPTS:
34a741a8
PH
109 try:
110 i = opts.index(private_opt)
8450c15c 111 opts[i + 1] = 'PRIVATE'
34a741a8
PH
112 except ValueError:
113 pass
114 return opts
115
34a741a8 116 # No need to wrap help messages if we're on a wide console
003c69a8 117 columns = compat_get_terminal_size().columns
8450c15c
PH
118 max_width = columns if columns else 80
119 max_help_position = 80
34a741a8
PH
120
121 fmt = optparse.IndentedHelpFormatter(width=max_width, max_help_position=max_help_position)
122 fmt.format_option_strings = _format_option_string
123
124 kw = {
8450c15c
PH
125 'version': __version__,
126 'formatter': fmt,
a42419da 127 'usage': '%prog [OPTIONS] URL [URL...]',
8450c15c 128 'conflict_handler': 'resolve',
34a741a8
PH
129 }
130
c7b0add8 131 parser = optparse.OptionParser(**compat_kwargs(kw))
34a741a8 132
8450c15c
PH
133 general = optparse.OptionGroup(parser, 'General Options')
134 general.add_option(
135 '-h', '--help',
136 action='help',
17941321 137 help='Print this help text and exit')
8450c15c
PH
138 general.add_option(
139 '-v', '--version',
140 action='version',
17941321 141 help='Print program version and exit')
8450c15c
PH
142 general.add_option(
143 '-U', '--update',
144 action='store_true', dest='update_self',
17941321 145 help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
8450c15c
PH
146 general.add_option(
147 '-i', '--ignore-errors',
148 action='store_true', dest='ignoreerrors', default=False,
17941321 149 help='Continue on download errors, for example to skip unavailable videos in a playlist')
8450c15c
PH
150 general.add_option(
151 '--abort-on-error',
152 action='store_false', dest='ignoreerrors',
153 help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
154 general.add_option(
155 '--dump-user-agent',
156 action='store_true', dest='dump_user_agent', default=False,
17941321 157 help='Display the current browser identification')
34a741a8 158 general.add_option(
8450c15c
PH
159 '--list-extractors',
160 action='store_true', dest='list_extractors', default=False,
9836cfb8 161 help='List all supported extractors')
8450c15c
PH
162 general.add_option(
163 '--extractor-descriptions',
164 action='store_true', dest='list_extractor_descriptions', default=False,
165 help='Output descriptions of all supported extractors')
d22dec74
S
166 general.add_option(
167 '--force-generic-extractor',
168 action='store_true', dest='force_generic_extractor', default=False,
169 help='Force extraction to use the generic extractor')
34a741a8
PH
170 general.add_option(
171 '--default-search',
172 dest='default_search', metavar='PREFIX',
17941321 173 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
PH
174 general.add_option(
175 '--ignore-config',
176 action='store_true',
d4e06d4a
PH
177 help='Do not read configuration files. '
178 'When given in the global configuration file /etc/youtube-dl.conf: '
179 'Do not read the user configuration in ~/.config/youtube-dl/config '
180 '(%APPDATA%/youtube-dl/config.txt on Windows)')
057a5206
PH
181 general.add_option(
182 '--flat-playlist',
183 action='store_const', dest='extract_flat', const='in_playlist',
184 default=False,
185 help='Do not extract the videos of a playlist, only list them.')
d77ab8e2
S
186 general.add_option(
187 '--mark-watched',
188 action='store_true', dest='mark_watched', default=False,
189 help='Mark videos watched (YouTube only)')
90f794c6
S
190 general.add_option(
191 '--no-mark-watched',
192 action='store_false', dest='mark_watched', default=False,
193 help='Do not mark videos watched (YouTube only)')
7e5db8c9
PH
194 general.add_option(
195 '--no-color', '--no-colors',
196 action='store_true', dest='no_color',
197 default=False,
17941321 198 help='Do not emit color codes in output')
34a741a8 199
be4a824d
PH
200 network = optparse.OptionGroup(parser, 'Network Options')
201 network.add_option(
202 '--proxy', dest='proxy',
203 default=None, metavar='URL',
6ddb4888
YCH
204 help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental '
205 'SOCKS proxy, specify a proper scheme. For example '
206 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
207 'for direct connection')
be4a824d
PH
208 network.add_option(
209 '--socket-timeout',
210 dest='socket_timeout', type=float, default=None, metavar='SECONDS',
211 help='Time to wait before giving up, in seconds')
212 network.add_option(
213 '--source-address',
214 metavar='IP', dest='source_address', default=None,
215 help='Client-side IP address to bind to (experimental)',
216 )
500b8b41
PH
217 network.add_option(
218 '-4', '--force-ipv4',
219 action='store_const', const='0.0.0.0', dest='source_address',
220 help='Make all connections via IPv4 (experimental)',
221 )
222 network.add_option(
223 '-6', '--force-ipv6',
224 action='store_const', const='::', dest='source_address',
225 help='Make all connections via IPv6 (experimental)',
226 )
38cce791
YCH
227 network.add_option(
228 '--geo-verification-proxy',
229 dest='geo_verification_proxy', default=None, metavar='URL',
230 help='Use this proxy to verify the IP address for some geo-restricted sites. '
231 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)'
232 )
91410c9b
PH
233 network.add_option(
234 '--cn-verification-proxy',
235 dest='cn_verification_proxy', default=None, metavar='URL',
38cce791 236 help=optparse.SUPPRESS_HELP,
91410c9b 237 )
be4a824d 238
8450c15c 239 selection = optparse.OptionGroup(parser, 'Video Selection')
34a741a8
PH
240 selection.add_option(
241 '--playlist-start',
242 dest='playliststart', metavar='NUMBER', default=1, type=int,
17941321 243 help='Playlist video to start at (default is %default)')
34a741a8
PH
244 selection.add_option(
245 '--playlist-end',
246 dest='playlistend', metavar='NUMBER', default=None, type=int,
17941321 247 help='Playlist video to end at (default is last)')
c14e88f0
PH
248 selection.add_option(
249 '--playlist-items',
250 dest='playlist_items', metavar='ITEM_SPEC', default=None,
4eb59a6b 251 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 252 selection.add_option(
8450c15c
PH
253 '--match-title',
254 dest='matchtitle', metavar='REGEX',
17941321 255 help='Download only matching titles (regex or caseless sub-string)')
8450c15c
PH
256 selection.add_option(
257 '--reject-title',
258 dest='rejecttitle', metavar='REGEX',
17941321 259 help='Skip download for matching titles (regex or caseless sub-string)')
8450c15c
PH
260 selection.add_option(
261 '--max-downloads',
262 dest='max_downloads', metavar='NUMBER', type=int, default=None,
263 help='Abort after downloading NUMBER files')
264 selection.add_option(
265 '--min-filesize',
266 metavar='SIZE', dest='min_filesize', default=None,
267 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
268 selection.add_option(
269 '--max-filesize',
270 metavar='SIZE', dest='max_filesize', default=None,
271 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
272 selection.add_option(
273 '--date',
274 metavar='DATE', dest='date', default=None,
17941321 275 help='Download only videos uploaded in this date')
8450c15c
PH
276 selection.add_option(
277 '--datebefore',
278 metavar='DATE', dest='datebefore', default=None,
17941321 279 help='Download only videos uploaded on or before this date (i.e. inclusive)')
34a741a8 280 selection.add_option(
8450c15c
PH
281 '--dateafter',
282 metavar='DATE', dest='dateafter', default=None,
17941321 283 help='Download only videos uploaded on or after this date (i.e. inclusive)')
34a741a8 284 selection.add_option(
8450c15c
PH
285 '--min-views',
286 metavar='COUNT', dest='min_views', default=None, type=int,
17941321 287 help='Do not download any videos with less than COUNT views')
34a741a8 288 selection.add_option(
8450c15c
PH
289 '--max-views',
290 metavar='COUNT', dest='max_views', default=None, type=int,
291 help='Do not download any videos with more than COUNT views')
347de493
PH
292 selection.add_option(
293 '--match-filter',
294 metavar='FILTER', dest='match_filter', default=None,
295 help=(
17941321 296 'Generic video filter (experimental). '
347de493
PH
297 'Specify any key (see help for -o for a list of available keys) to'
298 ' match if the key is present, '
299 '!key to check if the key is not present,'
300 'key > NUMBER (like "comment_count > 12", also works with '
301 '>=, <, <=, !=, =) to compare against a number, and '
302 '& to require multiple matches. '
303 'Values which are not known are excluded unless you'
304 ' put a question mark (?) after the operator.'
305 'For example, to only match videos that have been liked more than '
306 '100 times and disliked less than 50 times (or the dislike '
307 'functionality is not available at the given service), but who '
5495937f 308 'also have a description, use --match-filter '
347de493
PH
309 '"like_count > 100 & dislike_count <? 50 & description" .'
310 ))
34a741a8 311 selection.add_option(
8450c15c
PH
312 '--no-playlist',
313 action='store_true', dest='noplaylist', default=False,
17941321 314 help='Download only the video, if the URL refers to a video and a playlist.')
df4bd0d5
PH
315 selection.add_option(
316 '--yes-playlist',
317 action='store_false', dest='noplaylist', default=False,
17941321 318 help='Download the playlist, if the URL refers to a video and a playlist.')
8450c15c
PH
319 selection.add_option(
320 '--age-limit',
321 metavar='YEARS', dest='age_limit', default=None, type=int,
17941321 322 help='Download only videos suitable for the given age')
8450c15c
PH
323 selection.add_option(
324 '--download-archive', metavar='FILE',
325 dest='download_archive',
326 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
327 selection.add_option(
328 '--include-ads',
329 dest='include_ads', action='store_true',
34a741a8 330 help='Download advertisements as well (experimental)')
34a741a8 331
8450c15c
PH
332 authentication = optparse.OptionGroup(parser, 'Authentication Options')
333 authentication.add_option(
334 '-u', '--username',
335 dest='username', metavar='USERNAME',
17941321 336 help='Login with this account ID')
8450c15c
PH
337 authentication.add_option(
338 '-p', '--password',
339 dest='password', metavar='PASSWORD',
17941321 340 help='Account password. If this option is left out, youtube-dl will ask interactively.')
8450c15c
PH
341 authentication.add_option(
342 '-2', '--twofactor',
343 dest='twofactor', metavar='TWOFACTOR',
17941321 344 help='Two-factor auth code')
8450c15c
PH
345 authentication.add_option(
346 '-n', '--netrc',
347 action='store_true', dest='usenetrc', default=False,
17941321 348 help='Use .netrc authentication data')
8450c15c
PH
349 authentication.add_option(
350 '--video-password',
351 dest='videopassword', metavar='PASSWORD',
804c343a 352 help='Video password (vimeo, smotri, youku)')
8450c15c
PH
353
354 video_format = optparse.OptionGroup(parser, 'Video Format Options')
355 video_format.add_option(
356 '-f', '--format',
357 action='store', dest='format', metavar='FORMAT', default=None,
a3805092 358 help='Video format code, see the "FORMAT SELECTION" for all the info')
8450c15c
PH
359 video_format.add_option(
360 '--all-formats',
361 action='store_const', dest='format', const='all',
17941321 362 help='Download all available video formats')
8450c15c
PH
363 video_format.add_option(
364 '--prefer-free-formats',
365 action='store_true', dest='prefer_free_formats', default=False,
17941321 366 help='Prefer free video formats unless a specific one is requested')
8450c15c
PH
367 video_format.add_option(
368 '-F', '--list-formats',
369 action='store_true', dest='listformats',
4b3fbafd 370 help='List all available formats of requested videos')
203fb43f
PH
371 video_format.add_option(
372 '--youtube-include-dash-manifest',
373 action='store_true', dest='youtube_include_dash_manifest', default=True,
374 help=optparse.SUPPRESS_HELP)
375 video_format.add_option(
376 '--youtube-skip-dash-manifest',
377 action='store_false', dest='youtube_include_dash_manifest',
b2575b38 378 help='Do not download the DASH manifests and related data on YouTube videos')
d120e901 379 video_format.add_option(
bd1a281e
PH
380 '--merge-output-format',
381 action='store', dest='merge_output_format', metavar='FORMAT', default=None,
d120e901 382 help=(
00334d0d
S
383 'If a merge is required (e.g. bestvideo+bestaudio), '
384 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
d120e901 385 'Ignored if no merge is required'))
8450c15c
PH
386
387 subtitles = optparse.OptionGroup(parser, 'Subtitle Options')
388 subtitles.add_option(
389 '--write-sub', '--write-srt',
390 action='store_true', dest='writesubtitles', default=False,
17941321 391 help='Write subtitle file')
8450c15c
PH
392 subtitles.add_option(
393 '--write-auto-sub', '--write-automatic-sub',
394 action='store_true', dest='writeautomaticsub', default=False,
741dd8ea 395 help='Write automatically generated subtitle file (YouTube only)')
8450c15c
PH
396 subtitles.add_option(
397 '--all-subs',
398 action='store_true', dest='allsubtitles', default=False,
17941321 399 help='Download all the available subtitles of the video')
8450c15c
PH
400 subtitles.add_option(
401 '--list-subs',
402 action='store_true', dest='listsubtitles', default=False,
17941321 403 help='List all available subtitles for the video')
8450c15c
PH
404 subtitles.add_option(
405 '--sub-format',
a504ced0 406 action='store', dest='subtitlesformat', metavar='FORMAT', default='best',
4a3cdf81 407 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
8450c15c
PH
408 subtitles.add_option(
409 '--sub-lang', '--sub-langs', '--srt-lang',
410 action='callback', dest='subtitleslangs', metavar='LANGS', type='str',
411 default=[], callback=_comma_separated_values_options_callback,
1ca59dac 412 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
8450c15c
PH
413
414 downloader = optparse.OptionGroup(parser, 'Download Options')
415 downloader.add_option(
8ec2b2c4
S
416 '-r', '--limit-rate', '--rate-limit',
417 dest='ratelimit', metavar='RATE',
17941321 418 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
8450c15c
PH
419 downloader.add_option(
420 '-R', '--retries',
421 dest='retries', metavar='RETRIES', default=10,
17941321 422 help='Number of retries (default is %default), or "infinite".')
52bb437e
S
423 downloader.add_option(
424 '--fragment-retries',
425 dest='fragment_retries', metavar='RETRIES', default=10,
426 help='Number of retries for a fragment (default is %default), or "infinite" (DASH only)')
8450c15c
PH
427 downloader.add_option(
428 '--buffer-size',
429 dest='buffersize', metavar='SIZE', default='1024',
17941321 430 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
8450c15c
PH
431 downloader.add_option(
432 '--no-resize-buffer',
433 action='store_true', dest='noresizebuffer', default=False,
17941321 434 help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
8450c15c
PH
435 downloader.add_option(
436 '--test',
437 action='store_true', dest='test', default=False,
438 help=optparse.SUPPRESS_HELP)
ff815fe6
MS
439 downloader.add_option(
440 '--playlist-reverse',
441 action='store_true',
442 help='Download playlist videos in reverse order')
881e6a1f
PH
443 downloader.add_option(
444 '--xattr-set-filesize',
445 dest='xattr_set_filesize', action='store_true',
17941321 446 help='Set file xattribute ytdl.filesize with expected filesize (experimental)')
85729c51
PH
447 downloader.add_option(
448 '--hls-prefer-native',
bf09af3a 449 dest='hls_prefer_native', action='store_true', default=None,
870d5258 450 help='Use the native HLS downloader instead of ffmpeg')
bf09af3a
S
451 downloader.add_option(
452 '--hls-prefer-ffmpeg',
453 dest='hls_prefer_native', action='store_false', default=None,
454 help='Use ffmpeg instead of the native HLS downloader')
7d106a65
JMF
455 downloader.add_option(
456 '--hls-use-mpegts',
457 dest='hls_use_mpegts', action='store_true',
458 help='Use the mpegts container for HLS videos, allowing to play the '
53be8894 459 'video while downloading (some players may not be able to play it)')
222516d9
PH
460 downloader.add_option(
461 '--external-downloader',
462 dest='external_downloader', metavar='COMMAND',
c75f0b36 463 help='Use the specified external downloader. '
222516d9 464 'Currently supports %s' % ','.join(list_external_downloaders()))
c75f0b36
PH
465 downloader.add_option(
466 '--external-downloader-args',
467 dest='external_downloader_args', metavar='ARGS',
17941321 468 help='Give these arguments to the external downloader')
8450c15c
PH
469
470 workarounds = optparse.OptionGroup(parser, 'Workarounds')
34a741a8 471 workarounds.add_option(
8450c15c
PH
472 '--encoding',
473 dest='encoding', metavar='ENCODING',
34a741a8
PH
474 help='Force the specified encoding (experimental)')
475 workarounds.add_option(
8450c15c
PH
476 '--no-check-certificate',
477 action='store_true', dest='no_check_certificate', default=False,
17941321 478 help='Suppress HTTPS certificate validation')
34a741a8 479 workarounds.add_option(
8450c15c
PH
480 '--prefer-insecure',
481 '--prefer-unsecure', action='store_true', dest='prefer_insecure',
34a741a8
PH
482 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
483 workarounds.add_option(
8450c15c
PH
484 '--user-agent',
485 metavar='UA', dest='user_agent',
17941321 486 help='Specify a custom user agent')
34a741a8 487 workarounds.add_option(
8450c15c
PH
488 '--referer',
489 metavar='URL', dest='referer', default=None,
17941321 490 help='Specify a custom referer, use if the video access is restricted to one domain',
34a741a8
PH
491 )
492 workarounds.add_option(
8450c15c
PH
493 '--add-header',
494 metavar='FIELD:VALUE', dest='headers', action='append',
17941321 495 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
34a741a8
PH
496 )
497 workarounds.add_option(
8450c15c
PH
498 '--bidi-workaround',
499 dest='bidi_workaround', action='store_true',
500 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
5f0d813d
PH
501 workarounds.add_option(
502 '--sleep-interval', metavar='SECONDS',
649f7966 503 dest='sleep_interval', type=float,
5f0d813d 504 help='Number of seconds to sleep before each download.')
34a741a8 505
8450c15c
PH
506 verbosity = optparse.OptionGroup(parser, 'Verbosity / Simulation Options')
507 verbosity.add_option(
508 '-q', '--quiet',
509 action='store_true', dest='quiet', default=False,
17941321 510 help='Activate quiet mode')
34a741a8
PH
511 verbosity.add_option(
512 '--no-warnings',
513 dest='no_warnings', action='store_true', default=False,
514 help='Ignore warnings')
8450c15c
PH
515 verbosity.add_option(
516 '-s', '--simulate',
517 action='store_true', dest='simulate', default=False,
17941321 518 help='Do not download the video and do not write anything to disk')
8450c15c
PH
519 verbosity.add_option(
520 '--skip-download',
521 action='store_true', dest='skip_download', default=False,
17941321 522 help='Do not download the video')
8450c15c
PH
523 verbosity.add_option(
524 '-g', '--get-url',
525 action='store_true', dest='geturl', default=False,
17941321 526 help='Simulate, quiet but print URL')
8450c15c
PH
527 verbosity.add_option(
528 '-e', '--get-title',
529 action='store_true', dest='gettitle', default=False,
17941321 530 help='Simulate, quiet but print title')
8450c15c
PH
531 verbosity.add_option(
532 '--get-id',
533 action='store_true', dest='getid', default=False,
17941321 534 help='Simulate, quiet but print id')
8450c15c
PH
535 verbosity.add_option(
536 '--get-thumbnail',
537 action='store_true', dest='getthumbnail', default=False,
17941321 538 help='Simulate, quiet but print thumbnail URL')
8450c15c
PH
539 verbosity.add_option(
540 '--get-description',
541 action='store_true', dest='getdescription', default=False,
17941321 542 help='Simulate, quiet but print video description')
8450c15c
PH
543 verbosity.add_option(
544 '--get-duration',
545 action='store_true', dest='getduration', default=False,
17941321 546 help='Simulate, quiet but print video length')
8450c15c
PH
547 verbosity.add_option(
548 '--get-filename',
549 action='store_true', dest='getfilename', default=False,
17941321 550 help='Simulate, quiet but print output filename')
8450c15c
PH
551 verbosity.add_option(
552 '--get-format',
553 action='store_true', dest='getformat', default=False,
17941321 554 help='Simulate, quiet but print output format')
8450c15c
PH
555 verbosity.add_option(
556 '-j', '--dump-json',
557 action='store_true', dest='dumpjson', default=False,
17941321 558 help='Simulate, quiet but print JSON information. See --output for a description of available keys.')
63e0be34
PH
559 verbosity.add_option(
560 '-J', '--dump-single-json',
561 action='store_true', dest='dump_single_json', default=False,
17941321 562 help='Simulate, quiet but print JSON information for each command-line argument. If the URL refers to a playlist, dump the whole playlist information in a single line.')
c0bdf32a
PH
563 verbosity.add_option(
564 '--print-json',
565 action='store_true', dest='print_json', default=False,
566 help='Be quiet and print the video information as JSON (video is still being downloaded).',
567 )
8450c15c
PH
568 verbosity.add_option(
569 '--newline',
570 action='store_true', dest='progress_with_newline', default=False,
17941321 571 help='Output progress bar as new lines')
8450c15c
PH
572 verbosity.add_option(
573 '--no-progress',
574 action='store_true', dest='noprogress', default=False,
17941321 575 help='Do not print progress bar')
8450c15c
PH
576 verbosity.add_option(
577 '--console-title',
578 action='store_true', dest='consoletitle', default=False,
17941321 579 help='Display progress in console titlebar')
8450c15c
PH
580 verbosity.add_option(
581 '-v', '--verbose',
582 action='store_true', dest='verbose', default=False,
17941321 583 help='Print various debugging information')
8450c15c 584 verbosity.add_option(
8bba753c 585 '--dump-pages', '--dump-intermediate-pages',
8450c15c 586 action='store_true', dest='dump_intermediate_pages', default=False,
79979c68 587 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
8450c15c
PH
588 verbosity.add_option(
589 '--write-pages',
590 action='store_true', dest='write_pages', default=False,
591 help='Write downloaded intermediary pages to files in the current directory to debug problems')
592 verbosity.add_option(
593 '--youtube-print-sig-code',
594 action='store_true', dest='youtube_print_sig_code', default=False,
595 help=optparse.SUPPRESS_HELP)
596 verbosity.add_option(
2f543a21 597 '--print-traffic', '--dump-headers',
8450c15c
PH
598 dest='debug_printtraffic', action='store_true', default=False,
599 help='Display sent and read HTTP traffic')
58b1f00d
PH
600 verbosity.add_option(
601 '-C', '--call-home',
602 dest='call_home', action='store_true', default=False,
17941321 603 help='Contact the youtube-dl server for debugging')
8bfa7545
PH
604 verbosity.add_option(
605 '--no-call-home',
606 dest='call_home', action='store_false', default=False,
17941321 607 help='Do NOT contact the youtube-dl server for debugging')
8450c15c
PH
608
609 filesystem = optparse.OptionGroup(parser, 'Filesystem Options')
610 filesystem.add_option(
611 '-a', '--batch-file',
612 dest='batchfile', metavar='FILE',
17941321 613 help='File containing URLs to download (\'-\' for stdin)')
8450c15c
PH
614 filesystem.add_option(
615 '--id', default=False,
17941321 616 action='store_true', dest='useid', help='Use only video ID in file name')
8450c15c
PH
617 filesystem.add_option(
618 '-o', '--output',
619 dest='outtmpl', metavar='TEMPLATE',
17941321 620 help=('Output filename template. Use %(title)s to get the title, '
8450c15c
PH
621 '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
622 '%(autonumber)s to get an automatically incremented number, '
623 '%(ext)s for the filename extension, '
624 '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
17941321 625 '%(format_id)s for the unique id of the format (like YouTube\'s itags: "137"), '
8450c15c 626 '%(upload_date)s for the upload date (YYYYMMDD), '
f0185581 627 '%(extractor)s for the provider (youtube, metacafe, etc), '
a1cf99d0
PH
628 '%(id)s for the video id, '
629 '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
630 '%(playlist_index)s for the position in the playlist. '
8450c15c
PH
631 '%(height)s and %(width)s for the width and height of the video format. '
632 '%(resolution)s for a textual description of the resolution of the video format. '
a1cf99d0 633 '%% for a literal percent. '
8450c15c
PH
634 'Use - to output to stdout. Can also be used to download to a different directory, '
635 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
636 filesystem.add_option(
637 '--autonumber-size',
638 dest='autonumber_size', metavar='NUMBER',
17941321 639 help='Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
8450c15c
PH
640 filesystem.add_option(
641 '--restrict-filenames',
642 action='store_true', dest='restrictfilenames', default=False,
643 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
2865cf04
PH
644 filesystem.add_option(
645 '-A', '--auto-number',
646 action='store_true', dest='autonumber', default=False,
5495937f 647 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] Number downloaded files starting from 00000')
8450c15c
PH
648 filesystem.add_option(
649 '-t', '--title',
650 action='store_true', dest='usetitle', default=False,
17941321 651 help='[deprecated] Use title in file name (default)')
8450c15c
PH
652 filesystem.add_option(
653 '-l', '--literal', default=False,
654 action='store_true', dest='usetitle',
17941321 655 help='[deprecated] Alias of --title')
8450c15c
PH
656 filesystem.add_option(
657 '-w', '--no-overwrites',
658 action='store_true', dest='nooverwrites', default=False,
17941321 659 help='Do not overwrite files')
8450c15c
PH
660 filesystem.add_option(
661 '-c', '--continue',
662 action='store_true', dest='continue_dl', default=True,
17941321 663 help='Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
8450c15c
PH
664 filesystem.add_option(
665 '--no-continue',
666 action='store_false', dest='continue_dl',
17941321 667 help='Do not resume partially downloaded files (restart from beginning)')
8450c15c
PH
668 filesystem.add_option(
669 '--no-part',
670 action='store_true', dest='nopart', default=False,
17941321 671 help='Do not use .part files - write directly into output file')
8450c15c
PH
672 filesystem.add_option(
673 '--no-mtime',
674 action='store_false', dest='updatetime', default=True,
17941321 675 help='Do not use the Last-modified header to set the file modification time')
8450c15c
PH
676 filesystem.add_option(
677 '--write-description',
678 action='store_true', dest='writedescription', default=False,
17941321 679 help='Write video description to a .description file')
8450c15c
PH
680 filesystem.add_option(
681 '--write-info-json',
682 action='store_true', dest='writeinfojson', default=False,
17941321 683 help='Write video metadata to a .info.json file')
8450c15c
PH
684 filesystem.add_option(
685 '--write-annotations',
686 action='store_true', dest='writeannotations', default=False,
0669c89c 687 help='Write video annotations to a .annotations.xml file')
8450c15c 688 filesystem.add_option(
244fe977 689 '--load-info-json', '--load-info',
8450c15c 690 dest='load_info_filename', metavar='FILE',
1a48181a 691 help='JSON file containing the video information (created with the "--write-info-json" option)')
8450c15c
PH
692 filesystem.add_option(
693 '--cookies',
694 dest='cookiefile', metavar='FILE',
17941321 695 help='File to read cookies from and dump cookie jar in')
34a741a8
PH
696 filesystem.add_option(
697 '--cache-dir', dest='cachedir', default=None, metavar='DIR',
698 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.')
699 filesystem.add_option(
700 '--no-cache-dir', action='store_const', const=False, dest='cachedir',
701 help='Disable filesystem caching')
702 filesystem.add_option(
8450c15c
PH
703 '--rm-cache-dir',
704 action='store_true', dest='rm_cachedir',
34a741a8
PH
705 help='Delete all filesystem cache files')
706
cfb56d1a
PH
707 thumbnail = optparse.OptionGroup(parser, 'Thumbnail images')
708 thumbnail.add_option(
709 '--write-thumbnail',
710 action='store_true', dest='writethumbnail', default=False,
17941321 711 help='Write thumbnail image to disk')
ec82d85a
PH
712 thumbnail.add_option(
713 '--write-all-thumbnails',
714 action='store_true', dest='write_all_thumbnails', default=False,
17941321 715 help='Write all thumbnail image formats to disk')
cfb56d1a
PH
716 thumbnail.add_option(
717 '--list-thumbnails',
718 action='store_true', dest='list_thumbnails', default=False,
719 help='Simulate and list all available thumbnail formats')
720
8450c15c
PH
721 postproc = optparse.OptionGroup(parser, 'Post-processing Options')
722 postproc.add_option(
723 '-x', '--extract-audio',
724 action='store_true', dest='extractaudio', default=False,
17941321 725 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
8450c15c
PH
726 postproc.add_option(
727 '--audio-format', metavar='FORMAT', dest='audioformat', default='best',
17941321 728 help='Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
8450c15c
PH
729 postproc.add_option(
730 '--audio-quality', metavar='QUALITY',
731 dest='audioquality', default='5',
17941321 732 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)')
8450c15c
PH
733 postproc.add_option(
734 '--recode-video',
735 metavar='FORMAT', dest='recodevideo', default=None,
f72b0a60 736 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
d84f1d14 737 postproc.add_option(
1866432d 738 '--postprocessor-args',
f72b0a60
S
739 dest='postprocessor_args', metavar='ARGS',
740 help='Give these arguments to the postprocessor')
8450c15c
PH
741 postproc.add_option(
742 '-k', '--keep-video',
743 action='store_true', dest='keepvideo', default=False,
17941321 744 help='Keep the video file on disk after the post-processing; the video is erased by default')
8450c15c
PH
745 postproc.add_option(
746 '--no-post-overwrites',
747 action='store_true', dest='nopostoverwrites', default=False,
17941321 748 help='Do not overwrite post-processed files; the post-processed files are overwritten by default')
8450c15c
PH
749 postproc.add_option(
750 '--embed-subs',
751 action='store_true', dest='embedsubtitles', default=False,
40025ee2 752 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
8450c15c
PH
753 postproc.add_option(
754 '--embed-thumbnail',
755 action='store_true', dest='embedthumbnail', default=False,
17941321 756 help='Embed thumbnail in the audio as cover art')
8450c15c
PH
757 postproc.add_option(
758 '--add-metadata',
759 action='store_true', dest='addmetadata', default=False,
17941321 760 help='Write metadata to the video file')
e7db87f7 761 postproc.add_option(
762 '--metadata-from-title',
763 metavar='FORMAT', dest='metafromtitle',
17941321 764 help='Parse additional metadata like song title / artist from the video title. '
e7db87f7 765 'The format syntax is the same as --output, '
88cf6fb3 766 'the parsed parameters replace existing values. '
663004ac 767 'Additional templates: %(album)s, %(artist)s. '
e7db87f7 768 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
769 '"Coldplay - Paradise"')
8450c15c
PH
770 postproc.add_option(
771 '--xattrs',
772 action='store_true', dest='xattrs', default=False,
17941321 773 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
6271f1ca
PH
774 postproc.add_option(
775 '--fixup',
776 metavar='POLICY', dest='fixup', default='detect_or_warn',
9fffd046 777 help='Automatically correct known faults of the file. '
6271f1ca 778 'One of never (do nothing), warn (only emit a warning), '
5774ef35 779 'detect_or_warn (the default; fix file if we can, warn otherwise)')
8450c15c
PH
780 postproc.add_option(
781 '--prefer-avconv',
782 action='store_false', dest='prefer_ffmpeg',
34a741a8 783 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
8450c15c
PH
784 postproc.add_option(
785 '--prefer-ffmpeg',
786 action='store_true', dest='prefer_ffmpeg',
34a741a8 787 help='Prefer ffmpeg over avconv for running the postprocessors')
73fac4e9
PH
788 postproc.add_option(
789 '--ffmpeg-location', '--avconv-location', metavar='PATH',
790 dest='ffmpeg_location',
791 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
34a741a8 792 postproc.add_option(
8450c15c
PH
793 '--exec',
794 metavar='CMD', dest='exec_cmd',
5f6a1245 795 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
e9fade72 796 postproc.add_option(
f5bc4b5f 797 '--convert-subs', '--convert-subtitles',
e9fade72
JMF
798 metavar='FORMAT', dest='convertsubtitles', default=None,
799 help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
34a741a8
PH
800
801 parser.add_option_group(general)
be4a824d 802 parser.add_option_group(network)
34a741a8
PH
803 parser.add_option_group(selection)
804 parser.add_option_group(downloader)
805 parser.add_option_group(filesystem)
cfb56d1a 806 parser.add_option_group(thumbnail)
34a741a8
PH
807 parser.add_option_group(verbosity)
808 parser.add_option_group(workarounds)
809 parser.add_option_group(video_format)
810 parser.add_option_group(subtitles)
811 parser.add_option_group(authentication)
812 parser.add_option_group(postproc)
813
814 if overrideArguments is not None:
815 opts, args = parser.parse_args(overrideArguments)
816 if opts.verbose:
8450c15c 817 write_string('[debug] Override config: ' + repr(overrideArguments) + '\n')
34a741a8 818 else:
b04b94da
S
819 def compat_conf(conf):
820 if sys.version_info < (3,):
821 return [a.decode(preferredencoding(), 'replace') for a in conf]
822 return conf
823
824 command_line_conf = compat_conf(sys.argv[1:])
f5e2efbb 825
c06a9fa3
PH
826 if '--ignore-config' in command_line_conf:
827 system_conf = []
828 user_conf = []
34a741a8 829 else:
30d22dae 830 system_conf = _readOptions('/etc/youtube-dl.conf')
c06a9fa3
PH
831 if '--ignore-config' in system_conf:
832 user_conf = []
34a741a8 833 else:
30d22dae 834 user_conf = _readUserConf()
c06a9fa3 835 argv = system_conf + user_conf + command_line_conf
34a741a8
PH
836
837 opts, args = parser.parse_args(argv)
838 if opts.verbose:
c06a9fa3
PH
839 write_string('[debug] System config: ' + repr(_hide_login_info(system_conf)) + '\n')
840 write_string('[debug] User config: ' + repr(_hide_login_info(user_conf)) + '\n')
841 write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf)) + '\n')
34a741a8
PH
842
843 return parser, opts, args