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