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']
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 action
='store_const', dest
='extract_flat', const
='in_playlist',
185 help='Do not extract the videos of a playlist, only list them.')
188 action
='store_true', dest
='mark_watched', default
=False,
189 help='Mark videos watched (YouTube only)')
192 action
='store_false', dest
='mark_watched', default
=False,
193 help='Do not mark videos watched (YouTube only)')
195 '--no-color', '--no-colors',
196 action
='store_true', dest
='no_color',
198 help='Do not emit color codes in output')
200 network
= optparse
.OptionGroup(parser
, 'Network Options')
202 '--proxy', dest
='proxy',
203 default
=None, metavar
='URL',
204 help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable experimental '
205 'SOCKS proxy, specify a proper scheme. For example '
206 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
207 'for direct connection')
210 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
211 help='Time to wait before giving up, in seconds')
214 metavar
='IP', dest
='source_address', default
=None,
215 help='Client-side IP address to bind to (experimental)',
218 '-4', '--force-ipv4',
219 action
='store_const', const
='0.0.0.0', dest
='source_address',
220 help='Make all connections via IPv4 (experimental)',
223 '-6', '--force-ipv6',
224 action
='store_const', const
='::', dest
='source_address',
225 help='Make all connections via IPv6 (experimental)',
228 '--geo-verification-proxy',
229 dest
='geo_verification_proxy', default
=None, metavar
='URL',
230 help='Use this proxy to verify the IP address for some geo-restricted sites. '
231 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)'
234 '--cn-verification-proxy',
235 dest
='cn_verification_proxy', default
=None, metavar
='URL',
236 help=optparse
.SUPPRESS_HELP
,
239 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
240 selection
.add_option(
242 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
243 help='Playlist video to start at (default is %default)')
244 selection
.add_option(
246 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
247 help='Playlist video to end at (default is last)')
248 selection
.add_option(
250 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
251 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.')
252 selection
.add_option(
254 dest
='matchtitle', metavar
='REGEX',
255 help='Download only matching titles (regex or caseless sub-string)')
256 selection
.add_option(
258 dest
='rejecttitle', metavar
='REGEX',
259 help='Skip download for matching titles (regex or caseless sub-string)')
260 selection
.add_option(
262 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
263 help='Abort after downloading NUMBER files')
264 selection
.add_option(
266 metavar
='SIZE', dest
='min_filesize', default
=None,
267 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
268 selection
.add_option(
270 metavar
='SIZE', dest
='max_filesize', default
=None,
271 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
272 selection
.add_option(
274 metavar
='DATE', dest
='date', default
=None,
275 help='Download only videos uploaded in this date')
276 selection
.add_option(
278 metavar
='DATE', dest
='datebefore', default
=None,
279 help='Download only videos uploaded on or before this date (i.e. inclusive)')
280 selection
.add_option(
282 metavar
='DATE', dest
='dateafter', default
=None,
283 help='Download only videos uploaded on or after this date (i.e. inclusive)')
284 selection
.add_option(
286 metavar
='COUNT', dest
='min_views', default
=None, type=int,
287 help='Do not download any videos with less than COUNT views')
288 selection
.add_option(
290 metavar
='COUNT', dest
='max_views', default
=None, type=int,
291 help='Do not download any videos with more than COUNT views')
292 selection
.add_option(
294 metavar
='FILTER', dest
='match_filter', default
=None,
296 'Generic video filter (experimental). '
297 'Specify any key (see help for -o for a list of available keys) to'
298 ' match if the key is present, '
299 '!key to check if the key is not present,'
300 'key > NUMBER (like "comment_count > 12", also works with '
301 '>=, <, <=, !=, =) to compare against a number, and '
302 '& to require multiple matches. '
303 'Values which are not known are excluded unless you'
304 ' put a question mark (?) after the operator.'
305 'For example, to only match videos that have been liked more than '
306 '100 times and disliked less than 50 times (or the dislike '
307 'functionality is not available at the given service), but who '
308 'also have a description, use --match-filter '
309 '"like_count > 100 & dislike_count <? 50 & description" .'
311 selection
.add_option(
313 action
='store_true', dest
='noplaylist', default
=False,
314 help='Download only the video, if the URL refers to a video and a playlist.')
315 selection
.add_option(
317 action
='store_false', dest
='noplaylist', default
=False,
318 help='Download the playlist, if the URL refers to a video and a playlist.')
319 selection
.add_option(
321 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
322 help='Download only videos suitable for the given age')
323 selection
.add_option(
324 '--download-archive', metavar
='FILE',
325 dest
='download_archive',
326 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
327 selection
.add_option(
329 dest
='include_ads', action
='store_true',
330 help='Download advertisements as well (experimental)')
332 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
333 authentication
.add_option(
335 dest
='username', metavar
='USERNAME',
336 help='Login with this account ID')
337 authentication
.add_option(
339 dest
='password', metavar
='PASSWORD',
340 help='Account password. If this option is left out, youtube-dl will ask interactively.')
341 authentication
.add_option(
343 dest
='twofactor', metavar
='TWOFACTOR',
344 help='Two-factor auth code')
345 authentication
.add_option(
347 action
='store_true', dest
='usenetrc', default
=False,
348 help='Use .netrc authentication data')
349 authentication
.add_option(
351 dest
='videopassword', metavar
='PASSWORD',
352 help='Video password (vimeo, smotri, youku)')
354 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
355 video_format
.add_option(
357 action
='store', dest
='format', metavar
='FORMAT', default
=None,
358 help='Video format code, see the "FORMAT SELECTION" for all the info')
359 video_format
.add_option(
361 action
='store_const', dest
='format', const
='all',
362 help='Download all available video formats')
363 video_format
.add_option(
364 '--prefer-free-formats',
365 action
='store_true', dest
='prefer_free_formats', default
=False,
366 help='Prefer free video formats unless a specific one is requested')
367 video_format
.add_option(
368 '-F', '--list-formats',
369 action
='store_true', dest
='listformats',
370 help='List all available formats of requested videos')
371 video_format
.add_option(
372 '--youtube-include-dash-manifest',
373 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
374 help=optparse
.SUPPRESS_HELP
)
375 video_format
.add_option(
376 '--youtube-skip-dash-manifest',
377 action
='store_false', dest
='youtube_include_dash_manifest',
378 help='Do not download the DASH manifests and related data on YouTube videos')
379 video_format
.add_option(
380 '--merge-output-format',
381 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
383 'If a merge is required (e.g. bestvideo+bestaudio), '
384 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
385 'Ignored if no merge is required'))
387 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
388 subtitles
.add_option(
389 '--write-sub', '--write-srt',
390 action
='store_true', dest
='writesubtitles', default
=False,
391 help='Write subtitle file')
392 subtitles
.add_option(
393 '--write-auto-sub', '--write-automatic-sub',
394 action
='store_true', dest
='writeautomaticsub', default
=False,
395 help='Write automatically generated subtitle file (YouTube only)')
396 subtitles
.add_option(
398 action
='store_true', dest
='allsubtitles', default
=False,
399 help='Download all the available subtitles of the video')
400 subtitles
.add_option(
402 action
='store_true', dest
='listsubtitles', default
=False,
403 help='List all available subtitles for the video')
404 subtitles
.add_option(
406 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
407 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
408 subtitles
.add_option(
409 '--sub-lang', '--sub-langs', '--srt-lang',
410 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
411 default
=[], callback
=_comma_separated_values_options_callback
,
412 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
414 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
415 downloader
.add_option(
416 '-r', '--limit-rate', '--rate-limit',
417 dest
='ratelimit', metavar
='RATE',
418 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
419 downloader
.add_option(
421 dest
='retries', metavar
='RETRIES', default
=10,
422 help='Number of retries (default is %default), or "infinite".')
423 downloader
.add_option(
424 '--fragment-retries',
425 dest
='fragment_retries', metavar
='RETRIES', default
=10,
426 help='Number of retries for a fragment (default is %default), or "infinite" (DASH only)')
427 downloader
.add_option(
429 dest
='buffersize', metavar
='SIZE', default
='1024',
430 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
431 downloader
.add_option(
432 '--no-resize-buffer',
433 action
='store_true', dest
='noresizebuffer', default
=False,
434 help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
435 downloader
.add_option(
437 action
='store_true', dest
='test', default
=False,
438 help=optparse
.SUPPRESS_HELP
)
439 downloader
.add_option(
440 '--playlist-reverse',
442 help='Download playlist videos in reverse order')
443 downloader
.add_option(
444 '--xattr-set-filesize',
445 dest
='xattr_set_filesize', action
='store_true',
446 help='Set file xattribute ytdl.filesize with expected filesize (experimental)')
447 downloader
.add_option(
448 '--hls-prefer-native',
449 dest
='hls_prefer_native', action
='store_true', default
=None,
450 help='Use the native HLS downloader instead of ffmpeg')
451 downloader
.add_option(
452 '--hls-prefer-ffmpeg',
453 dest
='hls_prefer_native', action
='store_false', default
=None,
454 help='Use ffmpeg instead of the native HLS downloader')
455 downloader
.add_option(
457 dest
='hls_use_mpegts', action
='store_true',
458 help='Use the mpegts container for HLS videos, allowing to play the '
459 'video while downloading (some players may not be able to play it)')
460 downloader
.add_option(
461 '--external-downloader',
462 dest
='external_downloader', metavar
='COMMAND',
463 help='Use the specified external downloader. '
464 'Currently supports %s' % ','.join(list_external_downloaders()))
465 downloader
.add_option(
466 '--external-downloader-args',
467 dest
='external_downloader_args', metavar
='ARGS',
468 help='Give these arguments to the external downloader')
470 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
471 workarounds
.add_option(
473 dest
='encoding', metavar
='ENCODING',
474 help='Force the specified encoding (experimental)')
475 workarounds
.add_option(
476 '--no-check-certificate',
477 action
='store_true', dest
='no_check_certificate', default
=False,
478 help='Suppress HTTPS certificate validation')
479 workarounds
.add_option(
481 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
482 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
483 workarounds
.add_option(
485 metavar
='UA', dest
='user_agent',
486 help='Specify a custom user agent')
487 workarounds
.add_option(
489 metavar
='URL', dest
='referer', default
=None,
490 help='Specify a custom referer, use if the video access is restricted to one domain',
492 workarounds
.add_option(
494 metavar
='FIELD:VALUE', dest
='headers', action
='append',
495 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
497 workarounds
.add_option(
499 dest
='bidi_workaround', action
='store_true',
500 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
501 workarounds
.add_option(
502 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
503 dest
='sleep_interval', type=float,
505 'Number of seconds to sleep before each download when used alone '
506 'or a lower bound of a range for randomized sleep before each download '
507 '(minimum possible number of seconds to sleep) when used along with '
508 '--max-sleep-interval.'))
509 workarounds
.add_option(
510 '--max-sleep-interval', metavar
='SECONDS',
511 dest
='max_sleep_interval', type=float,
513 'Upper bound of a range for randomized sleep before each download '
514 '(maximum possible number of seconds to sleep). Must only be used '
515 'along with --min-sleep-interval.'))
517 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
518 verbosity
.add_option(
520 action
='store_true', dest
='quiet', default
=False,
521 help='Activate quiet mode')
522 verbosity
.add_option(
524 dest
='no_warnings', action
='store_true', default
=False,
525 help='Ignore warnings')
526 verbosity
.add_option(
528 action
='store_true', dest
='simulate', default
=False,
529 help='Do not download the video and do not write anything to disk')
530 verbosity
.add_option(
532 action
='store_true', dest
='skip_download', default
=False,
533 help='Do not download the video')
534 verbosity
.add_option(
536 action
='store_true', dest
='geturl', default
=False,
537 help='Simulate, quiet but print URL')
538 verbosity
.add_option(
540 action
='store_true', dest
='gettitle', default
=False,
541 help='Simulate, quiet but print title')
542 verbosity
.add_option(
544 action
='store_true', dest
='getid', default
=False,
545 help='Simulate, quiet but print id')
546 verbosity
.add_option(
548 action
='store_true', dest
='getthumbnail', default
=False,
549 help='Simulate, quiet but print thumbnail URL')
550 verbosity
.add_option(
552 action
='store_true', dest
='getdescription', default
=False,
553 help='Simulate, quiet but print video description')
554 verbosity
.add_option(
556 action
='store_true', dest
='getduration', default
=False,
557 help='Simulate, quiet but print video length')
558 verbosity
.add_option(
560 action
='store_true', dest
='getfilename', default
=False,
561 help='Simulate, quiet but print output filename')
562 verbosity
.add_option(
564 action
='store_true', dest
='getformat', default
=False,
565 help='Simulate, quiet but print output format')
566 verbosity
.add_option(
568 action
='store_true', dest
='dumpjson', default
=False,
569 help='Simulate, quiet but print JSON information. See --output for a description of available keys.')
570 verbosity
.add_option(
571 '-J', '--dump-single-json',
572 action
='store_true', dest
='dump_single_json', default
=False,
573 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.')
574 verbosity
.add_option(
576 action
='store_true', dest
='print_json', default
=False,
577 help='Be quiet and print the video information as JSON (video is still being downloaded).',
579 verbosity
.add_option(
581 action
='store_true', dest
='progress_with_newline', default
=False,
582 help='Output progress bar as new lines')
583 verbosity
.add_option(
585 action
='store_true', dest
='noprogress', default
=False,
586 help='Do not print progress bar')
587 verbosity
.add_option(
589 action
='store_true', dest
='consoletitle', default
=False,
590 help='Display progress in console titlebar')
591 verbosity
.add_option(
593 action
='store_true', dest
='verbose', default
=False,
594 help='Print various debugging information')
595 verbosity
.add_option(
596 '--dump-pages', '--dump-intermediate-pages',
597 action
='store_true', dest
='dump_intermediate_pages', default
=False,
598 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
599 verbosity
.add_option(
601 action
='store_true', dest
='write_pages', default
=False,
602 help='Write downloaded intermediary pages to files in the current directory to debug problems')
603 verbosity
.add_option(
604 '--youtube-print-sig-code',
605 action
='store_true', dest
='youtube_print_sig_code', default
=False,
606 help=optparse
.SUPPRESS_HELP
)
607 verbosity
.add_option(
608 '--print-traffic', '--dump-headers',
609 dest
='debug_printtraffic', action
='store_true', default
=False,
610 help='Display sent and read HTTP traffic')
611 verbosity
.add_option(
613 dest
='call_home', action
='store_true', default
=False,
614 help='Contact the youtube-dl server for debugging')
615 verbosity
.add_option(
617 dest
='call_home', action
='store_false', default
=False,
618 help='Do NOT contact the youtube-dl server for debugging')
620 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
621 filesystem
.add_option(
622 '-a', '--batch-file',
623 dest
='batchfile', metavar
='FILE',
624 help='File containing URLs to download (\'-\' for stdin)')
625 filesystem
.add_option(
626 '--id', default
=False,
627 action
='store_true', dest
='useid', help='Use only video ID in file name')
628 filesystem
.add_option(
630 dest
='outtmpl', metavar
='TEMPLATE',
631 help=('Output filename template. Use %(title)s to get the title, '
632 '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
633 '%(autonumber)s to get an automatically incremented number, '
634 '%(ext)s for the filename extension, '
635 '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
636 '%(format_id)s for the unique id of the format (like YouTube\'s itags: "137"), '
637 '%(upload_date)s for the upload date (YYYYMMDD), '
638 '%(extractor)s for the provider (youtube, metacafe, etc), '
639 '%(id)s for the video id, '
640 '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
641 '%(playlist_index)s for the position in the playlist. '
642 '%(height)s and %(width)s for the width and height of the video format. '
643 '%(resolution)s for a textual description of the resolution of the video format. '
644 '%% for a literal percent. '
645 'Use - to output to stdout. Can also be used to download to a different directory, '
646 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
647 filesystem
.add_option(
649 dest
='autonumber_size', metavar
='NUMBER',
650 help='Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
651 filesystem
.add_option(
652 '--restrict-filenames',
653 action
='store_true', dest
='restrictfilenames', default
=False,
654 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
655 filesystem
.add_option(
656 '-A', '--auto-number',
657 action
='store_true', dest
='autonumber', default
=False,
658 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] Number downloaded files starting from 00000')
659 filesystem
.add_option(
661 action
='store_true', dest
='usetitle', default
=False,
662 help='[deprecated] Use title in file name (default)')
663 filesystem
.add_option(
664 '-l', '--literal', default
=False,
665 action
='store_true', dest
='usetitle',
666 help='[deprecated] Alias of --title')
667 filesystem
.add_option(
668 '-w', '--no-overwrites',
669 action
='store_true', dest
='nooverwrites', default
=False,
670 help='Do not overwrite files')
671 filesystem
.add_option(
673 action
='store_true', dest
='continue_dl', default
=True,
674 help='Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
675 filesystem
.add_option(
677 action
='store_false', dest
='continue_dl',
678 help='Do not resume partially downloaded files (restart from beginning)')
679 filesystem
.add_option(
681 action
='store_true', dest
='nopart', default
=False,
682 help='Do not use .part files - write directly into output file')
683 filesystem
.add_option(
685 action
='store_false', dest
='updatetime', default
=True,
686 help='Do not use the Last-modified header to set the file modification time')
687 filesystem
.add_option(
688 '--write-description',
689 action
='store_true', dest
='writedescription', default
=False,
690 help='Write video description to a .description file')
691 filesystem
.add_option(
693 action
='store_true', dest
='writeinfojson', default
=False,
694 help='Write video metadata to a .info.json file')
695 filesystem
.add_option(
696 '--write-annotations',
697 action
='store_true', dest
='writeannotations', default
=False,
698 help='Write video annotations to a .annotations.xml file')
699 filesystem
.add_option(
700 '--load-info-json', '--load-info',
701 dest
='load_info_filename', metavar
='FILE',
702 help='JSON file containing the video information (created with the "--write-info-json" option)')
703 filesystem
.add_option(
705 dest
='cookiefile', metavar
='FILE',
706 help='File to read cookies from and dump cookie jar in')
707 filesystem
.add_option(
708 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
709 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.')
710 filesystem
.add_option(
711 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
712 help='Disable filesystem caching')
713 filesystem
.add_option(
715 action
='store_true', dest
='rm_cachedir',
716 help='Delete all filesystem cache files')
718 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
719 thumbnail
.add_option(
721 action
='store_true', dest
='writethumbnail', default
=False,
722 help='Write thumbnail image to disk')
723 thumbnail
.add_option(
724 '--write-all-thumbnails',
725 action
='store_true', dest
='write_all_thumbnails', default
=False,
726 help='Write all thumbnail image formats to disk')
727 thumbnail
.add_option(
729 action
='store_true', dest
='list_thumbnails', default
=False,
730 help='Simulate and list all available thumbnail formats')
732 postproc
= optparse
.OptionGroup(parser
, 'Post-processing Options')
734 '-x', '--extract-audio',
735 action
='store_true', dest
='extractaudio', default
=False,
736 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
738 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
739 help='Specify audio format: "best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
741 '--audio-quality', metavar
='QUALITY',
742 dest
='audioquality', default
='5',
743 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)')
746 metavar
='FORMAT', dest
='recodevideo', default
=None,
747 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
749 '--postprocessor-args',
750 dest
='postprocessor_args', metavar
='ARGS',
751 help='Give these arguments to the postprocessor')
753 '-k', '--keep-video',
754 action
='store_true', dest
='keepvideo', default
=False,
755 help='Keep the video file on disk after the post-processing; the video is erased by default')
757 '--no-post-overwrites',
758 action
='store_true', dest
='nopostoverwrites', default
=False,
759 help='Do not overwrite post-processed files; the post-processed files are overwritten by default')
762 action
='store_true', dest
='embedsubtitles', default
=False,
763 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
766 action
='store_true', dest
='embedthumbnail', default
=False,
767 help='Embed thumbnail in the audio as cover art')
770 action
='store_true', dest
='addmetadata', default
=False,
771 help='Write metadata to the video file')
773 '--metadata-from-title',
774 metavar
='FORMAT', dest
='metafromtitle',
775 help='Parse additional metadata like song title / artist from the video title. '
776 'The format syntax is the same as --output, '
777 'the parsed parameters replace existing values. '
778 'Additional templates: %(album)s, %(artist)s. '
779 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
780 '"Coldplay - Paradise"')
783 action
='store_true', dest
='xattrs', default
=False,
784 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
787 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
788 help='Automatically correct known faults of the file. '
789 'One of never (do nothing), warn (only emit a warning), '
790 'detect_or_warn (the default; fix file if we can, warn otherwise)')
793 action
='store_false', dest
='prefer_ffmpeg',
794 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
797 action
='store_true', dest
='prefer_ffmpeg',
798 help='Prefer ffmpeg over avconv for running the postprocessors')
800 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
801 dest
='ffmpeg_location',
802 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
805 metavar
='CMD', dest
='exec_cmd',
806 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
808 '--convert-subs', '--convert-subtitles',
809 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
810 help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
812 parser
.add_option_group(general
)
813 parser
.add_option_group(network
)
814 parser
.add_option_group(selection
)
815 parser
.add_option_group(downloader
)
816 parser
.add_option_group(filesystem
)
817 parser
.add_option_group(thumbnail
)
818 parser
.add_option_group(verbosity
)
819 parser
.add_option_group(workarounds
)
820 parser
.add_option_group(video_format
)
821 parser
.add_option_group(subtitles
)
822 parser
.add_option_group(authentication
)
823 parser
.add_option_group(postproc
)
825 if overrideArguments
is not None:
826 opts
, args
= parser
.parse_args(overrideArguments
)
828 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
830 def compat_conf(conf
):
831 if sys
.version_info
< (3,):
832 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
835 command_line_conf
= compat_conf(sys
.argv
[1:])
837 if '--ignore-config' in command_line_conf
:
841 system_conf
= _readOptions('/etc/youtube-dl.conf')
842 if '--ignore-config' in system_conf
:
845 user_conf
= _readUserConf()
846 argv
= system_conf
+ user_conf
+ command_line_conf
848 opts
, args
= parser
.parse_args(argv
)
850 write_string('[debug] System config: ' + repr(_hide_login_info(system_conf
)) + '\n')
851 write_string('[debug] User config: ' + repr(_hide_login_info(user_conf
)) + '\n')
852 write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf
)) + '\n')
854 return parser
, opts
, args