1 from __future__
import unicode_literals
8 from .downloader
.external
import list_external_downloaders
11 compat_get_terminal_size
,
20 from .version
import __version__
23 def parseOpts(overrideArguments
=None):
24 def _readOptions(filename_bytes
, default
=[]):
26 optionf
= open(filename_bytes
)
28 return default
# silently skip if file is not present
30 # FIXME: https://github.com/rg3/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
31 contents
= optionf
.read()
32 if sys
.version_info
< (3,):
33 contents
= contents
.decode(preferredencoding())
34 res
= compat_shlex_split(contents
, comments
=True)
40 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME')
42 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl', 'config')
43 if not os
.path
.isfile(userConfFile
):
44 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl.conf')
46 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl', 'config')
47 if not os
.path
.isfile(userConfFile
):
48 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl.conf')
49 userConf
= _readOptions(userConfFile
, None)
52 appdata_dir
= compat_getenv('appdata')
54 userConf
= _readOptions(
55 os
.path
.join(appdata_dir
, 'youtube-dl', 'config'),
58 userConf
= _readOptions(
59 os
.path
.join(appdata_dir
, 'youtube-dl', 'config.txt'),
63 userConf
= _readOptions(
64 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf'),
67 userConf
= _readOptions(
68 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf.txt'),
76 def _format_option_string(option
):
77 ''' ('-o', '--option') -> -o, --format METAVAR'''
81 if option
._short
_opts
:
82 opts
.append(option
._short
_opts
[0])
84 opts
.append(option
._long
_opts
[0])
88 if option
.takes_value():
89 opts
.append(' %s' % option
.metavar
)
93 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
94 setattr(parser
.values
, option
.dest
, value
.split(','))
96 def _hide_login_info(opts
):
97 PRIVATE_OPTS
= ['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username']
98 eqre
= re
.compile('^(?P<key>' + ('|'.join(re
.escape(po
) for po
in PRIVATE_OPTS
)) + ')=.+$')
103 return m
.group('key') + '=PRIVATE'
107 opts
= list(map(_scrub_eq
, opts
))
108 for private_opt
in PRIVATE_OPTS
:
110 i
= opts
.index(private_opt
)
111 opts
[i
+ 1] = 'PRIVATE'
116 # No need to wrap help messages if we're on a wide console
117 columns
= compat_get_terminal_size().columns
118 max_width
= columns
if columns
else 80
119 max_help_position
= 80
121 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
122 fmt
.format_option_strings
= _format_option_string
125 'version': __version__
,
127 'usage': '%prog [OPTIONS] URL [URL...]',
128 'conflict_handler': 'resolve',
131 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
133 general
= optparse
.OptionGroup(parser
, 'General Options')
137 help='Print this help text and exit')
141 help='Print program version and exit')
144 action
='store_true', dest
='update_self',
145 help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
147 '-i', '--ignore-errors',
148 action
='store_true', dest
='ignoreerrors', default
=False,
149 help='Continue on download errors, for example to skip unavailable videos in a playlist')
152 action
='store_false', dest
='ignoreerrors',
153 help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
156 action
='store_true', dest
='dump_user_agent', default
=False,
157 help='Display the current browser identification')
160 action
='store_true', dest
='list_extractors', default
=False,
161 help='List all supported extractors')
163 '--extractor-descriptions',
164 action
='store_true', dest
='list_extractor_descriptions', default
=False,
165 help='Output descriptions of all supported extractors')
167 '--force-generic-extractor',
168 action
='store_true', dest
='force_generic_extractor', default
=False,
169 help='Force extraction to use the generic extractor')
172 dest
='default_search', metavar
='PREFIX',
173 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.')
177 help='Do not read configuration files. '
178 'When given in the global configuration file /etc/youtube-dl.conf: '
179 'Do not read the user configuration in ~/.config/youtube-dl/config '
180 '(%APPDATA%/youtube-dl/config.txt on Windows)')
183 dest
='config_location', metavar
='PATH',
184 help='Location of the configuration file; either the path to the config or its containing directory.')
187 action
='store_const', dest
='extract_flat', const
='in_playlist',
189 help='Do not extract the videos of a playlist, only list them.')
192 action
='store_true', dest
='mark_watched', default
=False,
193 help='Mark videos watched (YouTube only)')
196 action
='store_false', dest
='mark_watched', default
=False,
197 help='Do not mark videos watched (YouTube only)')
199 '--no-color', '--no-colors',
200 action
='store_true', dest
='no_color',
202 help='Do not emit color codes in output')
204 network
= optparse
.OptionGroup(parser
, 'Network Options')
206 '--proxy', dest
='proxy',
207 default
=None, metavar
='URL',
208 help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental '
209 'SOCKS proxy, specify a proper scheme. For example '
210 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
211 'for direct connection')
214 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
215 help='Time to wait before giving up, in seconds')
218 metavar
='IP', dest
='source_address', default
=None,
219 help='Client-side IP address to bind to',
222 '-4', '--force-ipv4',
223 action
='store_const', const
='0.0.0.0', dest
='source_address',
224 help='Make all connections via IPv4',
227 '-6', '--force-ipv6',
228 action
='store_const', const
='::', dest
='source_address',
229 help='Make all connections via IPv6',
232 '--geo-verification-proxy',
233 dest
='geo_verification_proxy', default
=None, metavar
='URL',
234 help='Use this proxy to verify the IP address for some geo-restricted sites. '
235 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading.'
238 '--cn-verification-proxy',
239 dest
='cn_verification_proxy', default
=None, metavar
='URL',
240 help=optparse
.SUPPRESS_HELP
,
243 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
244 selection
.add_option(
246 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
247 help='Playlist video to start at (default is %default)')
248 selection
.add_option(
250 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
251 help='Playlist video to end at (default is last)')
252 selection
.add_option(
254 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
255 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.')
256 selection
.add_option(
258 dest
='matchtitle', metavar
='REGEX',
259 help='Download only matching titles (regex or caseless sub-string)')
260 selection
.add_option(
262 dest
='rejecttitle', metavar
='REGEX',
263 help='Skip download for matching titles (regex or caseless sub-string)')
264 selection
.add_option(
266 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
267 help='Abort after downloading NUMBER files')
268 selection
.add_option(
270 metavar
='SIZE', dest
='min_filesize', default
=None,
271 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
272 selection
.add_option(
274 metavar
='SIZE', dest
='max_filesize', default
=None,
275 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
276 selection
.add_option(
278 metavar
='DATE', dest
='date', default
=None,
279 help='Download only videos uploaded in this date')
280 selection
.add_option(
282 metavar
='DATE', dest
='datebefore', default
=None,
283 help='Download only videos uploaded on or before this date (i.e. inclusive)')
284 selection
.add_option(
286 metavar
='DATE', dest
='dateafter', default
=None,
287 help='Download only videos uploaded on or after this date (i.e. inclusive)')
288 selection
.add_option(
290 metavar
='COUNT', dest
='min_views', default
=None, type=int,
291 help='Do not download any videos with less than COUNT views')
292 selection
.add_option(
294 metavar
='COUNT', dest
='max_views', default
=None, type=int,
295 help='Do not download any videos with more than COUNT views')
296 selection
.add_option(
298 metavar
='FILTER', dest
='match_filter', default
=None,
300 'Generic video filter. '
301 'Specify any key (see help for -o for a list of available keys) to'
302 ' match if the key is present, '
303 '!key to check if the key is not present,'
304 'key > NUMBER (like "comment_count > 12", also works with '
305 '>=, <, <=, !=, =) to compare against a number, and '
306 '& to require multiple matches. '
307 'Values which are not known are excluded unless you'
308 ' put a question mark (?) after the operator.'
309 'For example, to only match videos that have been liked more than '
310 '100 times and disliked less than 50 times (or the dislike '
311 'functionality is not available at the given service), but who '
312 'also have a description, use --match-filter '
313 '"like_count > 100 & dislike_count <? 50 & description" .'
315 selection
.add_option(
317 action
='store_true', dest
='noplaylist', default
=False,
318 help='Download only the video, if the URL refers to a video and a playlist.')
319 selection
.add_option(
321 action
='store_false', dest
='noplaylist', default
=False,
322 help='Download the playlist, if the URL refers to a video and a playlist.')
323 selection
.add_option(
325 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
326 help='Download only videos suitable for the given age')
327 selection
.add_option(
328 '--download-archive', metavar
='FILE',
329 dest
='download_archive',
330 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
331 selection
.add_option(
333 dest
='include_ads', action
='store_true',
334 help='Download advertisements as well (experimental)')
336 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
337 authentication
.add_option(
339 dest
='username', metavar
='USERNAME',
340 help='Login with this account ID')
341 authentication
.add_option(
343 dest
='password', metavar
='PASSWORD',
344 help='Account password. If this option is left out, youtube-dl will ask interactively.')
345 authentication
.add_option(
347 dest
='twofactor', metavar
='TWOFACTOR',
348 help='Two-factor authentication code')
349 authentication
.add_option(
351 action
='store_true', dest
='usenetrc', default
=False,
352 help='Use .netrc authentication data')
353 authentication
.add_option(
355 dest
='videopassword', metavar
='PASSWORD',
356 help='Video password (vimeo, smotri, youku)')
358 adobe_pass
= optparse
.OptionGroup(parser
, 'Adobe Pass Options')
359 adobe_pass
.add_option(
361 dest
='ap_mso', metavar
='MSO',
362 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
363 adobe_pass
.add_option(
365 dest
='ap_username', metavar
='USERNAME',
366 help='Multiple-system operator account login')
367 adobe_pass
.add_option(
369 dest
='ap_password', metavar
='PASSWORD',
370 help='Multiple-system operator account password. If this option is left out, youtube-dl will ask interactively.')
371 adobe_pass
.add_option(
373 action
='store_true', dest
='ap_list_mso', default
=False,
374 help='List all supported multiple-system operators')
376 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
377 video_format
.add_option(
379 action
='store', dest
='format', metavar
='FORMAT', default
=None,
380 help='Video format code, see the "FORMAT SELECTION" for all the info')
381 video_format
.add_option(
383 action
='store_const', dest
='format', const
='all',
384 help='Download all available video formats')
385 video_format
.add_option(
386 '--prefer-free-formats',
387 action
='store_true', dest
='prefer_free_formats', default
=False,
388 help='Prefer free video formats unless a specific one is requested')
389 video_format
.add_option(
390 '-F', '--list-formats',
391 action
='store_true', dest
='listformats',
392 help='List all available formats of requested videos')
393 video_format
.add_option(
394 '--youtube-include-dash-manifest',
395 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
396 help=optparse
.SUPPRESS_HELP
)
397 video_format
.add_option(
398 '--youtube-skip-dash-manifest',
399 action
='store_false', dest
='youtube_include_dash_manifest',
400 help='Do not download the DASH manifests and related data on YouTube videos')
401 video_format
.add_option(
402 '--merge-output-format',
403 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
405 'If a merge is required (e.g. bestvideo+bestaudio), '
406 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
407 'Ignored if no merge is required'))
409 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
410 subtitles
.add_option(
411 '--write-sub', '--write-srt',
412 action
='store_true', dest
='writesubtitles', default
=False,
413 help='Write subtitle file')
414 subtitles
.add_option(
415 '--write-auto-sub', '--write-automatic-sub',
416 action
='store_true', dest
='writeautomaticsub', default
=False,
417 help='Write automatically generated subtitle file (YouTube only)')
418 subtitles
.add_option(
420 action
='store_true', dest
='allsubtitles', default
=False,
421 help='Download all the available subtitles of the video')
422 subtitles
.add_option(
424 action
='store_true', dest
='listsubtitles', default
=False,
425 help='List all available subtitles for the video')
426 subtitles
.add_option(
428 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
429 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
430 subtitles
.add_option(
431 '--sub-lang', '--sub-langs', '--srt-lang',
432 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
433 default
=[], callback
=_comma_separated_values_options_callback
,
434 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
436 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
437 downloader
.add_option(
438 '-r', '--limit-rate', '--rate-limit',
439 dest
='ratelimit', metavar
='RATE',
440 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
441 downloader
.add_option(
443 dest
='retries', metavar
='RETRIES', default
=10,
444 help='Number of retries (default is %default), or "infinite".')
445 downloader
.add_option(
446 '--fragment-retries',
447 dest
='fragment_retries', metavar
='RETRIES', default
=10,
448 help='Number of retries for a fragment (default is %default), or "infinite" (DASH and hlsnative only)')
449 downloader
.add_option(
450 '--skip-unavailable-fragments',
451 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
452 help='Skip unavailable fragments (DASH and hlsnative only)')
453 downloader
.add_option(
454 '--abort-on-unavailable-fragment',
455 action
='store_false', dest
='skip_unavailable_fragments',
456 help='Abort downloading when some fragment is not available')
457 downloader
.add_option(
459 dest
='buffersize', metavar
='SIZE', default
='1024',
460 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
461 downloader
.add_option(
462 '--no-resize-buffer',
463 action
='store_true', dest
='noresizebuffer', default
=False,
464 help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
465 downloader
.add_option(
467 action
='store_true', dest
='test', default
=False,
468 help=optparse
.SUPPRESS_HELP
)
469 downloader
.add_option(
470 '--playlist-reverse',
472 help='Download playlist videos in reverse order')
473 downloader
.add_option(
476 help='Download playlist videos in random order')
477 downloader
.add_option(
478 '--xattr-set-filesize',
479 dest
='xattr_set_filesize', action
='store_true',
480 help='Set file xattribute ytdl.filesize with expected file size (experimental)')
481 downloader
.add_option(
482 '--hls-prefer-native',
483 dest
='hls_prefer_native', action
='store_true', default
=None,
484 help='Use the native HLS downloader instead of ffmpeg')
485 downloader
.add_option(
486 '--hls-prefer-ffmpeg',
487 dest
='hls_prefer_native', action
='store_false', default
=None,
488 help='Use ffmpeg instead of the native HLS downloader')
489 downloader
.add_option(
491 dest
='hls_use_mpegts', action
='store_true',
492 help='Use the mpegts container for HLS videos, allowing to play the '
493 'video while downloading (some players may not be able to play it)')
494 downloader
.add_option(
495 '--external-downloader',
496 dest
='external_downloader', metavar
='COMMAND',
497 help='Use the specified external downloader. '
498 'Currently supports %s' % ','.join(list_external_downloaders()))
499 downloader
.add_option(
500 '--external-downloader-args',
501 dest
='external_downloader_args', metavar
='ARGS',
502 help='Give these arguments to the external downloader')
504 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
505 workarounds
.add_option(
507 dest
='encoding', metavar
='ENCODING',
508 help='Force the specified encoding (experimental)')
509 workarounds
.add_option(
510 '--no-check-certificate',
511 action
='store_true', dest
='no_check_certificate', default
=False,
512 help='Suppress HTTPS certificate validation')
513 workarounds
.add_option(
515 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
516 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
517 workarounds
.add_option(
519 metavar
='UA', dest
='user_agent',
520 help='Specify a custom user agent')
521 workarounds
.add_option(
523 metavar
='URL', dest
='referer', default
=None,
524 help='Specify a custom referer, use if the video access is restricted to one domain',
526 workarounds
.add_option(
528 metavar
='FIELD:VALUE', dest
='headers', action
='append',
529 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
531 workarounds
.add_option(
533 dest
='bidi_workaround', action
='store_true',
534 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
535 workarounds
.add_option(
536 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
537 dest
='sleep_interval', type=float,
539 'Number of seconds to sleep before each download when used alone '
540 'or a lower bound of a range for randomized sleep before each download '
541 '(minimum possible number of seconds to sleep) when used along with '
542 '--max-sleep-interval.'))
543 workarounds
.add_option(
544 '--max-sleep-interval', metavar
='SECONDS',
545 dest
='max_sleep_interval', type=float,
547 'Upper bound of a range for randomized sleep before each download '
548 '(maximum possible number of seconds to sleep). Must only be used '
549 'along with --min-sleep-interval.'))
551 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
552 verbosity
.add_option(
554 action
='store_true', dest
='quiet', default
=False,
555 help='Activate quiet mode')
556 verbosity
.add_option(
558 dest
='no_warnings', action
='store_true', default
=False,
559 help='Ignore warnings')
560 verbosity
.add_option(
562 action
='store_true', dest
='simulate', default
=False,
563 help='Do not download the video and do not write anything to disk')
564 verbosity
.add_option(
566 action
='store_true', dest
='skip_download', default
=False,
567 help='Do not download the video')
568 verbosity
.add_option(
570 action
='store_true', dest
='geturl', default
=False,
571 help='Simulate, quiet but print URL')
572 verbosity
.add_option(
574 action
='store_true', dest
='gettitle', default
=False,
575 help='Simulate, quiet but print title')
576 verbosity
.add_option(
578 action
='store_true', dest
='getid', default
=False,
579 help='Simulate, quiet but print id')
580 verbosity
.add_option(
582 action
='store_true', dest
='getthumbnail', default
=False,
583 help='Simulate, quiet but print thumbnail URL')
584 verbosity
.add_option(
586 action
='store_true', dest
='getdescription', default
=False,
587 help='Simulate, quiet but print video description')
588 verbosity
.add_option(
590 action
='store_true', dest
='getduration', default
=False,
591 help='Simulate, quiet but print video length')
592 verbosity
.add_option(
594 action
='store_true', dest
='getfilename', default
=False,
595 help='Simulate, quiet but print output filename')
596 verbosity
.add_option(
598 action
='store_true', dest
='getformat', default
=False,
599 help='Simulate, quiet but print output format')
600 verbosity
.add_option(
602 action
='store_true', dest
='dumpjson', default
=False,
603 help='Simulate, quiet but print JSON information. See --output for a description of available keys.')
604 verbosity
.add_option(
605 '-J', '--dump-single-json',
606 action
='store_true', dest
='dump_single_json', default
=False,
607 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.')
608 verbosity
.add_option(
610 action
='store_true', dest
='print_json', default
=False,
611 help='Be quiet and print the video information as JSON (video is still being downloaded).',
613 verbosity
.add_option(
615 action
='store_true', dest
='progress_with_newline', default
=False,
616 help='Output progress bar as new lines')
617 verbosity
.add_option(
619 action
='store_true', dest
='noprogress', default
=False,
620 help='Do not print progress bar')
621 verbosity
.add_option(
623 action
='store_true', dest
='consoletitle', default
=False,
624 help='Display progress in console titlebar')
625 verbosity
.add_option(
627 action
='store_true', dest
='verbose', default
=False,
628 help='Print various debugging information')
629 verbosity
.add_option(
630 '--dump-pages', '--dump-intermediate-pages',
631 action
='store_true', dest
='dump_intermediate_pages', default
=False,
632 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
633 verbosity
.add_option(
635 action
='store_true', dest
='write_pages', default
=False,
636 help='Write downloaded intermediary pages to files in the current directory to debug problems')
637 verbosity
.add_option(
638 '--youtube-print-sig-code',
639 action
='store_true', dest
='youtube_print_sig_code', default
=False,
640 help=optparse
.SUPPRESS_HELP
)
641 verbosity
.add_option(
642 '--print-traffic', '--dump-headers',
643 dest
='debug_printtraffic', action
='store_true', default
=False,
644 help='Display sent and read HTTP traffic')
645 verbosity
.add_option(
647 dest
='call_home', action
='store_true', default
=False,
648 help='Contact the youtube-dl server for debugging')
649 verbosity
.add_option(
651 dest
='call_home', action
='store_false', default
=False,
652 help='Do NOT contact the youtube-dl server for debugging')
654 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
655 filesystem
.add_option(
656 '-a', '--batch-file',
657 dest
='batchfile', metavar
='FILE',
658 help='File containing URLs to download (\'-\' for stdin)')
659 filesystem
.add_option(
660 '--id', default
=False,
661 action
='store_true', dest
='useid', help='Use only video ID in file name')
662 filesystem
.add_option(
664 dest
='outtmpl', metavar
='TEMPLATE',
665 help=('Output filename template, see the "OUTPUT TEMPLATE" for all the info'))
666 filesystem
.add_option(
668 dest
='autonumber_size', metavar
='NUMBER', default
=5, type=int,
669 help='Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given (default is %default)')
670 filesystem
.add_option(
671 '--autonumber-start',
672 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
673 help='Specify the start value for %(autonumber)s (default is %default)')
674 filesystem
.add_option(
675 '--restrict-filenames',
676 action
='store_true', dest
='restrictfilenames', default
=False,
677 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
678 filesystem
.add_option(
679 '-A', '--auto-number',
680 action
='store_true', dest
='autonumber', default
=False,
681 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] Number downloaded files starting from 00000')
682 filesystem
.add_option(
684 action
='store_true', dest
='usetitle', default
=False,
685 help='[deprecated] Use title in file name (default)')
686 filesystem
.add_option(
687 '-l', '--literal', default
=False,
688 action
='store_true', dest
='usetitle',
689 help='[deprecated] Alias of --title')
690 filesystem
.add_option(
691 '-w', '--no-overwrites',
692 action
='store_true', dest
='nooverwrites', default
=False,
693 help='Do not overwrite files')
694 filesystem
.add_option(
696 action
='store_true', dest
='continue_dl', default
=True,
697 help='Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
698 filesystem
.add_option(
700 action
='store_false', dest
='continue_dl',
701 help='Do not resume partially downloaded files (restart from beginning)')
702 filesystem
.add_option(
704 action
='store_true', dest
='nopart', default
=False,
705 help='Do not use .part files - write directly into output file')
706 filesystem
.add_option(
708 action
='store_false', dest
='updatetime', default
=True,
709 help='Do not use the Last-modified header to set the file modification time')
710 filesystem
.add_option(
711 '--write-description',
712 action
='store_true', dest
='writedescription', default
=False,
713 help='Write video description to a .description file')
714 filesystem
.add_option(
716 action
='store_true', dest
='writeinfojson', default
=False,
717 help='Write video metadata to a .info.json file')
718 filesystem
.add_option(
719 '--write-annotations',
720 action
='store_true', dest
='writeannotations', default
=False,
721 help='Write video annotations to a .annotations.xml file')
722 filesystem
.add_option(
723 '--load-info-json', '--load-info',
724 dest
='load_info_filename', metavar
='FILE',
725 help='JSON file containing the video information (created with the "--write-info-json" option)')
726 filesystem
.add_option(
728 dest
='cookiefile', metavar
='FILE',
729 help='File to read cookies from and dump cookie jar in')
730 filesystem
.add_option(
731 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
732 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.')
733 filesystem
.add_option(
734 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
735 help='Disable filesystem caching')
736 filesystem
.add_option(
738 action
='store_true', dest
='rm_cachedir',
739 help='Delete all filesystem cache files')
741 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
742 thumbnail
.add_option(
744 action
='store_true', dest
='writethumbnail', default
=False,
745 help='Write thumbnail image to disk')
746 thumbnail
.add_option(
747 '--write-all-thumbnails',
748 action
='store_true', dest
='write_all_thumbnails', default
=False,
749 help='Write all thumbnail image formats to disk')
750 thumbnail
.add_option(
752 action
='store_true', dest
='list_thumbnails', default
=False,
753 help='Simulate and list all available thumbnail formats')
755 postproc
= optparse
.OptionGroup(parser
, 'Post-processing Options')
757 '-x', '--extract-audio',
758 action
='store_true', dest
='extractaudio', default
=False,
759 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
761 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
762 help='Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default; No effect without -x')
764 '--audio-quality', metavar
='QUALITY',
765 dest
='audioquality', default
='5',
766 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)')
769 metavar
='FORMAT', dest
='recodevideo', default
=None,
770 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
772 '--postprocessor-args',
773 dest
='postprocessor_args', metavar
='ARGS',
774 help='Give these arguments to the postprocessor')
776 '-k', '--keep-video',
777 action
='store_true', dest
='keepvideo', default
=False,
778 help='Keep the video file on disk after the post-processing; the video is erased by default')
780 '--no-post-overwrites',
781 action
='store_true', dest
='nopostoverwrites', default
=False,
782 help='Do not overwrite post-processed files; the post-processed files are overwritten by default')
785 action
='store_true', dest
='embedsubtitles', default
=False,
786 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
789 action
='store_true', dest
='embedthumbnail', default
=False,
790 help='Embed thumbnail in the audio as cover art')
793 action
='store_true', dest
='addmetadata', default
=False,
794 help='Write metadata to the video file')
796 '--metadata-from-title',
797 metavar
='FORMAT', dest
='metafromtitle',
798 help='Parse additional metadata like song title / artist from the video title. '
799 'The format syntax is the same as --output, '
800 'the parsed parameters replace existing values. '
801 'Additional templates: %(album)s, %(artist)s. '
802 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
803 '"Coldplay - Paradise"')
806 action
='store_true', dest
='xattrs', default
=False,
807 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
810 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
811 help='Automatically correct known faults of the file. '
812 'One of never (do nothing), warn (only emit a warning), '
813 'detect_or_warn (the default; fix file if we can, warn otherwise)')
816 action
='store_false', dest
='prefer_ffmpeg',
817 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
820 action
='store_true', dest
='prefer_ffmpeg',
821 help='Prefer ffmpeg over avconv for running the postprocessors')
823 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
824 dest
='ffmpeg_location',
825 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
828 metavar
='CMD', dest
='exec_cmd',
829 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
831 '--convert-subs', '--convert-subtitles',
832 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
833 help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
835 parser
.add_option_group(general
)
836 parser
.add_option_group(network
)
837 parser
.add_option_group(selection
)
838 parser
.add_option_group(downloader
)
839 parser
.add_option_group(filesystem
)
840 parser
.add_option_group(thumbnail
)
841 parser
.add_option_group(verbosity
)
842 parser
.add_option_group(workarounds
)
843 parser
.add_option_group(video_format
)
844 parser
.add_option_group(subtitles
)
845 parser
.add_option_group(authentication
)
846 parser
.add_option_group(adobe_pass
)
847 parser
.add_option_group(postproc
)
849 if overrideArguments
is not None:
850 opts
, args
= parser
.parse_args(overrideArguments
)
852 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
854 def compat_conf(conf
):
855 if sys
.version_info
< (3,):
856 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
859 command_line_conf
= compat_conf(sys
.argv
[1:])
860 opts
, args
= parser
.parse_args(command_line_conf
)
862 system_conf
= user_conf
= custom_conf
= []
864 if '--config-location' in command_line_conf
:
865 location
= compat_expanduser(opts
.config_location
)
866 if os
.path
.isdir(location
):
867 location
= os
.path
.join(location
, 'youtube-dl.conf')
868 if not os
.path
.exists(location
):
869 parser
.error('config-location %s does not exist.' % location
)
870 custom_conf
= _readOptions(location
)
871 elif '--ignore-config' in command_line_conf
:
874 system_conf
= _readOptions('/etc/youtube-dl.conf')
875 if '--ignore-config' not in system_conf
:
876 user_conf
= _readUserConf()
878 argv
= system_conf
+ user_conf
+ custom_conf
+ command_line_conf
879 opts
, args
= parser
.parse_args(argv
)
881 for conf_label
, conf
in (
882 ('System config', system_conf
),
883 ('User config', user_conf
),
884 ('Custom config', custom_conf
),
885 ('Command-line args', command_line_conf
)):
886 write_string('[debug] %s: %s\n' % (conf_label
, repr(_hide_login_info(conf
))))
888 return parser
, opts
, args