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
= optparse
.OptionGroup(parser
, 'Geo Restriction')
234 '--geo-verification-proxy',
235 dest
='geo_verification_proxy', default
=None, metavar
='URL',
236 help='Use this proxy to verify the IP address for some geo-restricted sites. '
237 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading.')
239 '--cn-verification-proxy',
240 dest
='cn_verification_proxy', default
=None, metavar
='URL',
241 help=optparse
.SUPPRESS_HELP
)
244 action
='store_true', dest
='geo_bypass', default
=True,
245 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header (experimental)')
248 action
='store_false', dest
='geo_bypass', default
=True,
249 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header (experimental)')
251 '--geo-bypass-country', metavar
='CODE',
252 dest
='geo_bypass_country', default
=None,
253 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code (experimental)')
255 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
256 selection
.add_option(
258 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
259 help='Playlist video to start at (default is %default)')
260 selection
.add_option(
262 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
263 help='Playlist video to end at (default is last)')
264 selection
.add_option(
266 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
267 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.')
268 selection
.add_option(
270 dest
='matchtitle', metavar
='REGEX',
271 help='Download only matching titles (regex or caseless sub-string)')
272 selection
.add_option(
274 dest
='rejecttitle', metavar
='REGEX',
275 help='Skip download for matching titles (regex or caseless sub-string)')
276 selection
.add_option(
278 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
279 help='Abort after downloading NUMBER files')
280 selection
.add_option(
282 metavar
='SIZE', dest
='min_filesize', default
=None,
283 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
284 selection
.add_option(
286 metavar
='SIZE', dest
='max_filesize', default
=None,
287 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
288 selection
.add_option(
290 metavar
='DATE', dest
='date', default
=None,
291 help='Download only videos uploaded in this date')
292 selection
.add_option(
294 metavar
='DATE', dest
='datebefore', default
=None,
295 help='Download only videos uploaded on or before this date (i.e. inclusive)')
296 selection
.add_option(
298 metavar
='DATE', dest
='dateafter', default
=None,
299 help='Download only videos uploaded on or after this date (i.e. inclusive)')
300 selection
.add_option(
302 metavar
='COUNT', dest
='min_views', default
=None, type=int,
303 help='Do not download any videos with less than COUNT views')
304 selection
.add_option(
306 metavar
='COUNT', dest
='max_views', default
=None, type=int,
307 help='Do not download any videos with more than COUNT views')
308 selection
.add_option(
310 metavar
='FILTER', dest
='match_filter', default
=None,
312 'Generic video filter. '
313 'Specify any key (see help for -o for a list of available keys) to '
314 'match if the key is present, '
315 '!key to check if the key is not present, '
316 'key > NUMBER (like "comment_count > 12", also works with '
317 '>=, <, <=, !=, =) to compare against a number, '
318 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
319 'to match against a string literal '
320 'and & to require multiple matches. '
321 'Values which are not known are excluded unless you '
322 'put a question mark (?) after the operator. '
323 'For example, to only match videos that have been liked more than '
324 '100 times and disliked less than 50 times (or the dislike '
325 'functionality is not available at the given service), but who '
326 'also have a description, use --match-filter '
327 '"like_count > 100 & dislike_count <? 50 & description" .'
329 selection
.add_option(
331 action
='store_true', dest
='noplaylist', default
=False,
332 help='Download only the video, if the URL refers to a video and a playlist.')
333 selection
.add_option(
335 action
='store_false', dest
='noplaylist', default
=False,
336 help='Download the playlist, if the URL refers to a video and a playlist.')
337 selection
.add_option(
339 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
340 help='Download only videos suitable for the given age')
341 selection
.add_option(
342 '--download-archive', metavar
='FILE',
343 dest
='download_archive',
344 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
345 selection
.add_option(
347 dest
='include_ads', action
='store_true',
348 help='Download advertisements as well (experimental)')
350 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
351 authentication
.add_option(
353 dest
='username', metavar
='USERNAME',
354 help='Login with this account ID')
355 authentication
.add_option(
357 dest
='password', metavar
='PASSWORD',
358 help='Account password. If this option is left out, youtube-dl will ask interactively.')
359 authentication
.add_option(
361 dest
='twofactor', metavar
='TWOFACTOR',
362 help='Two-factor authentication code')
363 authentication
.add_option(
365 action
='store_true', dest
='usenetrc', default
=False,
366 help='Use .netrc authentication data')
367 authentication
.add_option(
369 dest
='videopassword', metavar
='PASSWORD',
370 help='Video password (vimeo, smotri, youku)')
372 adobe_pass
= optparse
.OptionGroup(parser
, 'Adobe Pass Options')
373 adobe_pass
.add_option(
375 dest
='ap_mso', metavar
='MSO',
376 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
377 adobe_pass
.add_option(
379 dest
='ap_username', metavar
='USERNAME',
380 help='Multiple-system operator account login')
381 adobe_pass
.add_option(
383 dest
='ap_password', metavar
='PASSWORD',
384 help='Multiple-system operator account password. If this option is left out, youtube-dl will ask interactively.')
385 adobe_pass
.add_option(
387 action
='store_true', dest
='ap_list_mso', default
=False,
388 help='List all supported multiple-system operators')
390 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
391 video_format
.add_option(
393 action
='store', dest
='format', metavar
='FORMAT', default
=None,
394 help='Video format code, see the "FORMAT SELECTION" for all the info')
395 video_format
.add_option(
397 action
='store_const', dest
='format', const
='all',
398 help='Download all available video formats')
399 video_format
.add_option(
400 '--prefer-free-formats',
401 action
='store_true', dest
='prefer_free_formats', default
=False,
402 help='Prefer free video formats unless a specific one is requested')
403 video_format
.add_option(
404 '-F', '--list-formats',
405 action
='store_true', dest
='listformats',
406 help='List all available formats of requested videos')
407 video_format
.add_option(
408 '--youtube-include-dash-manifest',
409 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
410 help=optparse
.SUPPRESS_HELP
)
411 video_format
.add_option(
412 '--youtube-skip-dash-manifest',
413 action
='store_false', dest
='youtube_include_dash_manifest',
414 help='Do not download the DASH manifests and related data on YouTube videos')
415 video_format
.add_option(
416 '--merge-output-format',
417 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
419 'If a merge is required (e.g. bestvideo+bestaudio), '
420 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
421 'Ignored if no merge is required'))
423 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
424 subtitles
.add_option(
425 '--write-sub', '--write-srt',
426 action
='store_true', dest
='writesubtitles', default
=False,
427 help='Write subtitle file')
428 subtitles
.add_option(
429 '--write-auto-sub', '--write-automatic-sub',
430 action
='store_true', dest
='writeautomaticsub', default
=False,
431 help='Write automatically generated subtitle file (YouTube only)')
432 subtitles
.add_option(
434 action
='store_true', dest
='allsubtitles', default
=False,
435 help='Download all the available subtitles of the video')
436 subtitles
.add_option(
438 action
='store_true', dest
='listsubtitles', default
=False,
439 help='List all available subtitles for the video')
440 subtitles
.add_option(
442 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
443 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
444 subtitles
.add_option(
445 '--sub-lang', '--sub-langs', '--srt-lang',
446 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
447 default
=[], callback
=_comma_separated_values_options_callback
,
448 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
450 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
451 downloader
.add_option(
452 '-r', '--limit-rate', '--rate-limit',
453 dest
='ratelimit', metavar
='RATE',
454 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
455 downloader
.add_option(
457 dest
='retries', metavar
='RETRIES', default
=10,
458 help='Number of retries (default is %default), or "infinite".')
459 downloader
.add_option(
460 '--fragment-retries',
461 dest
='fragment_retries', metavar
='RETRIES', default
=10,
462 help='Number of retries for a fragment (default is %default), or "infinite" (DASH and hlsnative only)')
463 downloader
.add_option(
464 '--skip-unavailable-fragments',
465 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
466 help='Skip unavailable fragments (DASH and hlsnative only)')
467 downloader
.add_option(
468 '--abort-on-unavailable-fragment',
469 action
='store_false', dest
='skip_unavailable_fragments',
470 help='Abort downloading when some fragment is not available')
471 downloader
.add_option(
473 dest
='buffersize', metavar
='SIZE', default
='1024',
474 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
475 downloader
.add_option(
476 '--no-resize-buffer',
477 action
='store_true', dest
='noresizebuffer', default
=False,
478 help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
479 downloader
.add_option(
481 action
='store_true', dest
='test', default
=False,
482 help=optparse
.SUPPRESS_HELP
)
483 downloader
.add_option(
484 '--playlist-reverse',
486 help='Download playlist videos in reverse order')
487 downloader
.add_option(
490 help='Download playlist videos in random order')
491 downloader
.add_option(
492 '--xattr-set-filesize',
493 dest
='xattr_set_filesize', action
='store_true',
494 help='Set file xattribute ytdl.filesize with expected file size (experimental)')
495 downloader
.add_option(
496 '--hls-prefer-native',
497 dest
='hls_prefer_native', action
='store_true', default
=None,
498 help='Use the native HLS downloader instead of ffmpeg')
499 downloader
.add_option(
500 '--hls-prefer-ffmpeg',
501 dest
='hls_prefer_native', action
='store_false', default
=None,
502 help='Use ffmpeg instead of the native HLS downloader')
503 downloader
.add_option(
505 dest
='hls_use_mpegts', action
='store_true',
506 help='Use the mpegts container for HLS videos, allowing to play the '
507 'video while downloading (some players may not be able to play it)')
508 downloader
.add_option(
509 '--external-downloader',
510 dest
='external_downloader', metavar
='COMMAND',
511 help='Use the specified external downloader. '
512 'Currently supports %s' % ','.join(list_external_downloaders()))
513 downloader
.add_option(
514 '--external-downloader-args',
515 dest
='external_downloader_args', metavar
='ARGS',
516 help='Give these arguments to the external downloader')
518 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
519 workarounds
.add_option(
521 dest
='encoding', metavar
='ENCODING',
522 help='Force the specified encoding (experimental)')
523 workarounds
.add_option(
524 '--no-check-certificate',
525 action
='store_true', dest
='no_check_certificate', default
=False,
526 help='Suppress HTTPS certificate validation')
527 workarounds
.add_option(
529 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
530 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
531 workarounds
.add_option(
533 metavar
='UA', dest
='user_agent',
534 help='Specify a custom user agent')
535 workarounds
.add_option(
537 metavar
='URL', dest
='referer', default
=None,
538 help='Specify a custom referer, use if the video access is restricted to one domain',
540 workarounds
.add_option(
542 metavar
='FIELD:VALUE', dest
='headers', action
='append',
543 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
545 workarounds
.add_option(
547 dest
='bidi_workaround', action
='store_true',
548 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
549 workarounds
.add_option(
550 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
551 dest
='sleep_interval', type=float,
553 'Number of seconds to sleep before each download when used alone '
554 'or a lower bound of a range for randomized sleep before each download '
555 '(minimum possible number of seconds to sleep) when used along with '
556 '--max-sleep-interval.'))
557 workarounds
.add_option(
558 '--max-sleep-interval', metavar
='SECONDS',
559 dest
='max_sleep_interval', type=float,
561 'Upper bound of a range for randomized sleep before each download '
562 '(maximum possible number of seconds to sleep). Must only be used '
563 'along with --min-sleep-interval.'))
565 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
566 verbosity
.add_option(
568 action
='store_true', dest
='quiet', default
=False,
569 help='Activate quiet mode')
570 verbosity
.add_option(
572 dest
='no_warnings', action
='store_true', default
=False,
573 help='Ignore warnings')
574 verbosity
.add_option(
576 action
='store_true', dest
='simulate', default
=False,
577 help='Do not download the video and do not write anything to disk')
578 verbosity
.add_option(
580 action
='store_true', dest
='skip_download', default
=False,
581 help='Do not download the video')
582 verbosity
.add_option(
584 action
='store_true', dest
='geturl', default
=False,
585 help='Simulate, quiet but print URL')
586 verbosity
.add_option(
588 action
='store_true', dest
='gettitle', default
=False,
589 help='Simulate, quiet but print title')
590 verbosity
.add_option(
592 action
='store_true', dest
='getid', default
=False,
593 help='Simulate, quiet but print id')
594 verbosity
.add_option(
596 action
='store_true', dest
='getthumbnail', default
=False,
597 help='Simulate, quiet but print thumbnail URL')
598 verbosity
.add_option(
600 action
='store_true', dest
='getdescription', default
=False,
601 help='Simulate, quiet but print video description')
602 verbosity
.add_option(
604 action
='store_true', dest
='getduration', default
=False,
605 help='Simulate, quiet but print video length')
606 verbosity
.add_option(
608 action
='store_true', dest
='getfilename', default
=False,
609 help='Simulate, quiet but print output filename')
610 verbosity
.add_option(
612 action
='store_true', dest
='getformat', default
=False,
613 help='Simulate, quiet but print output format')
614 verbosity
.add_option(
616 action
='store_true', dest
='dumpjson', default
=False,
617 help='Simulate, quiet but print JSON information. See --output for a description of available keys.')
618 verbosity
.add_option(
619 '-J', '--dump-single-json',
620 action
='store_true', dest
='dump_single_json', default
=False,
621 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.')
622 verbosity
.add_option(
624 action
='store_true', dest
='print_json', default
=False,
625 help='Be quiet and print the video information as JSON (video is still being downloaded).',
627 verbosity
.add_option(
629 action
='store_true', dest
='progress_with_newline', default
=False,
630 help='Output progress bar as new lines')
631 verbosity
.add_option(
633 action
='store_true', dest
='noprogress', default
=False,
634 help='Do not print progress bar')
635 verbosity
.add_option(
637 action
='store_true', dest
='consoletitle', default
=False,
638 help='Display progress in console titlebar')
639 verbosity
.add_option(
641 action
='store_true', dest
='verbose', default
=False,
642 help='Print various debugging information')
643 verbosity
.add_option(
644 '--dump-pages', '--dump-intermediate-pages',
645 action
='store_true', dest
='dump_intermediate_pages', default
=False,
646 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
647 verbosity
.add_option(
649 action
='store_true', dest
='write_pages', default
=False,
650 help='Write downloaded intermediary pages to files in the current directory to debug problems')
651 verbosity
.add_option(
652 '--youtube-print-sig-code',
653 action
='store_true', dest
='youtube_print_sig_code', default
=False,
654 help=optparse
.SUPPRESS_HELP
)
655 verbosity
.add_option(
656 '--print-traffic', '--dump-headers',
657 dest
='debug_printtraffic', action
='store_true', default
=False,
658 help='Display sent and read HTTP traffic')
659 verbosity
.add_option(
661 dest
='call_home', action
='store_true', default
=False,
662 help='Contact the youtube-dl server for debugging')
663 verbosity
.add_option(
665 dest
='call_home', action
='store_false', default
=False,
666 help='Do NOT contact the youtube-dl server for debugging')
668 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
669 filesystem
.add_option(
670 '-a', '--batch-file',
671 dest
='batchfile', metavar
='FILE',
672 help='File containing URLs to download (\'-\' for stdin)')
673 filesystem
.add_option(
674 '--id', default
=False,
675 action
='store_true', dest
='useid', help='Use only video ID in file name')
676 filesystem
.add_option(
678 dest
='outtmpl', metavar
='TEMPLATE',
679 help=('Output filename template, see the "OUTPUT TEMPLATE" for all the info'))
680 filesystem
.add_option(
682 dest
='autonumber_size', metavar
='NUMBER', default
=5, type=int,
683 help='[deprecated; use output template with %(autonumber)0Nd, where N in the number of digits] '
684 'Specify the number of digits in %(autonumber)s when it is present '
685 'in output filename template or --auto-number option is given (default is %default)')
686 filesystem
.add_option(
687 '--autonumber-start',
688 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
689 help='Specify the start value for %(autonumber)s (default is %default)')
690 filesystem
.add_option(
691 '--restrict-filenames',
692 action
='store_true', dest
='restrictfilenames', default
=False,
693 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
694 filesystem
.add_option(
695 '-A', '--auto-number',
696 action
='store_true', dest
='autonumber', default
=False,
697 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] Number downloaded files starting from 00000')
698 filesystem
.add_option(
700 action
='store_true', dest
='usetitle', default
=False,
701 help='[deprecated] Use title in file name (default)')
702 filesystem
.add_option(
703 '-l', '--literal', default
=False,
704 action
='store_true', dest
='usetitle',
705 help='[deprecated] Alias of --title')
706 filesystem
.add_option(
707 '-w', '--no-overwrites',
708 action
='store_true', dest
='nooverwrites', default
=False,
709 help='Do not overwrite files')
710 filesystem
.add_option(
712 action
='store_true', dest
='continue_dl', default
=True,
713 help='Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
714 filesystem
.add_option(
716 action
='store_false', dest
='continue_dl',
717 help='Do not resume partially downloaded files (restart from beginning)')
718 filesystem
.add_option(
720 action
='store_true', dest
='nopart', default
=False,
721 help='Do not use .part files - write directly into output file')
722 filesystem
.add_option(
724 action
='store_false', dest
='updatetime', default
=True,
725 help='Do not use the Last-modified header to set the file modification time')
726 filesystem
.add_option(
727 '--write-description',
728 action
='store_true', dest
='writedescription', default
=False,
729 help='Write video description to a .description file')
730 filesystem
.add_option(
732 action
='store_true', dest
='writeinfojson', default
=False,
733 help='Write video metadata to a .info.json file')
734 filesystem
.add_option(
735 '--write-annotations',
736 action
='store_true', dest
='writeannotations', default
=False,
737 help='Write video annotations to a .annotations.xml file')
738 filesystem
.add_option(
739 '--load-info-json', '--load-info',
740 dest
='load_info_filename', metavar
='FILE',
741 help='JSON file containing the video information (created with the "--write-info-json" option)')
742 filesystem
.add_option(
744 dest
='cookiefile', metavar
='FILE',
745 help='File to read cookies from and dump cookie jar in')
746 filesystem
.add_option(
747 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
748 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.')
749 filesystem
.add_option(
750 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
751 help='Disable filesystem caching')
752 filesystem
.add_option(
754 action
='store_true', dest
='rm_cachedir',
755 help='Delete all filesystem cache files')
757 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
758 thumbnail
.add_option(
760 action
='store_true', dest
='writethumbnail', default
=False,
761 help='Write thumbnail image to disk')
762 thumbnail
.add_option(
763 '--write-all-thumbnails',
764 action
='store_true', dest
='write_all_thumbnails', default
=False,
765 help='Write all thumbnail image formats to disk')
766 thumbnail
.add_option(
768 action
='store_true', dest
='list_thumbnails', default
=False,
769 help='Simulate and list all available thumbnail formats')
771 postproc
= optparse
.OptionGroup(parser
, 'Post-processing Options')
773 '-x', '--extract-audio',
774 action
='store_true', dest
='extractaudio', default
=False,
775 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
777 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
778 help='Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default; No effect without -x')
780 '--audio-quality', metavar
='QUALITY',
781 dest
='audioquality', default
='5',
782 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)')
785 metavar
='FORMAT', dest
='recodevideo', default
=None,
786 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
788 '--postprocessor-args',
789 dest
='postprocessor_args', metavar
='ARGS',
790 help='Give these arguments to the postprocessor')
792 '-k', '--keep-video',
793 action
='store_true', dest
='keepvideo', default
=False,
794 help='Keep the video file on disk after the post-processing; the video is erased by default')
796 '--no-post-overwrites',
797 action
='store_true', dest
='nopostoverwrites', default
=False,
798 help='Do not overwrite post-processed files; the post-processed files are overwritten by default')
801 action
='store_true', dest
='embedsubtitles', default
=False,
802 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
805 action
='store_true', dest
='embedthumbnail', default
=False,
806 help='Embed thumbnail in the audio as cover art')
809 action
='store_true', dest
='addmetadata', default
=False,
810 help='Write metadata to the video file')
812 '--metadata-from-title',
813 metavar
='FORMAT', dest
='metafromtitle',
814 help='Parse additional metadata like song title / artist from the video title. '
815 'The format syntax is the same as --output, '
816 'the parsed parameters replace existing values. '
817 'Additional templates: %(album)s, %(artist)s. '
818 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
819 '"Coldplay - Paradise"')
822 action
='store_true', dest
='xattrs', default
=False,
823 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
826 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
827 help='Automatically correct known faults of the file. '
828 'One of never (do nothing), warn (only emit a warning), '
829 'detect_or_warn (the default; fix file if we can, warn otherwise)')
832 action
='store_false', dest
='prefer_ffmpeg',
833 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
836 action
='store_true', dest
='prefer_ffmpeg',
837 help='Prefer ffmpeg over avconv for running the postprocessors')
839 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
840 dest
='ffmpeg_location',
841 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
844 metavar
='CMD', dest
='exec_cmd',
845 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
847 '--convert-subs', '--convert-subtitles',
848 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
849 help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
851 parser
.add_option_group(general
)
852 parser
.add_option_group(network
)
853 parser
.add_option_group(geo
)
854 parser
.add_option_group(selection
)
855 parser
.add_option_group(downloader
)
856 parser
.add_option_group(filesystem
)
857 parser
.add_option_group(thumbnail
)
858 parser
.add_option_group(verbosity
)
859 parser
.add_option_group(workarounds
)
860 parser
.add_option_group(video_format
)
861 parser
.add_option_group(subtitles
)
862 parser
.add_option_group(authentication
)
863 parser
.add_option_group(adobe_pass
)
864 parser
.add_option_group(postproc
)
866 if overrideArguments
is not None:
867 opts
, args
= parser
.parse_args(overrideArguments
)
869 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
871 def compat_conf(conf
):
872 if sys
.version_info
< (3,):
873 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
876 command_line_conf
= compat_conf(sys
.argv
[1:])
877 opts
, args
= parser
.parse_args(command_line_conf
)
879 system_conf
= user_conf
= custom_conf
= []
881 if '--config-location' in command_line_conf
:
882 location
= compat_expanduser(opts
.config_location
)
883 if os
.path
.isdir(location
):
884 location
= os
.path
.join(location
, 'youtube-dl.conf')
885 if not os
.path
.exists(location
):
886 parser
.error('config-location %s does not exist.' % location
)
887 custom_conf
= _readOptions(location
)
888 elif '--ignore-config' in command_line_conf
:
891 system_conf
= _readOptions('/etc/youtube-dl.conf')
892 if '--ignore-config' not in system_conf
:
893 user_conf
= _readUserConf()
895 argv
= system_conf
+ user_conf
+ custom_conf
+ command_line_conf
896 opts
, args
= parser
.parse_args(argv
)
898 for conf_label
, conf
in (
899 ('System config', system_conf
),
900 ('User config', user_conf
),
901 ('Custom config', custom_conf
),
902 ('Command-line args', command_line_conf
)):
903 write_string('[debug] %s: %s\n' % (conf_label
, repr(_hide_login_info(conf
))))
905 return parser
, opts
, args