1 from __future__
import unicode_literals
8 from .downloader
.external
import list_external_downloaders
18 from .version
import __version__
21 def parseOpts(overrideArguments
=None):
22 def _readOptions(filename_bytes
, default
=[]):
24 optionf
= open(filename_bytes
)
26 return default
# silently skip if file is not present
30 res
+= shlex
.split(l
, comments
=True)
36 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME')
38 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl', 'config')
39 if not os
.path
.isfile(userConfFile
):
40 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl.conf')
42 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl', 'config')
43 if not os
.path
.isfile(userConfFile
):
44 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl.conf')
45 userConf
= _readOptions(userConfFile
, None)
48 appdata_dir
= compat_getenv('appdata')
50 userConf
= _readOptions(
51 os
.path
.join(appdata_dir
, 'youtube-dl', 'config'),
54 userConf
= _readOptions(
55 os
.path
.join(appdata_dir
, 'youtube-dl', 'config.txt'),
59 userConf
= _readOptions(
60 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf'),
63 userConf
= _readOptions(
64 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf.txt'),
72 def _format_option_string(option
):
73 ''' ('-o', '--option') -> -o, --format METAVAR'''
77 if option
._short
_opts
:
78 opts
.append(option
._short
_opts
[0])
80 opts
.append(option
._long
_opts
[0])
84 if option
.takes_value():
85 opts
.append(' %s' % option
.metavar
)
89 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
90 setattr(parser
.values
, option
.dest
, value
.split(','))
92 def _hide_login_info(opts
):
94 for private_opt
in ['-p', '--password', '-u', '--username', '--video-password']:
96 i
= opts
.index(private_opt
)
97 opts
[i
+ 1] = 'PRIVATE'
102 # No need to wrap help messages if we're on a wide console
103 columns
= get_term_width()
104 max_width
= columns
if columns
else 80
105 max_help_position
= 80
107 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
108 fmt
.format_option_strings
= _format_option_string
111 'version': __version__
,
113 'usage': '%prog [OPTIONS] URL [URL...]',
114 'conflict_handler': 'resolve',
117 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
119 general
= optparse
.OptionGroup(parser
, 'General Options')
123 help='print this help text and exit')
127 help='print program version and exit')
130 action
='store_true', dest
='update_self',
131 help='update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
133 '-i', '--ignore-errors',
134 action
='store_true', dest
='ignoreerrors', default
=False,
135 help='continue on download errors, for example to skip unavailable videos in a playlist')
138 action
='store_false', dest
='ignoreerrors',
139 help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
142 action
='store_true', dest
='dump_user_agent', default
=False,
143 help='display the current browser identification')
146 action
='store_true', dest
='list_extractors', default
=False,
147 help='List all supported extractors and the URLs they would handle')
149 '--extractor-descriptions',
150 action
='store_true', dest
='list_extractor_descriptions', default
=False,
151 help='Output descriptions of all supported extractors')
154 dest
='default_search', metavar
='PREFIX',
155 help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dl "large apple". Use the value "auto" to let youtube-dl guess ("auto_warning" to emit a warning when guessing). "error" just throws an error. The default value "fixup_error" repairs broken URLs, but emits an error if this is not possible instead of searching.')
159 help='Do not read configuration files. '
160 'When given in the global configuration file /etc/youtube-dl.conf: '
161 'Do not read the user configuration in ~/.config/youtube-dl/config '
162 '(%APPDATA%/youtube-dl/config.txt on Windows)')
165 action
='store_const', dest
='extract_flat', const
='in_playlist',
167 help='Do not extract the videos of a playlist, only list them.')
169 '--no-color', '--no-colors',
170 action
='store_true', dest
='no_color',
172 help='Do not emit color codes in output.')
174 network
= optparse
.OptionGroup(parser
, 'Network Options')
176 '--proxy', dest
='proxy',
177 default
=None, metavar
='URL',
178 help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
181 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
182 help='Time to wait before giving up, in seconds')
185 metavar
='IP', dest
='source_address', default
=None,
186 help='Client-side IP address to bind to (experimental)',
189 '-4', '--force-ipv4',
190 action
='store_const', const
='0.0.0.0', dest
='source_address',
191 help='Make all connections via IPv4 (experimental)',
194 '-6', '--force-ipv6',
195 action
='store_const', const
='::', dest
='source_address',
196 help='Make all connections via IPv6 (experimental)',
199 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
200 selection
.add_option(
202 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
203 help='playlist video to start at (default is %default)')
204 selection
.add_option(
206 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
207 help='playlist video to end at (default is last)')
208 selection
.add_option(
210 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
211 help='playlist video items to download. Specify indices of the videos in the playlist seperated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.')
212 selection
.add_option(
214 dest
='matchtitle', metavar
='REGEX',
215 help='download only matching titles (regex or caseless sub-string)')
216 selection
.add_option(
218 dest
='rejecttitle', metavar
='REGEX',
219 help='skip download for matching titles (regex or caseless sub-string)')
220 selection
.add_option(
222 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
223 help='Abort after downloading NUMBER files')
224 selection
.add_option(
226 metavar
='SIZE', dest
='min_filesize', default
=None,
227 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
228 selection
.add_option(
230 metavar
='SIZE', dest
='max_filesize', default
=None,
231 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
232 selection
.add_option(
234 metavar
='DATE', dest
='date', default
=None,
235 help='download only videos uploaded in this date')
236 selection
.add_option(
238 metavar
='DATE', dest
='datebefore', default
=None,
239 help='download only videos uploaded on or before this date (i.e. inclusive)')
240 selection
.add_option(
242 metavar
='DATE', dest
='dateafter', default
=None,
243 help='download only videos uploaded on or after this date (i.e. inclusive)')
244 selection
.add_option(
246 metavar
='COUNT', dest
='min_views', default
=None, type=int,
247 help='Do not download any videos with less than COUNT views',)
248 selection
.add_option(
250 metavar
='COUNT', dest
='max_views', default
=None, type=int,
251 help='Do not download any videos with more than COUNT views')
252 selection
.add_option(
254 metavar
='FILTER', dest
='match_filter', default
=None,
256 '(Experimental) Generic video filter. '
257 'Specify any key (see help for -o for a list of available keys) to'
258 ' match if the key is present, '
259 '!key to check if the key is not present,'
260 'key > NUMBER (like "comment_count > 12", also works with '
261 '>=, <, <=, !=, =) to compare against a number, and '
262 '& to require multiple matches. '
263 'Values which are not known are excluded unless you'
264 ' put a question mark (?) after the operator.'
265 'For example, to only match videos that have been liked more than '
266 '100 times and disliked less than 50 times (or the dislike '
267 'functionality is not available at the given service), but who '
268 'also have a description, use --match-filter '
269 '"like_count > 100 & dislike_count <? 50 & description" .'
271 selection
.add_option(
273 action
='store_true', dest
='noplaylist', default
=False,
274 help='If the URL refers to a video and a playlist, download only the video.')
275 selection
.add_option(
277 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
278 help='download only videos suitable for the given age')
279 selection
.add_option(
280 '--download-archive', metavar
='FILE',
281 dest
='download_archive',
282 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
283 selection
.add_option(
285 dest
='include_ads', action
='store_true',
286 help='Download advertisements as well (experimental)')
288 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
289 authentication
.add_option(
291 dest
='username', metavar
='USERNAME',
292 help='login with this account ID')
293 authentication
.add_option(
295 dest
='password', metavar
='PASSWORD',
296 help='account password. If this option is left out, youtube-dl will ask interactively.')
297 authentication
.add_option(
299 dest
='twofactor', metavar
='TWOFACTOR',
300 help='two-factor auth code')
301 authentication
.add_option(
303 action
='store_true', dest
='usenetrc', default
=False,
304 help='use .netrc authentication data')
305 authentication
.add_option(
307 dest
='videopassword', metavar
='PASSWORD',
308 help='video password (vimeo, smotri)')
310 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
311 video_format
.add_option(
313 action
='store', dest
='format', metavar
='FORMAT', default
=None,
315 'video format code, specify the order of preference using'
316 ' slashes, as in -f 22/17/18 . '
317 ' Instead of format codes, you can select by extension for the '
318 'extensions aac, m4a, mp3, mp4, ogg, wav, webm. '
319 'You can also use the special names "best",'
320 ' "bestvideo", "bestaudio", "worst". '
321 ' You can filter the video results by putting a condition in'
322 ' brackets, as in -f "best[height=720]"'
323 ' (or -f "[filesize>10M]"). '
324 ' This works for filesize, height, width, tbr, abr, vbr, asr, and fps'
325 ' and the comparisons <, <=, >, >=, =, !='
326 ' and for ext, acodec, vcodec, container, and protocol'
327 ' and the comparisons =, != .'
328 ' Formats for which the value is not known are excluded unless you'
329 ' put a question mark (?) after the operator.'
330 ' You can combine format filters, so '
331 '-f "[height <=? 720][tbr>500]" '
332 'selects up to 720p videos (or videos where the height is not '
333 'known) with a bitrate of at least 500 KBit/s.'
334 ' By default, youtube-dl will pick the best quality.'
335 ' Use commas to download multiple audio formats, such as'
336 ' -f 136/137/mp4/bestvideo,140/m4a/bestaudio.'
337 ' You can merge the video and audio of two formats into a single'
338 ' file using -f <video-format>+<audio-format> (requires ffmpeg or'
339 ' avconv), for example -f bestvideo+bestaudio.'))
340 video_format
.add_option(
342 action
='store_const', dest
='format', const
='all',
343 help='download all available video formats')
344 video_format
.add_option(
345 '--prefer-free-formats',
346 action
='store_true', dest
='prefer_free_formats', default
=False,
347 help='prefer free video formats unless a specific one is requested')
348 video_format
.add_option(
350 action
='store', dest
='format_limit', metavar
='FORMAT',
351 help='highest quality format to download')
352 video_format
.add_option(
353 '-F', '--list-formats',
354 action
='store_true', dest
='listformats',
355 help='list all available formats')
356 video_format
.add_option(
357 '--youtube-include-dash-manifest',
358 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
359 help=optparse
.SUPPRESS_HELP
)
360 video_format
.add_option(
361 '--youtube-skip-dash-manifest',
362 action
='store_false', dest
='youtube_include_dash_manifest',
363 help='Do not download the DASH manifest on YouTube videos')
364 video_format
.add_option(
365 '--merge-output-format',
366 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
368 'If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv.'
369 'Ignored if no merge is required'))
371 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
372 subtitles
.add_option(
373 '--write-sub', '--write-srt',
374 action
='store_true', dest
='writesubtitles', default
=False,
375 help='write subtitle file')
376 subtitles
.add_option(
377 '--write-auto-sub', '--write-automatic-sub',
378 action
='store_true', dest
='writeautomaticsub', default
=False,
379 help='write automatic subtitle file (youtube only)')
380 subtitles
.add_option(
382 action
='store_true', dest
='allsubtitles', default
=False,
383 help='downloads all the available subtitles of the video')
384 subtitles
.add_option(
386 action
='store_true', dest
='listsubtitles', default
=False,
387 help='lists all available subtitles for the video')
388 subtitles
.add_option(
390 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='srt',
391 help='subtitle format (default=srt) ([sbv/vtt] youtube only)')
392 subtitles
.add_option(
393 '--sub-lang', '--sub-langs', '--srt-lang',
394 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
395 default
=[], callback
=_comma_separated_values_options_callback
,
396 help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
398 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
399 downloader
.add_option(
400 '-r', '--rate-limit',
401 dest
='ratelimit', metavar
='LIMIT',
402 help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
403 downloader
.add_option(
405 dest
='retries', metavar
='RETRIES', default
=10,
406 help='number of retries (default is %default), or "infinite".')
407 downloader
.add_option(
409 dest
='buffersize', metavar
='SIZE', default
='1024',
410 help='size of download buffer (e.g. 1024 or 16K) (default is %default)')
411 downloader
.add_option(
412 '--no-resize-buffer',
413 action
='store_true', dest
='noresizebuffer', default
=False,
414 help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
415 downloader
.add_option(
417 action
='store_true', dest
='test', default
=False,
418 help=optparse
.SUPPRESS_HELP
)
419 downloader
.add_option(
420 '--playlist-reverse',
422 help='Download playlist videos in reverse order')
423 downloader
.add_option(
424 '--xattr-set-filesize',
425 dest
='xattr_set_filesize', action
='store_true',
426 help='(experimental) set file xattribute ytdl.filesize with expected filesize')
427 downloader
.add_option(
428 '--external-downloader',
429 dest
='external_downloader', metavar
='COMMAND',
430 help='(experimental) Use the specified external downloader. '
431 'Currently supports %s' % ','.join(list_external_downloaders()))
433 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
434 workarounds
.add_option(
436 dest
='encoding', metavar
='ENCODING',
437 help='Force the specified encoding (experimental)')
438 workarounds
.add_option(
439 '--no-check-certificate',
440 action
='store_true', dest
='no_check_certificate', default
=False,
441 help='Suppress HTTPS certificate validation.')
442 workarounds
.add_option(
444 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
445 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
446 workarounds
.add_option(
448 metavar
='UA', dest
='user_agent',
449 help='specify a custom user agent')
450 workarounds
.add_option(
452 metavar
='URL', dest
='referer', default
=None,
453 help='specify a custom referer, use if the video access is restricted to one domain',
455 workarounds
.add_option(
457 metavar
='FIELD:VALUE', dest
='headers', action
='append',
458 help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
460 workarounds
.add_option(
462 dest
='bidi_workaround', action
='store_true',
463 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
464 workarounds
.add_option(
465 '--sleep-interval', metavar
='SECONDS',
466 dest
='sleep_interval', type=float,
467 help='Number of seconds to sleep before each download.')
469 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
470 verbosity
.add_option(
472 action
='store_true', dest
='quiet', default
=False,
473 help='activates quiet mode')
474 verbosity
.add_option(
476 dest
='no_warnings', action
='store_true', default
=False,
477 help='Ignore warnings')
478 verbosity
.add_option(
480 action
='store_true', dest
='simulate', default
=False,
481 help='do not download the video and do not write anything to disk',)
482 verbosity
.add_option(
484 action
='store_true', dest
='skip_download', default
=False,
485 help='do not download the video',)
486 verbosity
.add_option(
488 action
='store_true', dest
='geturl', default
=False,
489 help='simulate, quiet but print URL')
490 verbosity
.add_option(
492 action
='store_true', dest
='gettitle', default
=False,
493 help='simulate, quiet but print title')
494 verbosity
.add_option(
496 action
='store_true', dest
='getid', default
=False,
497 help='simulate, quiet but print id')
498 verbosity
.add_option(
500 action
='store_true', dest
='getthumbnail', default
=False,
501 help='simulate, quiet but print thumbnail URL')
502 verbosity
.add_option(
504 action
='store_true', dest
='getdescription', default
=False,
505 help='simulate, quiet but print video description')
506 verbosity
.add_option(
508 action
='store_true', dest
='getduration', default
=False,
509 help='simulate, quiet but print video length')
510 verbosity
.add_option(
512 action
='store_true', dest
='getfilename', default
=False,
513 help='simulate, quiet but print output filename')
514 verbosity
.add_option(
516 action
='store_true', dest
='getformat', default
=False,
517 help='simulate, quiet but print output format')
518 verbosity
.add_option(
520 action
='store_true', dest
='dumpjson', default
=False,
521 help='simulate, quiet but print JSON information. See --output for a description of available keys.')
522 verbosity
.add_option(
523 '-J', '--dump-single-json',
524 action
='store_true', dest
='dump_single_json', default
=False,
525 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.')
526 verbosity
.add_option(
528 action
='store_true', dest
='print_json', default
=False,
529 help='Be quiet and print the video information as JSON (video is still being downloaded).',
531 verbosity
.add_option(
533 action
='store_true', dest
='progress_with_newline', default
=False,
534 help='output progress bar as new lines')
535 verbosity
.add_option(
537 action
='store_true', dest
='noprogress', default
=False,
538 help='do not print progress bar')
539 verbosity
.add_option(
541 action
='store_true', dest
='consoletitle', default
=False,
542 help='display progress in console titlebar')
543 verbosity
.add_option(
545 action
='store_true', dest
='verbose', default
=False,
546 help='print various debugging information')
547 verbosity
.add_option(
548 '--dump-intermediate-pages',
549 action
='store_true', dest
='dump_intermediate_pages', default
=False,
550 help='print downloaded pages to debug problems (very verbose)')
551 verbosity
.add_option(
553 action
='store_true', dest
='write_pages', default
=False,
554 help='Write downloaded intermediary pages to files in the current directory to debug problems')
555 verbosity
.add_option(
556 '--youtube-print-sig-code',
557 action
='store_true', dest
='youtube_print_sig_code', default
=False,
558 help=optparse
.SUPPRESS_HELP
)
559 verbosity
.add_option(
560 '--print-traffic', '--dump-headers',
561 dest
='debug_printtraffic', action
='store_true', default
=False,
562 help='Display sent and read HTTP traffic')
563 verbosity
.add_option(
565 dest
='call_home', action
='store_true', default
=False,
566 help='Contact the youtube-dl server for debugging.')
567 verbosity
.add_option(
569 dest
='call_home', action
='store_false', default
=False,
570 help='Do NOT contact the youtube-dl server for debugging.')
572 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
573 filesystem
.add_option(
574 '-a', '--batch-file',
575 dest
='batchfile', metavar
='FILE',
576 help='file containing URLs to download (\'-\' for stdin)')
577 filesystem
.add_option(
578 '--id', default
=False,
579 action
='store_true', dest
='useid', help='use only video ID in file name')
580 filesystem
.add_option(
582 dest
='outtmpl', metavar
='TEMPLATE',
583 help=('output filename template. Use %(title)s to get the title, '
584 '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
585 '%(autonumber)s to get an automatically incremented number, '
586 '%(ext)s for the filename extension, '
587 '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
588 '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
589 '%(upload_date)s for the upload date (YYYYMMDD), '
590 '%(extractor)s for the provider (youtube, metacafe, etc), '
591 '%(id)s for the video id, '
592 '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
593 '%(playlist_index)s for the position in the playlist. '
594 '%(height)s and %(width)s for the width and height of the video format. '
595 '%(resolution)s for a textual description of the resolution of the video format. '
596 '%% for a literal percent. '
597 'Use - to output to stdout. Can also be used to download to a different directory, '
598 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
599 filesystem
.add_option(
601 dest
='autonumber_size', metavar
='NUMBER',
602 help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
603 filesystem
.add_option(
604 '--restrict-filenames',
605 action
='store_true', dest
='restrictfilenames', default
=False,
606 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
607 filesystem
.add_option(
608 '-A', '--auto-number',
609 action
='store_true', dest
='autonumber', default
=False,
610 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] number downloaded files starting from 00000')
611 filesystem
.add_option(
613 action
='store_true', dest
='usetitle', default
=False,
614 help='[deprecated] use title in file name (default)')
615 filesystem
.add_option(
616 '-l', '--literal', default
=False,
617 action
='store_true', dest
='usetitle',
618 help='[deprecated] alias of --title')
619 filesystem
.add_option(
620 '-w', '--no-overwrites',
621 action
='store_true', dest
='nooverwrites', default
=False,
622 help='do not overwrite files')
623 filesystem
.add_option(
625 action
='store_true', dest
='continue_dl', default
=True,
626 help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
627 filesystem
.add_option(
629 action
='store_false', dest
='continue_dl',
630 help='do not resume partially downloaded files (restart from beginning)')
631 filesystem
.add_option(
633 action
='store_true', dest
='nopart', default
=False,
634 help='do not use .part files - write directly into output file')
635 filesystem
.add_option(
637 action
='store_false', dest
='updatetime', default
=True,
638 help='do not use the Last-modified header to set the file modification time')
639 filesystem
.add_option(
640 '--write-description',
641 action
='store_true', dest
='writedescription', default
=False,
642 help='write video description to a .description file')
643 filesystem
.add_option(
645 action
='store_true', dest
='writeinfojson', default
=False,
646 help='write video metadata to a .info.json file')
647 filesystem
.add_option(
648 '--write-annotations',
649 action
='store_true', dest
='writeannotations', default
=False,
650 help='write video annotations to a .annotation file')
651 filesystem
.add_option(
653 dest
='load_info_filename', metavar
='FILE',
654 help='json file containing the video information (created with the "--write-json" option)')
655 filesystem
.add_option(
657 dest
='cookiefile', metavar
='FILE',
658 help='file to read cookies from and dump cookie jar in')
659 filesystem
.add_option(
660 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
661 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.')
662 filesystem
.add_option(
663 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
664 help='Disable filesystem caching')
665 filesystem
.add_option(
667 action
='store_true', dest
='rm_cachedir',
668 help='Delete all filesystem cache files')
670 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
671 thumbnail
.add_option(
673 action
='store_true', dest
='writethumbnail', default
=False,
674 help='write thumbnail image to disk')
675 thumbnail
.add_option(
676 '--write-all-thumbnails',
677 action
='store_true', dest
='write_all_thumbnails', default
=False,
678 help='write all thumbnail image formats to disk')
679 thumbnail
.add_option(
681 action
='store_true', dest
='list_thumbnails', default
=False,
682 help='Simulate and list all available thumbnail formats')
684 postproc
= optparse
.OptionGroup(parser
, 'Post-processing Options')
686 '-x', '--extract-audio',
687 action
='store_true', dest
='extractaudio', default
=False,
688 help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
690 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
691 help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
693 '--audio-quality', metavar
='QUALITY',
694 dest
='audioquality', default
='5',
695 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)')
698 metavar
='FORMAT', dest
='recodevideo', default
=None,
699 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
701 '-k', '--keep-video',
702 action
='store_true', dest
='keepvideo', default
=False,
703 help='keeps the video file on disk after the post-processing; the video is erased by default')
705 '--no-post-overwrites',
706 action
='store_true', dest
='nopostoverwrites', default
=False,
707 help='do not overwrite post-processed files; the post-processed files are overwritten by default')
710 action
='store_true', dest
='embedsubtitles', default
=False,
711 help='embed subtitles in the video (only for mp4 videos)')
714 action
='store_true', dest
='embedthumbnail', default
=False,
715 help='embed thumbnail in the audio as cover art')
718 action
='store_true', dest
='addmetadata', default
=False,
719 help='write metadata to the video file')
722 action
='store_true', dest
='xattrs', default
=False,
723 help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
726 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
727 help='Automatically correct known faults of the file. '
728 'One of never (do nothing), warn (only emit a warning), '
729 'detect_or_warn(the default; fix file if we can, warn otherwise)')
732 action
='store_false', dest
='prefer_ffmpeg',
733 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
736 action
='store_true', dest
='prefer_ffmpeg',
737 help='Prefer ffmpeg over avconv for running the postprocessors')
739 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
740 dest
='ffmpeg_location',
741 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
744 metavar
='CMD', dest
='exec_cmd',
745 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
747 parser
.add_option_group(general
)
748 parser
.add_option_group(network
)
749 parser
.add_option_group(selection
)
750 parser
.add_option_group(downloader
)
751 parser
.add_option_group(filesystem
)
752 parser
.add_option_group(thumbnail
)
753 parser
.add_option_group(verbosity
)
754 parser
.add_option_group(workarounds
)
755 parser
.add_option_group(video_format
)
756 parser
.add_option_group(subtitles
)
757 parser
.add_option_group(authentication
)
758 parser
.add_option_group(postproc
)
760 if overrideArguments
is not None:
761 opts
, args
= parser
.parse_args(overrideArguments
)
763 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
765 command_line_conf
= sys
.argv
[1:]
766 if '--ignore-config' in command_line_conf
:
770 system_conf
= _readOptions('/etc/youtube-dl.conf')
771 if '--ignore-config' in system_conf
:
774 user_conf
= _readUserConf()
775 argv
= system_conf
+ user_conf
+ command_line_conf
777 opts
, args
= parser
.parse_args(argv
)
779 write_string('[debug] System config: ' + repr(_hide_login_info(system_conf
)) + '\n')
780 write_string('[debug] User config: ' + repr(_hide_login_info(user_conf
)) + '\n')
781 write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf
)) + '\n')
783 return parser
, opts
, args