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