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