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