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 _hide_login_info(opts
):
24 PRIVATE_OPTS
= set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
25 eqre
= re
.compile('^(?P<key>' + ('|'.join(re
.escape(po
) for po
in PRIVATE_OPTS
)) + ')=.+$')
30 return m
.group('key') + '=PRIVATE'
34 opts
= list(map(_scrub_eq
, opts
))
35 for idx
, opt
in enumerate(opts
):
36 if opt
in PRIVATE_OPTS
and idx
+ 1 < len(opts
):
37 opts
[idx
+ 1] = 'PRIVATE'
41 def parseOpts(overrideArguments
=None):
42 def _readOptions(filename_bytes
, default
=[]):
44 optionf
= open(filename_bytes
)
46 return default
# silently skip if file is not present
48 # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
49 contents
= optionf
.read()
50 if sys
.version_info
< (3,):
51 contents
= contents
.decode(preferredencoding())
52 res
= compat_shlex_split(contents
, comments
=True)
58 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME')
60 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dlc', 'config')
61 if not os
.path
.isfile(userConfFile
):
62 userConfFile
= os
.path
.join(xdg_config_home
, 'youtube-dlc.conf')
64 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dlc', 'config')
65 if not os
.path
.isfile(userConfFile
):
66 userConfFile
= os
.path
.join(compat_expanduser('~'), '.config', 'youtube-dlc.conf')
67 userConf
= _readOptions(userConfFile
, None)
70 appdata_dir
= compat_getenv('appdata')
72 userConf
= _readOptions(
73 os
.path
.join(appdata_dir
, 'youtube-dlc', 'config'),
76 userConf
= _readOptions(
77 os
.path
.join(appdata_dir
, 'youtube-dlc', 'config.txt'),
81 userConf
= _readOptions(
82 os
.path
.join(compat_expanduser('~'), 'youtube-dlc.conf'),
85 userConf
= _readOptions(
86 os
.path
.join(compat_expanduser('~'), 'youtube-dlc.conf.txt'),
94 def _format_option_string(option
):
95 ''' ('-o', '--option') -> -o, --format METAVAR'''
99 if option
._short
_opts
:
100 opts
.append(option
._short
_opts
[0])
101 if option
._long
_opts
:
102 opts
.append(option
._long
_opts
[0])
106 if option
.takes_value():
107 opts
.append(' %s' % option
.metavar
)
111 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
112 setattr(parser
.values
, option
.dest
, value
.split(','))
114 # No need to wrap help messages if we're on a wide console
115 columns
= compat_get_terminal_size().columns
116 max_width
= columns
if columns
else 80
117 max_help_position
= 80
119 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
120 fmt
.format_option_strings
= _format_option_string
123 'version': __version__
,
125 'usage': '%prog [OPTIONS] URL [URL...]',
126 'conflict_handler': 'resolve',
129 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
131 general
= optparse
.OptionGroup(parser
, 'General Options')
135 help='Print this help text and exit')
139 help='Print program version and exit')
142 action
='store_true', dest
='update_self',
143 help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
145 '-i', '--ignore-errors',
146 action
='store_true', dest
='ignoreerrors', default
=False,
147 help='Continue on download errors, for example to skip unavailable videos in a playlist')
150 action
='store_false', dest
='ignoreerrors',
151 help='Abort downloading of further videos (in the playlist or the command line) if an error occurs')
154 action
='store_true', dest
='dump_user_agent', default
=False,
155 help='Display the current browser identification')
158 action
='store_true', dest
='list_extractors', default
=False,
159 help='List all supported extractors')
161 '--extractor-descriptions',
162 action
='store_true', dest
='list_extractor_descriptions', default
=False,
163 help='Output descriptions of all supported extractors')
165 '--force-generic-extractor',
166 action
='store_true', dest
='force_generic_extractor', default
=False,
167 help='Force extraction to use the generic extractor')
170 dest
='default_search', metavar
='PREFIX',
171 help='Use this prefix for unqualified URLs. For example "gvsearch2:" downloads two videos from google videos for youtube-dlc "large apple". Use the value "auto" to let youtube-dlc 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.')
175 help='Do not read configuration files. '
176 'When given in the global configuration file /etc/youtube-dlc.conf: '
177 'Do not read the user configuration in ~/.config/youtube-dlc/config '
178 '(%APPDATA%/youtube-dlc/config.txt on Windows)')
181 dest
='config_location', metavar
='PATH',
182 help='Location of the configuration file; either the path to the config or its containing directory.')
185 action
='store_const', dest
='extract_flat', const
='in_playlist',
187 help='Do not extract the videos of a playlist, only list them.')
190 action
='store_true', dest
='mark_watched', default
=False,
191 help='Mark videos watched (YouTube only)')
194 action
='store_false', dest
='mark_watched', default
=False,
195 help='Do not mark videos watched (YouTube only)')
197 '--no-color', '--no-colors',
198 action
='store_true', dest
='no_color',
200 help='Do not emit color codes in output')
202 network
= optparse
.OptionGroup(parser
, 'Network Options')
204 '--proxy', dest
='proxy',
205 default
=None, metavar
='URL',
206 help='Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
207 'SOCKS proxy, specify a proper scheme. For example '
208 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
209 'for direct connection')
212 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
213 help='Time to wait before giving up, in seconds')
216 metavar
='IP', dest
='source_address', default
=None,
217 help='Client-side IP address to bind to',
220 '-4', '--force-ipv4',
221 action
='store_const', const
='0.0.0.0', dest
='source_address',
222 help='Make all connections via IPv4',
225 '-6', '--force-ipv6',
226 action
='store_const', const
='::', dest
='source_address',
227 help='Make all connections via IPv6',
230 geo
= optparse
.OptionGroup(parser
, 'Geo Restriction')
232 '--geo-verification-proxy',
233 dest
='geo_verification_proxy', default
=None, metavar
='URL',
234 help='Use this proxy to verify the IP address for some geo-restricted sites. '
235 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading.')
237 '--cn-verification-proxy',
238 dest
='cn_verification_proxy', default
=None, metavar
='URL',
239 help=optparse
.SUPPRESS_HELP
)
242 action
='store_true', dest
='geo_bypass', default
=True,
243 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
246 action
='store_false', dest
='geo_bypass', default
=True,
247 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
249 '--geo-bypass-country', metavar
='CODE',
250 dest
='geo_bypass_country', default
=None,
251 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
253 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
254 dest
='geo_bypass_ip_block', default
=None,
255 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
257 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
258 selection
.add_option(
260 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
261 help='Playlist video to start at (default is %default)')
262 selection
.add_option(
264 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
265 help='Playlist video to end at (default is last)')
266 selection
.add_option(
268 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
269 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.')
270 selection
.add_option(
272 dest
='matchtitle', metavar
='REGEX',
273 help='Download only matching titles (regex or caseless sub-string)')
274 selection
.add_option(
276 dest
='rejecttitle', metavar
='REGEX',
277 help='Skip download for matching titles (regex or caseless sub-string)')
278 selection
.add_option(
280 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
281 help='Abort after downloading NUMBER files')
282 selection
.add_option(
284 metavar
='SIZE', dest
='min_filesize', default
=None,
285 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
286 selection
.add_option(
288 metavar
='SIZE', dest
='max_filesize', default
=None,
289 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
290 selection
.add_option(
292 metavar
='DATE', dest
='date', default
=None,
293 help='Download only videos uploaded in this date')
294 selection
.add_option(
296 metavar
='DATE', dest
='datebefore', default
=None,
297 help='Download only videos uploaded on or before this date (i.e. inclusive)')
298 selection
.add_option(
300 metavar
='DATE', dest
='dateafter', default
=None,
301 help='Download only videos uploaded on or after this date (i.e. inclusive)')
302 selection
.add_option(
304 metavar
='COUNT', dest
='min_views', default
=None, type=int,
305 help='Do not download any videos with less than COUNT views')
306 selection
.add_option(
308 metavar
='COUNT', dest
='max_views', default
=None, type=int,
309 help='Do not download any videos with more than COUNT views')
310 selection
.add_option(
312 metavar
='FILTER', dest
='match_filter', default
=None,
314 'Generic video filter. '
315 'Specify any key (see the "OUTPUT TEMPLATE" for a list of available keys) to '
316 'match if the key is present, '
317 '!key to check if the key is not present, '
318 'key > NUMBER (like "comment_count > 12", also works with '
319 '>=, <, <=, !=, =) to compare against a number, '
320 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
321 'to match against a string literal '
322 'and & to require multiple matches. '
323 'Values which are not known are excluded unless you '
324 'put a question mark (?) after the operator. '
325 'For example, to only match videos that have been liked more than '
326 '100 times and disliked less than 50 times (or the dislike '
327 'functionality is not available at the given service), but who '
328 'also have a description, use --match-filter '
329 '"like_count > 100 & dislike_count <? 50 & description" .'
331 selection
.add_option(
333 action
='store_true', dest
='noplaylist', default
=False,
334 help='Download only the video, if the URL refers to a video and a playlist.')
335 selection
.add_option(
337 action
='store_false', dest
='noplaylist', default
=False,
338 help='Download the playlist, if the URL refers to a video and a playlist.')
339 selection
.add_option(
341 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
342 help='Download only videos suitable for the given age')
343 selection
.add_option(
344 '--download-archive', metavar
='FILE',
345 dest
='download_archive',
346 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it.')
347 selection
.add_option(
348 '--break-on-existing',
349 action
='store_true', dest
='break_on_existing', default
=False,
350 help="Stop the download process after attempting to download a file that's in the archive.")
351 selection
.add_option(
353 dest
='include_ads', action
='store_true',
354 help='Download advertisements as well (experimental)')
356 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
357 authentication
.add_option(
359 dest
='username', metavar
='USERNAME',
360 help='Login with this account ID')
361 authentication
.add_option(
363 dest
='password', metavar
='PASSWORD',
364 help='Account password. If this option is left out, youtube-dlc will ask interactively.')
365 authentication
.add_option(
367 dest
='twofactor', metavar
='TWOFACTOR',
368 help='Two-factor authentication code')
369 authentication
.add_option(
371 action
='store_true', dest
='usenetrc', default
=False,
372 help='Use .netrc authentication data')
373 authentication
.add_option(
375 dest
='videopassword', metavar
='PASSWORD',
376 help='Video password (vimeo, smotri, youku)')
378 adobe_pass
= optparse
.OptionGroup(parser
, 'Adobe Pass Options')
379 adobe_pass
.add_option(
381 dest
='ap_mso', metavar
='MSO',
382 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
383 adobe_pass
.add_option(
385 dest
='ap_username', metavar
='USERNAME',
386 help='Multiple-system operator account login')
387 adobe_pass
.add_option(
389 dest
='ap_password', metavar
='PASSWORD',
390 help='Multiple-system operator account password. If this option is left out, youtube-dlc will ask interactively.')
391 adobe_pass
.add_option(
393 action
='store_true', dest
='ap_list_mso', default
=False,
394 help='List all supported multiple-system operators')
396 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
397 video_format
.add_option(
399 action
='store', dest
='format', metavar
='FORMAT', default
=None,
400 help='Video format code, see "FORMAT SELECTION" for more details')
401 video_format
.add_option(
402 '-S', '--format-sort',
403 dest
='format_sort', default
=[],
404 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
405 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
406 video_format
.add_option(
407 '--format-sort-force', '--S-force',
408 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
410 'Force user specified sort order to have precedence over all fields, '
411 'see "Sorting Formats" for more details'))
412 video_format
.add_option(
413 '--no-format-sort-force',
414 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
416 'Some fields have precedence over the user specified sort order (default), '
417 'see "Sorting Formats" for more details'))
418 video_format
.add_option(
419 '--video-multistreams',
420 action
='store_true', dest
='allow_multiple_video_streams', default
=True,
421 help='Allow multiple video streams to be merged into a single file (default)')
422 video_format
.add_option(
423 '--no-video-multistreams',
424 action
='store_false', dest
='allow_multiple_video_streams',
425 help='Only one video stream is downloaded for each output file')
426 video_format
.add_option(
427 '--audio-multistreams',
428 action
='store_true', dest
='allow_multiple_audio_streams', default
=True,
429 help='Allow multiple audio streams to be merged into a single file (default)')
430 video_format
.add_option(
431 '--no-audio-multistreams',
432 action
='store_false', dest
='allow_multiple_audio_streams',
433 help='Only one audio stream is downloaded for each output file')
434 video_format
.add_option(
436 action
='store_const', dest
='format', const
='all',
437 help='Download all available video formats')
438 video_format
.add_option(
439 '--prefer-free-formats',
440 action
='store_true', dest
='prefer_free_formats', default
=False,
441 help='Prefer free video formats unless a specific one is requested')
442 video_format
.add_option(
443 '-F', '--list-formats',
444 action
='store_true', dest
='listformats',
445 help='List all available formats of requested videos')
446 video_format
.add_option(
447 '--list-formats-as-table',
448 action
='store_true', dest
='listformats_table', default
=False,
449 help='Present the output of -F in a more tabular form')
450 video_format
.add_option(
451 '--list-formats-old',
452 action
='store_false', dest
='listformats_table',
453 help=optparse
.SUPPRESS_HELP
)
454 video_format
.add_option(
455 '--youtube-include-dash-manifest',
456 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
457 help=optparse
.SUPPRESS_HELP
)
458 video_format
.add_option(
459 '--youtube-skip-dash-manifest',
460 action
='store_false', dest
='youtube_include_dash_manifest',
461 help='Do not download the DASH manifests and related data on YouTube videos')
462 video_format
.add_option(
463 '--youtube-include-hls-manifest',
464 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
465 help=optparse
.SUPPRESS_HELP
)
466 video_format
.add_option(
467 '--youtube-skip-hls-manifest',
468 action
='store_false', dest
='youtube_include_hls_manifest',
469 help='Do not download the HLS manifests and related data on YouTube videos')
470 video_format
.add_option(
471 '--merge-output-format',
472 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
474 'If a merge is required (e.g. bestvideo+bestaudio), '
475 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
476 'Ignored if no merge is required'))
478 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
479 subtitles
.add_option(
480 '--write-sub', '--write-srt',
481 action
='store_true', dest
='writesubtitles', default
=False,
482 help='Write subtitle file')
483 subtitles
.add_option(
484 '--write-auto-sub', '--write-automatic-sub',
485 action
='store_true', dest
='writeautomaticsub', default
=False,
486 help='Write automatically generated subtitle file (YouTube only)')
487 subtitles
.add_option(
489 action
='store_true', dest
='allsubtitles', default
=False,
490 help='Download all the available subtitles of the video')
491 subtitles
.add_option(
493 action
='store_true', dest
='listsubtitles', default
=False,
494 help='List all available subtitles for the video')
495 subtitles
.add_option(
497 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
498 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
499 subtitles
.add_option(
500 '--sub-lang', '--sub-langs', '--srt-lang',
501 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
502 default
=[], callback
=_comma_separated_values_options_callback
,
503 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
505 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
506 downloader
.add_option(
507 '-r', '--limit-rate', '--rate-limit',
508 dest
='ratelimit', metavar
='RATE',
509 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
510 downloader
.add_option(
512 dest
='retries', metavar
='RETRIES', default
=10,
513 help='Number of retries (default is %default), or "infinite".')
514 downloader
.add_option(
515 '--fragment-retries',
516 dest
='fragment_retries', metavar
='RETRIES', default
=10,
517 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
518 downloader
.add_option(
519 '--skip-unavailable-fragments',
520 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
521 help='Skip unavailable fragments (DASH, hlsnative and ISM)')
522 downloader
.add_option(
523 '--abort-on-unavailable-fragment',
524 action
='store_false', dest
='skip_unavailable_fragments',
525 help='Abort downloading when some fragment is not available')
526 downloader
.add_option(
528 action
='store_true', dest
='keep_fragments', default
=False,
529 help='Keep downloaded fragments on disk after downloading is finished; fragments are erased by default')
530 downloader
.add_option(
532 dest
='buffersize', metavar
='SIZE', default
='1024',
533 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
534 downloader
.add_option(
535 '--no-resize-buffer',
536 action
='store_true', dest
='noresizebuffer', default
=False,
537 help='Do not automatically adjust the buffer size. By default, the buffer size is automatically resized from an initial value of SIZE.')
538 downloader
.add_option(
540 dest
='http_chunk_size', metavar
='SIZE', default
=None,
541 help='Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
542 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)')
543 downloader
.add_option(
545 action
='store_true', dest
='test', default
=False,
546 help=optparse
.SUPPRESS_HELP
)
547 downloader
.add_option(
548 '--playlist-reverse',
550 help='Download playlist videos in reverse order')
551 downloader
.add_option(
554 help='Download playlist videos in random order')
555 downloader
.add_option(
556 '--xattr-set-filesize',
557 dest
='xattr_set_filesize', action
='store_true',
558 help='Set file xattribute ytdl.filesize with expected file size')
559 downloader
.add_option(
560 '--hls-prefer-native',
561 dest
='hls_prefer_native', action
='store_true', default
=None,
562 help='Use the native HLS downloader instead of ffmpeg')
563 downloader
.add_option(
564 '--hls-prefer-ffmpeg',
565 dest
='hls_prefer_native', action
='store_false', default
=None,
566 help='Use ffmpeg instead of the native HLS downloader')
567 downloader
.add_option(
569 dest
='hls_use_mpegts', action
='store_true',
570 help='Use the mpegts container for HLS videos, allowing to play the '
571 'video while downloading (some players may not be able to play it)')
572 downloader
.add_option(
573 '--external-downloader',
574 dest
='external_downloader', metavar
='COMMAND',
575 help='Use the specified external downloader. '
576 'Currently supports %s' % ','.join(list_external_downloaders()))
577 downloader
.add_option(
578 '--external-downloader-args',
579 dest
='external_downloader_args', metavar
='ARGS',
580 help='Give these arguments to the external downloader')
582 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
583 workarounds
.add_option(
585 dest
='encoding', metavar
='ENCODING',
586 help='Force the specified encoding (experimental)')
587 workarounds
.add_option(
588 '--no-check-certificate',
589 action
='store_true', dest
='no_check_certificate', default
=False,
590 help='Suppress HTTPS certificate validation')
591 workarounds
.add_option(
593 '--prefer-unsecure', action
='store_true', dest
='prefer_insecure',
594 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
595 workarounds
.add_option(
597 metavar
='UA', dest
='user_agent',
598 help='Specify a custom user agent')
599 workarounds
.add_option(
601 metavar
='URL', dest
='referer', default
=None,
602 help='Specify a custom referer, use if the video access is restricted to one domain',
604 workarounds
.add_option(
606 metavar
='FIELD:VALUE', dest
='headers', action
='append',
607 help='Specify a custom HTTP header and its value, separated by a colon \':\'. You can use this option multiple times',
609 workarounds
.add_option(
611 dest
='bidi_workaround', action
='store_true',
612 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
613 workarounds
.add_option(
614 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
615 dest
='sleep_interval', type=float,
617 'Number of seconds to sleep before each download when used alone '
618 'or a lower bound of a range for randomized sleep before each download '
619 '(minimum possible number of seconds to sleep) when used along with '
620 '--max-sleep-interval.'))
621 workarounds
.add_option(
622 '--max-sleep-interval', metavar
='SECONDS',
623 dest
='max_sleep_interval', type=float,
625 'Upper bound of a range for randomized sleep before each download '
626 '(maximum possible number of seconds to sleep). Must only be used '
627 'along with --min-sleep-interval.'))
628 workarounds
.add_option(
630 dest
='sleep_interval_subtitles', default
=0, type=int,
631 help='Enforce sleep interval on subtitles as well')
633 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
634 verbosity
.add_option(
636 action
='store_true', dest
='quiet', default
=False,
637 help='Activate quiet mode')
638 verbosity
.add_option(
640 dest
='no_warnings', action
='store_true', default
=False,
641 help='Ignore warnings')
642 verbosity
.add_option(
644 action
='store_true', dest
='simulate', default
=False,
645 help='Do not download the video and do not write anything to disk')
646 verbosity
.add_option(
648 action
='store_true', dest
='skip_download', default
=False,
649 help='Do not download the video')
650 verbosity
.add_option(
652 action
='store_true', dest
='geturl', default
=False,
653 help='Simulate, quiet but print URL')
654 verbosity
.add_option(
656 action
='store_true', dest
='gettitle', default
=False,
657 help='Simulate, quiet but print title')
658 verbosity
.add_option(
660 action
='store_true', dest
='getid', default
=False,
661 help='Simulate, quiet but print id')
662 verbosity
.add_option(
664 action
='store_true', dest
='getthumbnail', default
=False,
665 help='Simulate, quiet but print thumbnail URL')
666 verbosity
.add_option(
668 action
='store_true', dest
='getdescription', default
=False,
669 help='Simulate, quiet but print video description')
670 verbosity
.add_option(
672 action
='store_true', dest
='getduration', default
=False,
673 help='Simulate, quiet but print video length')
674 verbosity
.add_option(
676 action
='store_true', dest
='getfilename', default
=False,
677 help='Simulate, quiet but print output filename')
678 verbosity
.add_option(
680 action
='store_true', dest
='getformat', default
=False,
681 help='Simulate, quiet but print output format')
682 verbosity
.add_option(
684 action
='store_true', dest
='dumpjson', default
=False,
685 help='Simulate, quiet but print JSON information. See the "OUTPUT TEMPLATE" for a description of available keys.')
686 verbosity
.add_option(
687 '-J', '--dump-single-json',
688 action
='store_true', dest
='dump_single_json', default
=False,
689 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.')
690 verbosity
.add_option(
692 action
='store_true', dest
='print_json', default
=False,
693 help='Be quiet and print the video information as JSON (video is still being downloaded).')
694 verbosity
.add_option(
695 '--force-write-download-archive', '--force-write-archive', '--force-download-archive',
696 action
='store_true', dest
='force_write_download_archive', default
=False,
698 'Force download archive entries to be written as far as no errors occur,'
699 'even if -s or another simulation switch is used.'))
700 verbosity
.add_option(
702 action
='store_true', dest
='progress_with_newline', default
=False,
703 help='Output progress bar as new lines')
704 verbosity
.add_option(
706 action
='store_true', dest
='noprogress', default
=False,
707 help='Do not print progress bar')
708 verbosity
.add_option(
710 action
='store_true', dest
='consoletitle', default
=False,
711 help='Display progress in console titlebar')
712 verbosity
.add_option(
714 action
='store_true', dest
='verbose', default
=False,
715 help='Print various debugging information')
716 verbosity
.add_option(
717 '--dump-pages', '--dump-intermediate-pages',
718 action
='store_true', dest
='dump_intermediate_pages', default
=False,
719 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
720 verbosity
.add_option(
722 action
='store_true', dest
='write_pages', default
=False,
723 help='Write downloaded intermediary pages to files in the current directory to debug problems')
724 verbosity
.add_option(
725 '--youtube-print-sig-code',
726 action
='store_true', dest
='youtube_print_sig_code', default
=False,
727 help=optparse
.SUPPRESS_HELP
)
728 verbosity
.add_option(
729 '--print-traffic', '--dump-headers',
730 dest
='debug_printtraffic', action
='store_true', default
=False,
731 help='Display sent and read HTTP traffic')
732 verbosity
.add_option(
734 dest
='call_home', action
='store_true', default
=False,
735 help='Contact the youtube-dlc server for debugging')
736 verbosity
.add_option(
738 dest
='call_home', action
='store_false', default
=False,
739 help='Do NOT contact the youtube-dlc server for debugging')
741 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
742 filesystem
.add_option(
743 '-a', '--batch-file',
744 dest
='batchfile', metavar
='FILE',
745 help="File containing URLs to download ('-' for stdin), one URL per line. "
746 "Lines starting with '#', ';' or ']' are considered as comments and ignored.")
747 filesystem
.add_option(
748 '--id', default
=False,
749 action
='store_true', dest
='useid', help='Use only video ID in file name')
750 filesystem
.add_option(
752 dest
='outtmpl', metavar
='TEMPLATE',
753 help=('Output filename template, see the "OUTPUT TEMPLATE" for all the info'))
754 filesystem
.add_option(
756 dest
='autonumber_size', metavar
='NUMBER', type=int,
757 help=optparse
.SUPPRESS_HELP
)
758 filesystem
.add_option(
759 '--autonumber-start',
760 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
761 help='Specify the start value for %(autonumber)s (default is %default)')
762 filesystem
.add_option(
763 '--restrict-filenames',
764 action
='store_true', dest
='restrictfilenames', default
=False,
765 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
766 filesystem
.add_option(
767 '-A', '--auto-number',
768 action
='store_true', dest
='autonumber', default
=False,
769 help=optparse
.SUPPRESS_HELP
)
770 filesystem
.add_option(
772 action
='store_true', dest
='usetitle', default
=False,
773 help=optparse
.SUPPRESS_HELP
)
774 filesystem
.add_option(
775 '-l', '--literal', default
=False,
776 action
='store_true', dest
='usetitle',
777 help=optparse
.SUPPRESS_HELP
)
778 filesystem
.add_option(
779 '-w', '--no-overwrites',
780 action
='store_true', dest
='nooverwrites', default
=False,
781 help='Do not overwrite files')
782 filesystem
.add_option(
784 action
='store_true', dest
='continue_dl', default
=True,
785 help='Force resume of partially downloaded files. By default, youtube-dlc will resume downloads if possible.')
786 filesystem
.add_option(
788 action
='store_false', dest
='continue_dl',
789 help='Do not resume partially downloaded files (restart from beginning)')
790 filesystem
.add_option(
792 action
='store_true', dest
='nopart', default
=False,
793 help='Do not use .part files - write directly into output file')
794 filesystem
.add_option(
796 action
='store_false', dest
='updatetime', default
=True,
797 help='Do not use the Last-modified header to set the file modification time')
798 filesystem
.add_option(
799 '--write-description',
800 action
='store_true', dest
='writedescription', default
=False,
801 help='Write video description to a .description file')
802 filesystem
.add_option(
804 action
='store_true', dest
='writeinfojson', default
=False,
805 help='Write video metadata to a .info.json file')
806 filesystem
.add_option(
807 '--write-annotations',
808 action
='store_true', dest
='writeannotations', default
=False,
809 help='Write video annotations to a .annotations.xml file')
810 filesystem
.add_option(
811 '--load-info-json', '--load-info',
812 dest
='load_info_filename', metavar
='FILE',
813 help='JSON file containing the video information (created with the "--write-info-json" option)')
814 filesystem
.add_option(
816 dest
='cookiefile', metavar
='FILE',
817 help='File to read cookies from and dump cookie jar in')
818 filesystem
.add_option(
819 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
820 help='Location in the filesystem where youtube-dlc can store some downloaded information permanently. By default $XDG_CACHE_HOME/youtube-dlc or ~/.cache/youtube-dlc . At the moment, only YouTube player files (for videos with obfuscated signatures) are cached, but that may change.')
821 filesystem
.add_option(
822 '--no-cache-dir', action
='store_const', const
=False, dest
='cachedir',
823 help='Disable filesystem caching')
824 filesystem
.add_option(
826 action
='store_true', dest
='rm_cachedir',
827 help='Delete all filesystem cache files')
828 filesystem
.add_option(
829 '--trim-file-name', dest
='trim_file_name', default
=0, type=int,
830 help='Limit the filename length (extension excluded)')
832 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail images')
833 thumbnail
.add_option(
835 action
='store_true', dest
='writethumbnail', default
=False,
836 help='Write thumbnail image to disk')
837 thumbnail
.add_option(
838 '--write-all-thumbnails',
839 action
='store_true', dest
='write_all_thumbnails', default
=False,
840 help='Write all thumbnail image formats to disk')
841 thumbnail
.add_option(
843 action
='store_true', dest
='list_thumbnails', default
=False,
844 help='Simulate and list all available thumbnail formats')
846 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
849 action
='store_true', dest
='writelink', default
=False,
850 help='Write an internet shortcut file, depending on the current platform (.url/.webloc/.desktop). The URL may be cached by the OS.')
853 action
='store_true', dest
='writeurllink', default
=False,
854 help='Write a Windows internet shortcut file (.url). Note that the OS caches the URL based on the file path.')
856 '--write-webloc-link',
857 action
='store_true', dest
='writewebloclink', default
=False,
858 help='Write a macOS internet shortcut file (.webloc)')
860 '--write-desktop-link',
861 action
='store_true', dest
='writedesktoplink', default
=False,
862 help='Write a Linux internet shortcut file (.desktop)')
864 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
866 '-x', '--extract-audio',
867 action
='store_true', dest
='extractaudio', default
=False,
868 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
870 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
871 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
873 '--audio-quality', metavar
='QUALITY',
874 dest
='audioquality', default
='5',
875 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)')
878 metavar
='FORMAT', dest
='remuxvideo', default
=None,
879 help='Remux the video to another container format if necessary (currently supported: mp4|mkv, target container format must support video / audio encoding, remuxing may fail)')
882 metavar
='FORMAT', dest
='recodevideo', default
=None,
883 help='Encode the video to another format if necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
885 '--postprocessor-args',
886 dest
='postprocessor_args', metavar
='ARGS',
887 help='Give these arguments to the postprocessor')
889 '-k', '--keep-video',
890 action
='store_true', dest
='keepvideo', default
=False,
891 help='Keep the video file on disk after the post-processing; the video is erased by default')
893 '--no-post-overwrites',
894 action
='store_true', dest
='nopostoverwrites', default
=False,
895 help='Do not overwrite post-processed files; the post-processed files are overwritten by default')
898 action
='store_true', dest
='embedsubtitles', default
=False,
899 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
902 action
='store_true', dest
='embedthumbnail', default
=False,
903 help='Embed thumbnail in the audio as cover art')
906 action
='store_true', dest
='addmetadata', default
=False,
907 help='Write metadata to the video file')
909 '--metadata-from-title',
910 metavar
='FORMAT', dest
='metafromtitle',
911 help='Parse additional metadata like song title / artist from the video title. '
912 'The format syntax is the same as --output. Regular expression with '
913 'named capture groups may also be used. '
914 'The parsed parameters replace existing values. '
915 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
916 '"Coldplay - Paradise". '
917 'Example (regex): --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"')
920 action
='store_true', dest
='xattrs', default
=False,
921 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
924 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
925 help='Automatically correct known faults of the file. '
926 'One of never (do nothing), warn (only emit a warning), '
927 'detect_or_warn (the default; fix file if we can, warn otherwise)')
930 action
='store_false', dest
='prefer_ffmpeg',
931 help='Prefer avconv over ffmpeg for running the postprocessors')
934 action
='store_true', dest
='prefer_ffmpeg',
935 help='Prefer ffmpeg over avconv for running the postprocessors (default)')
937 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
938 dest
='ffmpeg_location',
939 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory.')
942 metavar
='CMD', dest
='exec_cmd',
943 help='Execute a command on the file after downloading and post-processing, similar to find\'s -exec syntax. Example: --exec \'adb push {} /sdcard/Music/ && rm {}\'')
945 '--convert-subs', '--convert-subtitles',
946 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
947 help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
949 extractor
= optparse
.OptionGroup(parser
, 'SponSkrub Options (SponsorBlock)')
950 extractor
.add_option(
952 action
='store_true', dest
='sponskrub', default
=None,
953 help='Use sponskrub to mark sponsored sections with the data available in SponsorBlock API (Youtube only)')
954 extractor
.add_option(
956 action
='store_false', dest
='sponskrub',
957 help=optparse
.SUPPRESS_HELP
)
958 extractor
.add_option(
959 '--sponskrub-cut', default
=False,
960 action
='store_true', dest
='sponskrub_cut',
961 help='Cut out the sponsor sections instead of simply marking them')
962 extractor
.add_option(
963 '--sponskrub-force', default
=False,
964 action
='store_true', dest
='sponskrub_force',
965 help='Run sponskrub even if the video was already downloaded')
966 extractor
.add_option(
967 '--sponskrub-location', metavar
='PATH',
968 dest
='sponskrub_path', default
='',
969 help='Location of the sponskrub binary; either the path to the binary or its containing directory.')
970 extractor
.add_option(
971 '--sponskrub-args', dest
='sponskrub_args',
972 help='Give these arguments to sponskrub')
974 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
975 extractor
.add_option(
976 '--allow-dynamic-mpd',
977 action
='store_true', dest
='dynamic_mpd', default
=True,
978 help=optparse
.SUPPRESS_HELP
)
979 extractor
.add_option(
980 '--ignore-dynamic-mpd',
981 action
='store_false', dest
='dynamic_mpd',
982 help='Do not process dynamic DASH manifests')
984 parser
.add_option_group(general
)
985 parser
.add_option_group(network
)
986 parser
.add_option_group(geo
)
987 parser
.add_option_group(selection
)
988 parser
.add_option_group(downloader
)
989 parser
.add_option_group(filesystem
)
990 parser
.add_option_group(thumbnail
)
991 parser
.add_option_group(link
)
992 parser
.add_option_group(verbosity
)
993 parser
.add_option_group(workarounds
)
994 parser
.add_option_group(video_format
)
995 parser
.add_option_group(subtitles
)
996 parser
.add_option_group(authentication
)
997 parser
.add_option_group(adobe_pass
)
998 parser
.add_option_group(postproc
)
999 parser
.add_option_group(extractor
)
1001 if overrideArguments
is not None:
1002 opts
, args
= parser
.parse_args(overrideArguments
)
1004 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
1006 def compat_conf(conf
):
1007 if sys
.version_info
< (3,):
1008 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
1011 command_line_conf
= compat_conf(sys
.argv
[1:])
1012 opts
, args
= parser
.parse_args(command_line_conf
)
1014 system_conf
= user_conf
= custom_conf
= []
1016 if '--config-location' in command_line_conf
:
1017 location
= compat_expanduser(opts
.config_location
)
1018 if os
.path
.isdir(location
):
1019 location
= os
.path
.join(location
, 'youtube-dlc.conf')
1020 if not os
.path
.exists(location
):
1021 parser
.error('config-location %s does not exist.' % location
)
1022 custom_conf
= _readOptions(location
)
1023 elif '--ignore-config' in command_line_conf
:
1026 system_conf
= _readOptions('/etc/youtube-dlc.conf')
1027 if '--ignore-config' not in system_conf
:
1028 user_conf
= _readUserConf()
1030 argv
= system_conf
+ user_conf
+ custom_conf
+ command_line_conf
1031 opts
, args
= parser
.parse_args(argv
)
1033 for conf_label
, conf
in (
1034 ('System config', system_conf
),
1035 ('User config', user_conf
),
1036 ('Custom config', custom_conf
),
1037 ('Command-line args', command_line_conf
)):
1038 write_string('[debug] %s: %s\n' % (conf_label
, repr(_hide_login_info(conf
))))
1040 return parser
, opts
, args