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