1 from __future__
import unicode_literals
8 from .downloader
.external
import list_external_downloaders
11 compat_get_terminal_size
,
19 from .version
import __version__
22 def parseOpts(overrideArguments
=None):
23 def _readOptions(filename_bytes
, default
=[]):
25 optionf
= open(filename_bytes
)
27 return default
# silently skip if file is not present
31 res
+= shlex
.split(l
, comments
=True)
37 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME')
39 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl', 'config')
40 if not os
.path
.isfile(userConfFile
):
41 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dl.conf')
43 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl', 'config')
44 if not os
.path
.isfile(userConfFile
):
45 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dl.conf')
46 userConf
= _readOptions(userConfFile
, None)
49 appdata_dir
= compat_getenv('appdata')
51 userConf
= _readOptions(
52 os
.path
.join(appdata_dir
, 'youtube-dl', 'config'),
55 userConf
= _readOptions(
56 os
.path
.join(appdata_dir
, 'youtube-dl', 'config.txt'),
60 userConf
= _readOptions(
61 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf'),
64 userConf
= _readOptions(
65 os
.path
.join(compat_expanduser('~'), 'youtube-dl.conf.txt'),
73 def _format_option_string(option
):
74 ''' ('-o', '--option') -> -o, --format METAVAR'''
78 if option
._short
_opts
:
79 opts
.append(option
._short
_opts
[0])
81 opts
.append(option
._long
_opts
[0])
85 if option
.takes_value():
86 opts
.append(' %s' % option
.metavar
)
90 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
91 setattr(parser
.values
, option
.dest
, value
.split(','))
93 def _hide_login_info(opts
):
95 for private_opt
in ['-p', '--password', '-u', '--username', '--video-password']:
97 i
= opts
.index(private_opt
)
98 opts
[i
+ 1] = 'PRIVATE'
103 # No need to wrap help messages if we're on a wide console
104 columns
= compat_get_terminal_size().columns
105 max_width
= columns
if columns
else 80
106 max_help_position
= 80
108 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
109 fmt
.format_option_strings
= _format_option_string
112 'version': __version__
,
114 'usage': '%prog [OPTIONS] URL [URL...]',
115 'conflict_handler': 'resolve',
118 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
120 general
= optparse
.OptionGroup(parser
, 'General Options')
124 help='print this help text and exit')
128 help='print program version and exit')
131 action
='store_true', dest
='update_self',
132 help='update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
134 '-i', '--ignore-errors',
135 action
='store_true', dest
='ignoreerrors', default
=False,
136 help='continue on download errors, for example to skip unavailable videos in a playlist')
139 action
='store_false', dest
='ignoreerrors',
140 help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
143 action
='store_true', dest
='dump_user_agent', default
=False,
144 help='display the current browser identification')
147 action
='store_true', dest
='list_extractors', default
=False,
148 help='List all supported extractors and the URLs they would handle')
150 '--extractor-descriptions',
151 action
='store_true', dest
='list_extractor_descriptions', default
=False,
152 help='Output descriptions of all supported extractors')
155 dest
='default_search', metavar
='PREFIX',
156 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.')
160 help='Do not read configuration files. '
161 'When given in the global configuration file /etc/youtube-dl.conf: '
162 'Do not read the user configuration in ~/.config/youtube-dl/config '
163 '(%APPDATA%/youtube-dl/config.txt on Windows)')
166 action
='store_const', dest
='extract_flat', const
='in_playlist',
168 help='Do not extract the videos of a playlist, only list them.')
170 '--no-color', '--no-colors',
171 action
='store_true', dest
='no_color',
173 help='Do not emit color codes in output.')
175 network
= optparse
.OptionGroup(parser
, 'Network Options')
177 '--proxy', dest
='proxy',
178 default
=None, metavar
='URL',
179 help='Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy "") for direct connection')
182 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
183 help='Time to wait before giving up, in seconds')
186 metavar
='IP', dest
='source_address', default
=None,
187 help='Client-side IP address to bind to (experimental)',
190 '-4', '--force-ipv4',
191 action
='store_const', const
='0.0.0.0', dest
='source_address',
192 help='Make all connections via IPv4 (experimental)',
195 '-6', '--force-ipv6',
196 action
='store_const', const
='::', dest
='source_address',
197 help='Make all connections via IPv6 (experimental)',
200 '--cn-verification-proxy',
201 dest
='cn_verification_proxy', default
=None, metavar
='URL',
202 help='Use this proxy to verify the IP address for some Chinese sites. '
203 'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)'
206 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
207 selection
.add_option(
209 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
210 help='playlist video to start at (default is %default)')
211 selection
.add_option(
213 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
214 help='playlist video to end at (default is last)')
215 selection
.add_option(
217 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
218 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.')
219 selection
.add_option(
221 dest
='matchtitle', metavar
='REGEX',
222 help='download only matching titles (regex or caseless sub-string)')
223 selection
.add_option(
225 dest
='rejecttitle', metavar
='REGEX',
226 help='skip download for matching titles (regex or caseless sub-string)')
227 selection
.add_option(
229 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
230 help='Abort after downloading NUMBER files')
231 selection
.add_option(
233 metavar
='SIZE', dest
='min_filesize', default
=None,
234 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
235 selection
.add_option(
237 metavar
='SIZE', dest
='max_filesize', default
=None,
238 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
239 selection
.add_option(
241 metavar
='DATE', dest
='date', default
=None,
242 help='download only videos uploaded in this date')
243 selection
.add_option(
245 metavar
='DATE', dest
='datebefore', default
=None,
246 help='download only videos uploaded on or before this date (i.e. inclusive)')
247 selection
.add_option(
249 metavar
='DATE', dest
='dateafter', default
=None,
250 help='download only videos uploaded on or after this date (i.e. inclusive)')
251 selection
.add_option(
253 metavar
='COUNT', dest
='min_views', default
=None, type=int,
254 help='Do not download any videos with less than COUNT views',)
255 selection
.add_option(
257 metavar
='COUNT', dest
='max_views', default
=None, type=int,
258 help='Do not download any videos with more than COUNT views')
259 selection
.add_option(
261 metavar
='FILTER', dest
='match_filter', default
=None,
263 '(Experimental) Generic video filter. '
264 'Specify any key (see help for -o for a list of available keys) to'
265 ' match if the key is present, '
266 '!key to check if the key is not present,'
267 'key > NUMBER (like "comment_count > 12", also works with '
268 '>=, <, <=, !=, =) to compare against a number, and '
269 '& to require multiple matches. '
270 'Values which are not known are excluded unless you'
271 ' put a question mark (?) after the operator.'
272 'For example, to only match videos that have been liked more than '
273 '100 times and disliked less than 50 times (or the dislike '
274 'functionality is not available at the given service), but who '
275 'also have a description, use --match-filter '
276 '"like_count > 100 & dislike_count <? 50 & description" .'
278 selection
.add_option(
280 action
='store_true', dest
='noplaylist', default
=False,
281 help='If the URL refers to a video and a playlist, download only the video.')
282 selection
.add_option(
284 action
='store_false', dest
='noplaylist', default
=False,
285 help='If the URL refers to a video and a playlist, download the playlist.')
286 selection
.add_option(
288 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
289 help='download only videos suitable for the given age')
290 selection
.add_option(
291 '--download-archive', metavar
='FILE',
292 dest
='download_archive',
293 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
294 selection
.add_option(
296 dest
='include_ads', action
='store_true',
297 help='Download advertisements as well (experimental)')
299 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
300 authentication
.add_option(
302 dest
='username', metavar
='USERNAME',
303 help='login with this account ID')
304 authentication
.add_option(
306 dest
='password', metavar
='PASSWORD',
307 help='account password. If this option is left out, youtube-dl will ask interactively.')
308 authentication
.add_option(
310 dest
='twofactor', metavar
='TWOFACTOR',
311 help='two-factor auth code')
312 authentication
.add_option(
314 action
='store_true', dest
='usenetrc', default
=False,
315 help='use .netrc authentication data')
316 authentication
.add_option(
318 dest
='videopassword', metavar
='PASSWORD',
319 help='video password (vimeo, smotri)')
321 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
322 video_format
.add_option(
324 action
='store', dest
='format', metavar
='FORMAT', default
=None,
326 'video format code, specify the order of preference using'
327 ' slashes, as in -f 22/17/18 . '
328 ' Instead of format codes, you can select by extension for the '
329 'extensions aac, m4a, mp3, mp4, ogg, wav, webm. '
330 'You can also use the special names "best",'
331 ' "bestvideo", "bestaudio", "worst". '
332 ' You can filter the video results by putting a condition in'
333 ' brackets, as in -f "best[height=720]"'
334 ' (or -f "[filesize>10M]"). '
335 ' This works for filesize, height, width, tbr, abr, vbr, asr, and fps'
336 ' and the comparisons <, <=, >, >=, =, !='
337 ' and for ext, acodec, vcodec, container, and protocol'
338 ' and the comparisons =, != .'
339 ' Formats for which the value is not known are excluded unless you'
340 ' put a question mark (?) after the operator.'
341 ' You can combine format filters, so '
342 '-f "[height <=? 720][tbr>500]" '
343 'selects up to 720p videos (or videos where the height is not '
344 'known) with a bitrate of at least 500 KBit/s.'
345 ' By default, youtube-dl will pick the best quality.'
346 ' Use commas to download multiple audio formats, such as'
347 ' -f 136/137/mp4/bestvideo,140/m4a/bestaudio.'
348 ' You can merge the video and audio of two formats into a single'
349 ' file using -f <video-format>+<audio-format> (requires ffmpeg or'
350 ' avconv), for example -f bestvideo+bestaudio.'))
351 video_format
.add_option(
353 action
='store_const', dest
='format', const
='all',
354 help='download all available video formats')
355 video_format
.add_option(
356 '--prefer-free-formats',
357 action
='store_true', dest
='prefer_free_formats', default
=False,
358 help='prefer free video formats unless a specific one is requested')
359 video_format
.add_option(
361 action
='store', dest
='format_limit', metavar
='FORMAT',
362 help='highest quality format to download')
363 video_format
.add_option(
364 '-F', '--list-formats',
365 action
='store_true', dest
='listformats',
366 help='list all available formats')
367 video_format
.add_option(
368 '--youtube-include-dash-manifest',
369 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
370 help=optparse
.SUPPRESS_HELP
)
371 video_format
.add_option(
372 '--youtube-skip-dash-manifest',
373 action
='store_false', dest
='youtube_include_dash_manifest',
374 help='Do not download the DASH manifest on YouTube videos')
375 video_format
.add_option(
376 '--merge-output-format',
377 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
379 'If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv.'
380 'Ignored if no merge is required'))
382 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
383 subtitles
.add_option(
384 '--write-sub', '--write-srt',
385 action
='store_true', dest
='writesubtitles', default
=False,
386 help='write subtitle file')
387 subtitles
.add_option(
388 '--write-auto-sub', '--write-automatic-sub',
389 action
='store_true', dest
='writeautomaticsub', default
=False,
390 help='write automatic subtitle file (youtube only)')
391 subtitles
.add_option(
393 action
='store_true', dest
='allsubtitles', default
=False,
394 help='downloads all the available subtitles of the video')
395 subtitles
.add_option(
397 action
='store_true', dest
='listsubtitles', default
=False,
398 help='lists all available subtitles for the video')
399 subtitles
.add_option(
401 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
402 help='subtitle format, accepts formats preference, for example: "ass/srt/best"')
403 subtitles
.add_option(
404 '--sub-lang', '--sub-langs', '--srt-lang',
405 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
406 default
=[], callback
=_comma_separated_values_options_callback
,
407 help='languages of the subtitles to download (optional) separated by commas, use IETF language tags like \'en,pt\'')
409 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
410 downloader
.add_option(
411 '-r', '--rate-limit',
412 dest
='ratelimit', metavar
='LIMIT',
413 help='maximum download rate in bytes per second (e.g. 50K or 4.2M)')
414 downloader
.add_option(
416 dest
='retries', metavar
='RETRIES', default
=10,
417 help='number of retries (default is %default), or "infinite".')
418 downloader
.add_option(
420 dest
='buffersize', metavar
='SIZE', default
='1024',
421 help='size of download buffer (e.g. 1024 or 16K) (default is %default)')
422 downloader
.add_option(
423 '--no-resize-buffer',
424 action
='store_true', dest
='noresizebuffer', default
=False,
425 help='do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
426 downloader
.add_option(
428 action
='store_true', dest
='test', default
=False,
429 help=optparse
.SUPPRESS_HELP
)
430 downloader
.add_option(
431 '--playlist-reverse',
433 help='Download playlist videos in reverse order')
434 downloader
.add_option(
435 '--xattr-set-filesize',
436 dest
='xattr_set_filesize', action
='store_true',
437 help='(experimental) set file xattribute ytdl.filesize with expected filesize')
438 downloader
.add_option(
439 '--hls-prefer-native',
440 dest
='hls_prefer_native', action
='store_true',
441 help='(experimental) Use the native HLS downloader instead of ffmpeg.')
442 downloader
.add_option(
443 '--external-downloader',
444 dest
='external_downloader', metavar
='COMMAND',
445 help='Use the specified external downloader. '
446 'Currently supports %s' % ','.join(list_external_downloaders()))
447 downloader
.add_option(
448 '--external-downloader-args',
449 dest
='external_downloader_args', metavar
='ARGS',
450 help='Give these arguments to the external downloader.')
452 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
453 workarounds
.add_option(
455 dest
='encoding', metavar
='ENCODING',
456 help='Force the specified encoding (experimental)')
457 workarounds
.add_option(
458 '--no-check-certificate',
459 action
='store_true', dest
='no_check_certificate', default
=False,
460 help='Suppress HTTPS certificate validation.')
461 workarounds
.add_option(
463 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
464 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
465 workarounds
.add_option(
467 metavar
='UA', dest
='user_agent',
468 help='specify a custom user agent')
469 workarounds
.add_option(
471 metavar
='URL', dest
='referer', default
=None,
472 help='specify a custom referer, use if the video access is restricted to one domain',
474 workarounds
.add_option(
476 metavar
='FIELD:VALUE', dest
='headers', action
='append',
477 help='specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
479 workarounds
.add_option(
481 dest
='bidi_workaround', action
='store_true',
482 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
483 workarounds
.add_option(
484 '--sleep-interval', metavar
='SECONDS',
485 dest
='sleep_interval', type=float,
486 help='Number of seconds to sleep before each download.')
488 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
489 verbosity
.add_option(
491 action
='store_true', dest
='quiet', default
=False,
492 help='activates quiet mode')
493 verbosity
.add_option(
495 dest
='no_warnings', action
='store_true', default
=False,
496 help='Ignore warnings')
497 verbosity
.add_option(
499 action
='store_true', dest
='simulate', default
=False,
500 help='do not download the video and do not write anything to disk',)
501 verbosity
.add_option(
503 action
='store_true', dest
='skip_download', default
=False,
504 help='do not download the video',)
505 verbosity
.add_option(
507 action
='store_true', dest
='geturl', default
=False,
508 help='simulate, quiet but print URL')
509 verbosity
.add_option(
511 action
='store_true', dest
='gettitle', default
=False,
512 help='simulate, quiet but print title')
513 verbosity
.add_option(
515 action
='store_true', dest
='getid', default
=False,
516 help='simulate, quiet but print id')
517 verbosity
.add_option(
519 action
='store_true', dest
='getthumbnail', default
=False,
520 help='simulate, quiet but print thumbnail URL')
521 verbosity
.add_option(
523 action
='store_true', dest
='getdescription', default
=False,
524 help='simulate, quiet but print video description')
525 verbosity
.add_option(
527 action
='store_true', dest
='getduration', default
=False,
528 help='simulate, quiet but print video length')
529 verbosity
.add_option(
531 action
='store_true', dest
='getfilename', default
=False,
532 help='simulate, quiet but print output filename')
533 verbosity
.add_option(
535 action
='store_true', dest
='getformat', default
=False,
536 help='simulate, quiet but print output format')
537 verbosity
.add_option(
539 action
='store_true', dest
='dumpjson', default
=False,
540 help='simulate, quiet but print JSON information. See --output for a description of available keys.')
541 verbosity
.add_option(
542 '-J', '--dump-single-json',
543 action
='store_true', dest
='dump_single_json', default
=False,
544 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.')
545 verbosity
.add_option(
547 action
='store_true', dest
='print_json', default
=False,
548 help='Be quiet and print the video information as JSON (video is still being downloaded).',
550 verbosity
.add_option(
552 action
='store_true', dest
='progress_with_newline', default
=False,
553 help='output progress bar as new lines')
554 verbosity
.add_option(
556 action
='store_true', dest
='noprogress', default
=False,
557 help='do not print progress bar')
558 verbosity
.add_option(
560 action
='store_true', dest
='consoletitle', default
=False,
561 help='display progress in console titlebar')
562 verbosity
.add_option(
564 action
='store_true', dest
='verbose', default
=False,
565 help='print various debugging information')
566 verbosity
.add_option(
567 '--dump-pages', '--dump-intermediate-pages',
568 action
='store_true', dest
='dump_intermediate_pages', default
=False,
569 help='print downloaded pages to debug problems (very verbose)')
570 verbosity
.add_option(
572 action
='store_true', dest
='write_pages', default
=False,
573 help='Write downloaded intermediary pages to files in the current directory to debug problems')
574 verbosity
.add_option(
575 '--youtube-print-sig-code',
576 action
='store_true', dest
='youtube_print_sig_code', default
=False,
577 help=optparse
.SUPPRESS_HELP
)
578 verbosity
.add_option(
579 '--print-traffic', '--dump-headers',
580 dest
='debug_printtraffic', action
='store_true', default
=False,
581 help='Display sent and read HTTP traffic')
582 verbosity
.add_option(
584 dest
='call_home', action
='store_true', default
=False,
585 help='Contact the youtube-dl server for debugging.')
586 verbosity
.add_option(
588 dest
='call_home', action
='store_false', default
=False,
589 help='Do NOT contact the youtube-dl server for debugging.')
591 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
592 filesystem
.add_option(
593 '-a', '--batch-file',
594 dest
='batchfile', metavar
='FILE',
595 help='file containing URLs to download (\'-\' for stdin)')
596 filesystem
.add_option(
597 '--id', default
=False,
598 action
='store_true', dest
='useid', help='use only video ID in file name')
599 filesystem
.add_option(
601 dest
='outtmpl', metavar
='TEMPLATE',
602 help=('output filename template. Use %(title)s to get the title, '
603 '%(uploader)s for the uploader name, %(uploader_id)s for the uploader nickname if different, '
604 '%(autonumber)s to get an automatically incremented number, '
605 '%(ext)s for the filename extension, '
606 '%(format)s for the format description (like "22 - 1280x720" or "HD"), '
607 '%(format_id)s for the unique id of the format (like Youtube\'s itags: "137"), '
608 '%(upload_date)s for the upload date (YYYYMMDD), '
609 '%(extractor)s for the provider (youtube, metacafe, etc), '
610 '%(id)s for the video id, '
611 '%(playlist_title)s, %(playlist_id)s, or %(playlist)s (=title if present, ID otherwise) for the playlist the video is in, '
612 '%(playlist_index)s for the position in the playlist. '
613 '%(height)s and %(width)s for the width and height of the video format. '
614 '%(resolution)s for a textual description of the resolution of the video format. '
615 '%% for a literal percent. '
616 'Use - to output to stdout. Can also be used to download to a different directory, '
617 'for example with -o \'/my/downloads/%(uploader)s/%(title)s-%(id)s.%(ext)s\' .'))
618 filesystem
.add_option(
620 dest
='autonumber_size', metavar
='NUMBER',
621 help='Specifies the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given')
622 filesystem
.add_option(
623 '--restrict-filenames',
624 action
='store_true', dest
='restrictfilenames', default
=False,
625 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
626 filesystem
.add_option(
627 '-A', '--auto-number',
628 action
='store_true', dest
='autonumber', default
=False,
629 help='[deprecated; use -o "%(autonumber)s-%(title)s.%(ext)s" ] number downloaded files starting from 00000')
630 filesystem
.add_option(
632 action
='store_true', dest
='usetitle', default
=False,
633 help='[deprecated] use title in file name (default)')
634 filesystem
.add_option(
635 '-l', '--literal', default
=False,
636 action
='store_true', dest
='usetitle',
637 help='[deprecated] alias of --title')
638 filesystem
.add_option(
639 '-w', '--no-overwrites',
640 action
='store_true', dest
='nooverwrites', default
=False,
641 help='do not overwrite files')
642 filesystem
.add_option(
644 action
='store_true', dest
='continue_dl', default
=True,
645 help='force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible.')
646 filesystem
.add_option(
648 action
='store_false', dest
='continue_dl',
649 help='do not resume partially downloaded files (restart from beginning)')
650 filesystem
.add_option(
652 action
='store_true', dest
='nopart', default
=False,
653 help='do not use .part files - write directly into output file')
654 filesystem
.add_option(
656 action
='store_false', dest
='updatetime', default
=True,
657 help='do not use the Last-modified header to set the file modification time')
658 filesystem
.add_option(
659 '--write-description',
660 action
='store_true', dest
='writedescription', default
=False,
661 help='write video description to a .description file')
662 filesystem
.add_option(
664 action
='store_true', dest
='writeinfojson', default
=False,
665 help='write video metadata to a .info.json file')
666 filesystem
.add_option(
667 '--write-annotations',
668 action
='store_true', dest
='writeannotations', default
=False,
669 help='write video annotations to a .annotation file')
670 filesystem
.add_option(
672 dest
='load_info_filename', metavar
='FILE',
673 help='json file containing the video information (created with the "--write-json" option)')
674 filesystem
.add_option(
676 dest
='cookiefile', metavar
='FILE',
677 help='file to read cookies from and dump cookie jar in')
678 filesystem
.add_option(
679 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
680 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.')
681 filesystem
.add_option(
682 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
683 help='Disable filesystem caching')
684 filesystem
.add_option(
686 action
='store_true', dest
='rm_cachedir',
687 help='Delete all filesystem cache files')
689 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
690 thumbnail
.add_option(
692 action
='store_true', dest
='writethumbnail', default
=False,
693 help='write thumbnail image to disk')
694 thumbnail
.add_option(
695 '--write-all-thumbnails',
696 action
='store_true', dest
='write_all_thumbnails', default
=False,
697 help='write all thumbnail image formats to disk')
698 thumbnail
.add_option(
700 action
='store_true', dest
='list_thumbnails', default
=False,
701 help='Simulate and list all available thumbnail formats')
703 postproc
= optparse
.OptionGroup(parser
, 'Post-processing Options')
705 '-x', '--extract-audio',
706 action
='store_true', dest
='extractaudio', default
=False,
707 help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
709 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
710 help='"best", "aac", "vorbis", "mp3", "m4a", "opus", or "wav"; "%default" by default')
712 '--audio-quality', metavar
='QUALITY',
713 dest
='audioquality', default
='5',
714 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)')
717 metavar
='FORMAT', dest
='recodevideo', default
=None,
718 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv)')
720 '-k', '--keep-video',
721 action
='store_true', dest
='keepvideo', default
=False,
722 help='keeps the video file on disk after the post-processing; the video is erased by default')
724 '--no-post-overwrites',
725 action
='store_true', dest
='nopostoverwrites', default
=False,
726 help='do not overwrite post-processed files; the post-processed files are overwritten by default')
729 action
='store_true', dest
='embedsubtitles', default
=False,
730 help='embed subtitles in the video (only for mp4 videos)')
733 action
='store_true', dest
='embedthumbnail', default
=False,
734 help='embed thumbnail in the audio as cover art')
737 action
='store_true', dest
='addmetadata', default
=False,
738 help='write metadata to the video file')
740 '--metadata-from-title',
741 metavar
='FORMAT', dest
='metafromtitle',
742 help='parse additional metadata like song title / artist from the video title. '
743 'The format syntax is the same as --output, '
744 'the parsed parameters replace existing values. '
745 'Additional templates: %(album), %(artist). '
746 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
747 '"Coldplay - Paradise"')
750 action
='store_true', dest
='xattrs', default
=False,
751 help='write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
754 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
755 help='Automatically correct known faults of the file. '
756 'One of never (do nothing), warn (only emit a warning), '
757 'detect_or_warn(the default; fix file if we can, warn otherwise)')
760 action
='store_false', dest
='prefer_ffmpeg',
761 help='Prefer avconv over ffmpeg for running the postprocessors (default)')
764 action
='store_true', dest
='prefer_ffmpeg',
765 help='Prefer ffmpeg over avconv for running the postprocessors')
767 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
768 dest
='ffmpeg_location',
769 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
772 metavar
='CMD', dest
='exec_cmd',
773 help='Execute a command on the file after downloading, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
775 '--convert-subtitles', '--convert-subs',
776 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
777 help='Convert the subtitles to other format (currently supported: srt|ass|vtt)')
779 parser
.add_option_group(general
)
780 parser
.add_option_group(network
)
781 parser
.add_option_group(selection
)
782 parser
.add_option_group(downloader
)
783 parser
.add_option_group(filesystem
)
784 parser
.add_option_group(thumbnail
)
785 parser
.add_option_group(verbosity
)
786 parser
.add_option_group(workarounds
)
787 parser
.add_option_group(video_format
)
788 parser
.add_option_group(subtitles
)
789 parser
.add_option_group(authentication
)
790 parser
.add_option_group(postproc
)
792 if overrideArguments
is not None:
793 opts
, args
= parser
.parse_args(overrideArguments
)
795 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
797 command_line_conf
= sys
.argv
[1:]
798 # Workaround for Python 2.x, where argv is a byte list
799 if sys
.version_info
< (3,):
800 command_line_conf
= [
801 a
.decode(preferredencoding(), 'replace') for a
in command_line_conf
]
803 if '--ignore-config' in command_line_conf
:
807 system_conf
= _readOptions('/etc/youtube-dl.conf')
808 if '--ignore-config' in system_conf
:
811 user_conf
= _readUserConf()
812 argv
= system_conf
+ user_conf
+ command_line_conf
814 opts
, args
= parser
.parse_args(argv
)
816 write_string('[debug] System config: ' + repr(_hide_login_info(system_conf
)) + '\n')
817 write_string('[debug] User config: ' + repr(_hide_login_info(user_conf
)) + '\n')
818 write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf
)) + '\n')
820 return parser
, opts
, args