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