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