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