1 from __future__
import unicode_literals
8 from .downloader
.external
import list_external_downloaders
11 compat_get_terminal_size
,
21 from .version
import __version__
24 def _hide_login_info(opts
):
25 PRIVATE_OPTS
= set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
26 eqre
= re
.compile('^(?P<key>' + ('|'.join(re
.escape(po
) for po
in PRIVATE_OPTS
)) + ')=.+$')
31 return m
.group('key') + '=PRIVATE'
35 opts
= list(map(_scrub_eq
, opts
))
36 for idx
, opt
in enumerate(opts
):
37 if opt
in PRIVATE_OPTS
and idx
+ 1 < len(opts
):
38 opts
[idx
+ 1] = 'PRIVATE'
42 def parseOpts(overrideArguments
=None):
43 def _readOptions(filename_bytes
, default
=[]):
45 optionf
= open(filename_bytes
)
47 return default
# silently skip if file is not present
49 # FIXME: https://github.com/ytdl-org/youtube-dl/commit/dfe5fa49aed02cf36ba9f743b11b0903554b5e56
50 contents
= optionf
.read()
51 if sys
.version_info
< (3,):
52 contents
= contents
.decode(preferredencoding())
53 res
= compat_shlex_split(contents
, comments
=True)
58 def _readUserConf(package_name
, default
=[]):
60 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME') or compat_expanduser('~/.config')
61 userConfFile
= os
.path
.join(xdg_config_home
, package_name
, 'config')
62 if not os
.path
.isfile(userConfFile
):
63 userConfFile
= os
.path
.join(xdg_config_home
, '%s.conf' % package_name
)
64 userConf
= _readOptions(userConfFile
, default
=None)
65 if userConf
is not None:
66 return userConf
, userConfFile
69 appdata_dir
= compat_getenv('appdata')
71 userConfFile
= os
.path
.join(appdata_dir
, package_name
, 'config')
72 userConf
= _readOptions(userConfFile
, default
=None)
74 userConfFile
+= '.txt'
75 userConf
= _readOptions(userConfFile
, default
=None)
76 if userConf
is not None:
77 return userConf
, userConfFile
80 userConfFile
= os
.path
.join(compat_expanduser('~'), '%s.conf' % package_name
)
81 userConf
= _readOptions(userConfFile
, default
=None)
83 userConfFile
+= '.txt'
84 userConf
= _readOptions(userConfFile
, default
=None)
85 if userConf
is not None:
86 return userConf
, userConfFile
90 def _format_option_string(option
):
91 ''' ('-o', '--option') -> -o, --format METAVAR'''
95 if option
._short
_opts
:
96 opts
.append(option
._short
_opts
[0])
98 opts
.append(option
._long
_opts
[0])
102 if option
.takes_value():
103 opts
.append(' %s' % option
.metavar
)
107 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
108 setattr(parser
.values
, option
.dest
, value
.split(','))
110 def _dict_from_multiple_values_options_callback(
111 option
, opt_str
, value
, parser
, allowed_keys
=r
'[\w-]+', delimiter
=':', default_key
=None, process
=None):
113 out_dict
= getattr(parser
.values
, option
.dest
)
114 mobj
= re
.match(r
'(?i)(?P<key>%s)%s(?P<val>.*)$' % (allowed_keys
, delimiter
), value
)
116 key
, val
= mobj
.group('key').lower(), mobj
.group('val')
117 elif default_key
is not None:
118 key
, val
= default_key
, value
120 raise optparse
.OptionValueError(
121 'wrong %s formatting; it should be %s, not "%s"' % (opt_str
, option
.metavar
, value
))
122 out_dict
[key
] = process(val
) if callable(process
) else val
124 # No need to wrap help messages if we're on a wide console
125 columns
= compat_get_terminal_size().columns
126 max_width
= columns
if columns
else 80
127 max_help_position
= 80
129 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
130 fmt
.format_option_strings
= _format_option_string
133 'version': __version__
,
135 'usage': '%prog [OPTIONS] URL [URL...]',
136 'conflict_handler': 'resolve',
139 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
141 general
= optparse
.OptionGroup(parser
, 'General Options')
145 help='Print this help text and exit')
149 help='Print program version and exit')
152 action
='store_true', dest
='update_self',
153 help='[BROKEN] Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
155 '-i', '--ignore-errors', '--no-abort-on-error',
156 action
='store_true', dest
='ignoreerrors', default
=True,
157 help='Continue on download errors, for example to skip unavailable videos in a playlist (default) (Alias: --no-abort-on-error)')
159 '--abort-on-error', '--no-ignore-errors',
160 action
='store_false', dest
='ignoreerrors',
161 help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
164 action
='store_true', dest
='dump_user_agent', default
=False,
165 help='Display the current browser identification')
168 action
='store_true', dest
='list_extractors', default
=False,
169 help='List all supported extractors')
171 '--extractor-descriptions',
172 action
='store_true', dest
='list_extractor_descriptions', default
=False,
173 help='Output descriptions of all supported extractors')
175 '--force-generic-extractor',
176 action
='store_true', dest
='force_generic_extractor', default
=False,
177 help='Force extraction to use the generic extractor')
180 dest
='default_search', metavar
='PREFIX',
181 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')
183 '--ignore-config', '--no-config',
186 'Disable loading any configuration files except the one provided by --config-location. '
187 'When given inside a configuration file, no further configuration files are loaded. '
188 'Additionally, (for backward compatibility) if this option is found inside the '
189 'system configuration file, the user configuration is not loaded'))
192 dest
='config_location', metavar
='PATH',
193 help='Location of the main configuration file; either the path to the config or its containing directory')
196 action
='store_const', dest
='extract_flat', const
='in_playlist', default
=False,
197 help='Do not extract the videos of a playlist, only list them')
200 action
='store_true', dest
='extract_flat',
201 help='Do not resolve the video urls')
203 '--no-flat-playlist',
204 action
='store_false', dest
='extract_flat',
205 help='Extract the videos of a playlist')
208 action
='store_true', dest
='mark_watched', default
=False,
209 help='Mark videos watched (YouTube only)')
212 action
='store_false', dest
='mark_watched', default
=False,
213 help='Do not mark videos watched')
216 action
='store_true', dest
='no_color',
218 help='Do not emit color codes in output')
220 network
= optparse
.OptionGroup(parser
, 'Network Options')
222 '--proxy', dest
='proxy',
223 default
=None, metavar
='URL',
225 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
226 'SOCKS proxy, specify a proper scheme. For example '
227 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
228 'for direct connection'))
231 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
232 help='Time to wait before giving up, in seconds')
235 metavar
='IP', dest
='source_address', default
=None,
236 help='Client-side IP address to bind to',
239 '-4', '--force-ipv4',
240 action
='store_const', const
='0.0.0.0', dest
='source_address',
241 help='Make all connections via IPv4',
244 '-6', '--force-ipv6',
245 action
='store_const', const
='::', dest
='source_address',
246 help='Make all connections via IPv6',
249 geo
= optparse
.OptionGroup(parser
, 'Geo Restriction')
251 '--geo-verification-proxy',
252 dest
='geo_verification_proxy', default
=None, metavar
='URL',
254 'Use this proxy to verify the IP address for some geo-restricted sites. '
255 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
257 '--cn-verification-proxy',
258 dest
='cn_verification_proxy', default
=None, metavar
='URL',
259 help=optparse
.SUPPRESS_HELP
)
262 action
='store_true', dest
='geo_bypass', default
=True,
263 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
266 action
='store_false', dest
='geo_bypass', default
=True,
267 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
269 '--geo-bypass-country', metavar
='CODE',
270 dest
='geo_bypass_country', default
=None,
271 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
273 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
274 dest
='geo_bypass_ip_block', default
=None,
275 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
277 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
278 selection
.add_option(
280 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
281 help='Playlist video to start at (default is %default)')
282 selection
.add_option(
284 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
285 help='Playlist video to end at (default is last)')
286 selection
.add_option(
288 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
289 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')
290 selection
.add_option(
292 dest
='matchtitle', metavar
='REGEX',
293 help='Download only matching titles (regex or caseless sub-string)')
294 selection
.add_option(
296 dest
='rejecttitle', metavar
='REGEX',
297 help='Skip download for matching titles (regex or caseless sub-string)')
298 selection
.add_option(
300 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
301 help='Abort after downloading NUMBER files')
302 selection
.add_option(
304 metavar
='SIZE', dest
='min_filesize', default
=None,
305 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
306 selection
.add_option(
308 metavar
='SIZE', dest
='max_filesize', default
=None,
309 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
310 selection
.add_option(
312 metavar
='DATE', dest
='date', default
=None,
314 'Download only videos uploaded in this date. '
315 'The date can be "YYYYMMDD" or in the format '
316 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
317 selection
.add_option(
319 metavar
='DATE', dest
='datebefore', default
=None,
321 'Download only videos uploaded on or before this date. '
322 'The date formats accepted is the same as --date'))
323 selection
.add_option(
325 metavar
='DATE', dest
='dateafter', default
=None,
327 'Download only videos uploaded on or after this date. '
328 'The date formats accepted is the same as --date'))
329 selection
.add_option(
331 metavar
='COUNT', dest
='min_views', default
=None, type=int,
332 help='Do not download any videos with less than COUNT views')
333 selection
.add_option(
335 metavar
='COUNT', dest
='max_views', default
=None, type=int,
336 help='Do not download any videos with more than COUNT views')
337 selection
.add_option(
339 metavar
='FILTER', dest
='match_filter', default
=None,
341 'Generic video filter. '
342 'Specify any key (see "OUTPUT TEMPLATE" for a list of available keys) to '
343 'match if the key is present, '
344 '!key to check if the key is not present, '
345 'key>NUMBER (like "comment_count > 12", also works with '
346 '>=, <, <=, !=, =) to compare against a number, '
347 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
348 'to match against a string literal '
349 'and & to require multiple matches. '
350 'Values which are not known are excluded unless you '
351 'put a question mark (?) after the operator. '
352 'For example, to only match videos that have been liked more than '
353 '100 times and disliked less than 50 times (or the dislike '
354 'functionality is not available at the given service), but who '
355 'also have a description, use --match-filter '
356 '"like_count > 100 & dislike_count <? 50 & description"'))
357 selection
.add_option(
359 metavar
='FILTER', dest
='match_filter', action
='store_const', const
=None,
360 help='Do not use generic video filter (default)')
361 selection
.add_option(
363 action
='store_true', dest
='noplaylist', default
=False,
364 help='Download only the video, if the URL refers to a video and a playlist')
365 selection
.add_option(
367 action
='store_false', dest
='noplaylist', default
=False,
368 help='Download the playlist, if the URL refers to a video and a playlist')
369 selection
.add_option(
371 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
372 help='Download only videos suitable for the given age')
373 selection
.add_option(
374 '--download-archive', metavar
='FILE',
375 dest
='download_archive',
376 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
377 selection
.add_option(
378 '--break-on-existing',
379 action
='store_true', dest
='break_on_existing', default
=False,
380 help='Stop the download process when encountering a file that is in the archive')
381 selection
.add_option(
383 action
='store_true', dest
='break_on_reject', default
=False,
384 help='Stop the download process when encountering a file that has been filtered out')
385 selection
.add_option(
386 '--no-download-archive',
387 dest
='download_archive', action
="store_const", const
=None,
388 help='Do not use archive file (default)')
389 selection
.add_option(
391 dest
='include_ads', action
='store_true',
392 help='Download advertisements as well (experimental)')
393 selection
.add_option(
395 dest
='include_ads', action
='store_false',
396 help='Do not download advertisements (default)')
398 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
399 authentication
.add_option(
401 dest
='username', metavar
='USERNAME',
402 help='Login with this account ID')
403 authentication
.add_option(
405 dest
='password', metavar
='PASSWORD',
406 help='Account password. If this option is left out, youtube-dlc will ask interactively')
407 authentication
.add_option(
409 dest
='twofactor', metavar
='TWOFACTOR',
410 help='Two-factor authentication code')
411 authentication
.add_option(
413 action
='store_true', dest
='usenetrc', default
=False,
414 help='Use .netrc authentication data')
415 authentication
.add_option(
417 dest
='videopassword', metavar
='PASSWORD',
418 help='Video password (vimeo, youku)')
420 adobe_pass
= optparse
.OptionGroup(parser
, 'Adobe Pass Options')
421 adobe_pass
.add_option(
423 dest
='ap_mso', metavar
='MSO',
424 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
425 adobe_pass
.add_option(
427 dest
='ap_username', metavar
='USERNAME',
428 help='Multiple-system operator account login')
429 adobe_pass
.add_option(
431 dest
='ap_password', metavar
='PASSWORD',
432 help='Multiple-system operator account password. If this option is left out, youtube-dlc will ask interactively')
433 adobe_pass
.add_option(
435 action
='store_true', dest
='ap_list_mso', default
=False,
436 help='List all supported multiple-system operators')
438 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
439 video_format
.add_option(
441 action
='store', dest
='format', metavar
='FORMAT', default
=None,
442 help='Video format code, see "FORMAT SELECTION" for more details')
443 video_format
.add_option(
444 '-S', '--format-sort', metavar
='SORTORDER',
445 dest
='format_sort', default
=[],
446 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
447 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
448 video_format
.add_option(
449 '--format-sort-force', '--S-force',
450 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
452 'Force user specified sort order to have precedence over all fields, '
453 'see "Sorting Formats" for more details'))
454 video_format
.add_option(
455 '--no-format-sort-force',
456 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
458 'Some fields have precedence over the user specified sort order (default), '
459 'see "Sorting Formats" for more details'))
460 video_format
.add_option(
461 '--video-multistreams',
462 action
='store_true', dest
='allow_multiple_video_streams', default
=False,
463 help='Allow multiple video streams to be merged into a single file')
464 video_format
.add_option(
465 '--no-video-multistreams',
466 action
='store_false', dest
='allow_multiple_video_streams',
467 help='Only one video stream is downloaded for each output file (default)')
468 video_format
.add_option(
469 '--audio-multistreams',
470 action
='store_true', dest
='allow_multiple_audio_streams', default
=False,
471 help='Allow multiple audio streams to be merged into a single file')
472 video_format
.add_option(
473 '--no-audio-multistreams',
474 action
='store_false', dest
='allow_multiple_audio_streams',
475 help='Only one audio stream is downloaded for each output file (default)')
476 video_format
.add_option(
478 action
='store_const', dest
='format', const
='all',
479 help='Download all available video formats')
480 video_format
.add_option(
481 '--prefer-free-formats',
482 action
='store_true', dest
='prefer_free_formats', default
=False,
483 help='Prefer free video formats over non-free formats of same quality')
484 video_format
.add_option(
485 '-F', '--list-formats',
486 action
='store_true', dest
='listformats',
487 help='List all available formats of requested videos')
488 video_format
.add_option(
489 '--list-formats-as-table',
490 action
='store_true', dest
='listformats_table', default
=True,
491 help='Present the output of -F in tabular form (default)')
492 video_format
.add_option(
493 '--list-formats-old', '--no-list-formats-as-table',
494 action
='store_false', dest
='listformats_table',
495 help='Present the output of -F in the old form (Alias: --no-list-formats-as-table)')
496 video_format
.add_option(
497 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
498 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
499 help='Download the DASH manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-dash-manifest)')
500 video_format
.add_option(
501 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
502 action
='store_false', dest
='youtube_include_dash_manifest',
503 help='Do not download the DASH manifests and related data on YouTube videos (Alias: --no-youtube-include-dash-manifest)')
504 video_format
.add_option(
505 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
506 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
507 help='Download the HLS manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-hls-manifest)')
508 video_format
.add_option(
509 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
510 action
='store_false', dest
='youtube_include_hls_manifest',
511 help='Do not download the HLS manifests and related data on YouTube videos (Alias: --no-youtube-include-hls-manifest)')
512 video_format
.add_option(
513 '--merge-output-format',
514 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
516 'If a merge is required (e.g. bestvideo+bestaudio), '
517 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
518 'Ignored if no merge is required'))
520 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
521 subtitles
.add_option(
522 '--write-subs', '--write-srt',
523 action
='store_true', dest
='writesubtitles', default
=False,
524 help='Write subtitle file')
525 subtitles
.add_option(
526 '--no-write-subs', '--no-write-srt',
527 action
='store_false', dest
='writesubtitles',
528 help='Do not write subtitle file (default)')
529 subtitles
.add_option(
530 '--write-auto-subs', '--write-automatic-subs',
531 action
='store_true', dest
='writeautomaticsub', default
=False,
532 help='Write automatically generated subtitle file (YouTube only)')
533 subtitles
.add_option(
534 '--no-write-auto-subs', '--no-write-automatic-subs',
535 action
='store_false', dest
='writeautomaticsub', default
=False,
536 help='Do not write automatically generated subtitle file (default)')
537 subtitles
.add_option(
539 action
='store_true', dest
='allsubtitles', default
=False,
540 help='Download all the available subtitles of the video')
541 subtitles
.add_option(
543 action
='store_true', dest
='listsubtitles', default
=False,
544 help='List all available subtitles for the video')
545 subtitles
.add_option(
547 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
548 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
549 subtitles
.add_option(
550 '--sub-lang', '--sub-langs', '--srt-lang',
551 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
552 default
=[], callback
=_comma_separated_values_options_callback
,
553 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
555 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
556 downloader
.add_option(
557 '-r', '--limit-rate', '--rate-limit',
558 dest
='ratelimit', metavar
='RATE',
559 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
560 downloader
.add_option(
562 dest
='retries', metavar
='RETRIES', default
=10,
563 help='Number of retries (default is %default), or "infinite"')
564 downloader
.add_option(
565 '--fragment-retries',
566 dest
='fragment_retries', metavar
='RETRIES', default
=10,
567 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
568 downloader
.add_option(
569 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
570 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
571 help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)')
572 downloader
.add_option(
573 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
574 action
='store_false', dest
='skip_unavailable_fragments',
575 help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
576 downloader
.add_option(
578 action
='store_true', dest
='keep_fragments', default
=False,
579 help='Keep downloaded fragments on disk after downloading is finished')
580 downloader
.add_option(
581 '--no-keep-fragments',
582 action
='store_false', dest
='keep_fragments',
583 help='Delete downloaded fragments after downloading is finished (default)')
584 downloader
.add_option(
586 dest
='buffersize', metavar
='SIZE', default
='1024',
587 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
588 downloader
.add_option(
590 action
='store_false', dest
='noresizebuffer',
591 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
592 downloader
.add_option(
593 '--no-resize-buffer',
594 action
='store_true', dest
='noresizebuffer', default
=False,
595 help='Do not automatically adjust the buffer size')
596 downloader
.add_option(
598 dest
='http_chunk_size', metavar
='SIZE', default
=None,
600 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
601 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
602 downloader
.add_option(
604 action
='store_true', dest
='test', default
=False,
605 help=optparse
.SUPPRESS_HELP
)
606 downloader
.add_option(
607 '--playlist-reverse',
609 help='Download playlist videos in reverse order')
610 downloader
.add_option(
611 '--no-playlist-reverse',
612 action
='store_false', dest
='playlist_reverse',
613 help='Download playlist videos in default order (default)')
614 downloader
.add_option(
617 help='Download playlist videos in random order')
618 downloader
.add_option(
619 '--xattr-set-filesize',
620 dest
='xattr_set_filesize', action
='store_true',
621 help='Set file xattribute ytdl.filesize with expected file size')
622 downloader
.add_option(
623 '--hls-prefer-native',
624 dest
='hls_prefer_native', action
='store_true', default
=None,
625 help='Use the native HLS downloader instead of ffmpeg')
626 downloader
.add_option(
627 '--hls-prefer-ffmpeg',
628 dest
='hls_prefer_native', action
='store_false', default
=None,
629 help='Use ffmpeg instead of the native HLS downloader')
630 downloader
.add_option(
632 dest
='hls_use_mpegts', action
='store_true',
634 'Use the mpegts container for HLS videos, allowing to play the '
635 'video while downloading (some players may not be able to play it)'))
636 downloader
.add_option(
637 '--external-downloader',
638 dest
='external_downloader', metavar
='NAME',
640 'Use the specified external downloader. '
641 'Currently supports %s' % ', '.join(list_external_downloaders())))
642 downloader
.add_option(
643 '--downloader-args', '--external-downloader-args',
644 metavar
='NAME:ARGS', dest
='external_downloader_args', default
={}, type='str',
645 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
647 'allowed_keys': '|'.join(list_external_downloaders()),
648 'default_key': 'default', 'process': compat_shlex_split
},
650 'Give these arguments to the external downloader. '
651 'Specify the downloader name and the arguments separated by a colon ":". '
652 'You can use this option multiple times (Alias: --external-downloader-args)'))
654 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
655 workarounds
.add_option(
657 dest
='encoding', metavar
='ENCODING',
658 help='Force the specified encoding (experimental)')
659 workarounds
.add_option(
660 '--no-check-certificate',
661 action
='store_true', dest
='no_check_certificate', default
=False,
662 help='Suppress HTTPS certificate validation')
663 workarounds
.add_option(
664 '--prefer-insecure', '--prefer-unsecure',
665 action
='store_true', dest
='prefer_insecure',
666 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
667 workarounds
.add_option(
669 metavar
='UA', dest
='user_agent',
670 help='Specify a custom user agent')
671 workarounds
.add_option(
673 metavar
='URL', dest
='referer', default
=None,
674 help='Specify a custom referer, use if the video access is restricted to one domain',
676 workarounds
.add_option(
678 metavar
='FIELD:VALUE', dest
='headers', default
={}, type='str',
679 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
680 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
682 workarounds
.add_option(
684 dest
='bidi_workaround', action
='store_true',
685 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
686 workarounds
.add_option(
687 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
688 dest
='sleep_interval', type=float,
690 'Number of seconds to sleep before each download when used alone '
691 'or a lower bound of a range for randomized sleep before each download '
692 '(minimum possible number of seconds to sleep) when used along with '
693 '--max-sleep-interval'))
694 workarounds
.add_option(
695 '--max-sleep-interval', metavar
='SECONDS',
696 dest
='max_sleep_interval', type=float,
698 'Upper bound of a range for randomized sleep before each download '
699 '(maximum possible number of seconds to sleep). Must only be used '
700 'along with --min-sleep-interval'))
701 workarounds
.add_option(
702 '--sleep-subtitles', metavar
='SECONDS',
703 dest
='sleep_interval_subtitles', default
=0, type=int,
704 help='Enforce sleep interval on subtitles as well')
706 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
707 verbosity
.add_option(
709 action
='store_true', dest
='quiet', default
=False,
710 help='Activate quiet mode')
711 verbosity
.add_option(
713 dest
='no_warnings', action
='store_true', default
=False,
714 help='Ignore warnings')
715 verbosity
.add_option(
717 action
='store_true', dest
='simulate', default
=False,
718 help='Do not download the video and do not write anything to disk')
719 verbosity
.add_option(
720 '--skip-download', '--no-download',
721 action
='store_true', dest
='skip_download', default
=False,
722 help='Do not download the video')
723 verbosity
.add_option(
725 action
='store_true', dest
='geturl', default
=False,
726 help='Simulate, quiet but print URL')
727 verbosity
.add_option(
729 action
='store_true', dest
='gettitle', default
=False,
730 help='Simulate, quiet but print title')
731 verbosity
.add_option(
733 action
='store_true', dest
='getid', default
=False,
734 help='Simulate, quiet but print id')
735 verbosity
.add_option(
737 action
='store_true', dest
='getthumbnail', default
=False,
738 help='Simulate, quiet but print thumbnail URL')
739 verbosity
.add_option(
741 action
='store_true', dest
='getdescription', default
=False,
742 help='Simulate, quiet but print video description')
743 verbosity
.add_option(
745 action
='store_true', dest
='getduration', default
=False,
746 help='Simulate, quiet but print video length')
747 verbosity
.add_option(
749 action
='store_true', dest
='getfilename', default
=False,
750 help='Simulate, quiet but print output filename')
751 verbosity
.add_option(
753 action
='store_true', dest
='getformat', default
=False,
754 help='Simulate, quiet but print output format')
755 verbosity
.add_option(
757 action
='store_true', dest
='dumpjson', default
=False,
758 help='Simulate, quiet but print JSON information. See "OUTPUT TEMPLATE" for a description of available keys')
759 verbosity
.add_option(
760 '-J', '--dump-single-json',
761 action
='store_true', dest
='dump_single_json', default
=False,
763 'Simulate, quiet but print JSON information for each command-line argument. '
764 'If the URL refers to a playlist, dump the whole playlist information in a single line'))
765 verbosity
.add_option(
767 action
='store_true', dest
='print_json', default
=False,
768 help='Be quiet and print the video information as JSON (video is still being downloaded)')
769 verbosity
.add_option(
770 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
771 action
='store_true', dest
='force_write_download_archive', default
=False,
773 'Force download archive entries to be written as far as no errors occur,'
774 'even if -s or another simulation switch is used (Alias: --force-download-archive)'))
775 verbosity
.add_option(
777 action
='store_true', dest
='progress_with_newline', default
=False,
778 help='Output progress bar as new lines')
779 verbosity
.add_option(
781 action
='store_true', dest
='noprogress', default
=False,
782 help='Do not print progress bar')
783 verbosity
.add_option(
785 action
='store_true', dest
='consoletitle', default
=False,
786 help='Display progress in console titlebar')
787 verbosity
.add_option(
789 action
='store_true', dest
='verbose', default
=False,
790 help='Print various debugging information')
791 verbosity
.add_option(
792 '--dump-pages', '--dump-intermediate-pages',
793 action
='store_true', dest
='dump_intermediate_pages', default
=False,
794 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
795 verbosity
.add_option(
797 action
='store_true', dest
='write_pages', default
=False,
798 help='Write downloaded intermediary pages to files in the current directory to debug problems')
799 verbosity
.add_option(
800 '--youtube-print-sig-code',
801 action
='store_true', dest
='youtube_print_sig_code', default
=False,
802 help=optparse
.SUPPRESS_HELP
)
803 verbosity
.add_option(
804 '--print-traffic', '--dump-headers',
805 dest
='debug_printtraffic', action
='store_true', default
=False,
806 help='Display sent and read HTTP traffic')
807 verbosity
.add_option(
809 dest
='call_home', action
='store_true', default
=False,
810 help='[Broken] Contact the youtube-dlc server for debugging')
811 verbosity
.add_option(
813 dest
='call_home', action
='store_false',
814 help='Do not contact the youtube-dlc server for debugging (default)')
816 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
817 filesystem
.add_option(
818 '-a', '--batch-file',
819 dest
='batchfile', metavar
='FILE',
820 help="File containing URLs to download ('-' for stdin), one URL per line. "
821 "Lines starting with '#', ';' or ']' are considered as comments and ignored")
822 filesystem
.add_option(
823 '--id', default
=False,
824 action
='store_true', dest
='useid', help=optparse
.SUPPRESS_HELP
)
825 filesystem
.add_option(
827 metavar
='TYPE:PATH', dest
='paths', default
={}, type='str',
828 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
830 'allowed_keys': 'home|temp|config|description|annotation|subtitle|infojson|thumbnail',
831 'process': lambda x
: x
.strip()},
833 'The paths where the files should be downloaded. '
834 'Specify the type of file and the path separated by a colon ":" '
835 '(supported: description|annotation|subtitle|infojson|thumbnail). '
836 'Additionally, you can also provide "home" and "temp" paths. '
837 'All intermediary files are first downloaded to the temp path and '
838 'then the final files are moved over to the home path after download is finished. '
839 'Note that this option is ignored if --output is an absolute path'))
840 filesystem
.add_option(
842 dest
='outtmpl', metavar
='TEMPLATE',
843 help='Output filename template, see "OUTPUT TEMPLATE" for details')
844 filesystem
.add_option(
846 dest
='autonumber_size', metavar
='NUMBER', type=int,
847 help=optparse
.SUPPRESS_HELP
)
848 filesystem
.add_option(
849 '--autonumber-start',
850 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
851 help='Specify the start value for %(autonumber)s (default is %default)')
852 filesystem
.add_option(
853 '--restrict-filenames',
854 action
='store_true', dest
='restrictfilenames', default
=False,
855 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
856 filesystem
.add_option(
857 '--no-restrict-filenames',
858 action
='store_false', dest
='restrictfilenames', default
=False,
859 help='Allow Unicode characters, "&" and spaces in filenames (default)')
860 filesystem
.add_option(
861 '-A', '--auto-number',
862 action
='store_true', dest
='autonumber', default
=False,
863 help=optparse
.SUPPRESS_HELP
)
864 filesystem
.add_option(
866 action
='store_true', dest
='usetitle', default
=False,
867 help=optparse
.SUPPRESS_HELP
)
868 filesystem
.add_option(
869 '-l', '--literal', default
=False,
870 action
='store_true', dest
='usetitle',
871 help=optparse
.SUPPRESS_HELP
)
872 filesystem
.add_option(
873 '-w', '--no-overwrites',
874 action
='store_false', dest
='overwrites', default
=None,
875 help='Do not overwrite any files')
876 filesystem
.add_option(
877 '--force-overwrites', '--yes-overwrites',
878 action
='store_true', dest
='overwrites',
879 help='Overwrite all video and metadata files. This option includes --no-continue')
880 filesystem
.add_option(
881 '--no-force-overwrites',
882 action
='store_const', dest
='overwrites', const
=None,
883 help='Do not overwrite the video, but overwrite related files (default)')
884 filesystem
.add_option(
886 action
='store_true', dest
='continue_dl', default
=True,
887 help='Resume partially downloaded files (default)')
888 filesystem
.add_option(
890 action
='store_false', dest
='continue_dl',
891 help='Restart download of partially downloaded files from beginning')
892 filesystem
.add_option(
894 action
='store_false', dest
='nopart', default
=False,
895 help='Use .part files instead of writing directly into output file (default)')
896 filesystem
.add_option(
898 action
='store_true', dest
='nopart',
899 help='Do not use .part files - write directly into output file')
900 filesystem
.add_option(
902 action
='store_true', dest
='updatetime', default
=True,
903 help='Use the Last-modified header to set the file modification time (default)')
904 filesystem
.add_option(
906 action
='store_false', dest
='updatetime',
907 help='Do not use the Last-modified header to set the file modification time')
908 filesystem
.add_option(
909 '--write-description',
910 action
='store_true', dest
='writedescription', default
=False,
911 help='Write video description to a .description file')
912 filesystem
.add_option(
913 '--no-write-description',
914 action
='store_false', dest
='writedescription',
915 help='Do not write video description (default)')
916 filesystem
.add_option(
918 action
='store_true', dest
='writeinfojson', default
=False,
919 help='Write video metadata to a .info.json file')
920 filesystem
.add_option(
921 '--no-write-info-json',
922 action
='store_false', dest
='writeinfojson',
923 help='Do not write video metadata (default)')
924 filesystem
.add_option(
925 '--write-annotations',
926 action
='store_true', dest
='writeannotations', default
=False,
927 help='Write video annotations to a .annotations.xml file')
928 filesystem
.add_option(
929 '--no-write-annotations',
930 action
='store_false', dest
='writeannotations',
931 help='Do not write video annotations (default)')
932 filesystem
.add_option(
933 '--load-info-json', '--load-info',
934 dest
='load_info_filename', metavar
='FILE',
935 help='JSON file containing the video information (created with the "--write-info-json" option)')
936 filesystem
.add_option(
938 dest
='cookiefile', metavar
='FILE',
939 help='File to read cookies from and dump cookie jar in')
940 filesystem
.add_option(
942 action
='store_const', const
=None, dest
='cookiefile', metavar
='FILE',
943 help='Do not read/dump cookies (default)')
944 filesystem
.add_option(
945 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
946 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')
947 filesystem
.add_option(
948 '--no-cache-dir', action
='store_false', dest
='cachedir',
949 help='Disable filesystem caching')
950 filesystem
.add_option(
952 action
='store_true', dest
='rm_cachedir',
953 help='Delete all filesystem cache files')
954 filesystem
.add_option(
955 '--trim-file-name', metavar
='LENGTH',
956 dest
='trim_file_name', default
=0, type=int,
957 help='Limit the filename length (extension excluded)')
959 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail Images')
960 thumbnail
.add_option(
962 action
='store_true', dest
='writethumbnail', default
=False,
963 help='Write thumbnail image to disk')
964 thumbnail
.add_option(
965 '--no-write-thumbnail',
966 action
='store_false', dest
='writethumbnail',
967 help='Do not write thumbnail image to disk (default)')
968 thumbnail
.add_option(
969 '--write-all-thumbnails',
970 action
='store_true', dest
='write_all_thumbnails', default
=False,
971 help='Write all thumbnail image formats to disk')
972 thumbnail
.add_option(
974 action
='store_true', dest
='list_thumbnails', default
=False,
975 help='Simulate and list all available thumbnail formats')
977 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
980 action
='store_true', dest
='writelink', default
=False,
981 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
984 action
='store_true', dest
='writeurllink', default
=False,
985 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
987 '--write-webloc-link',
988 action
='store_true', dest
='writewebloclink', default
=False,
989 help='Write a .webloc macOS internet shortcut')
991 '--write-desktop-link',
992 action
='store_true', dest
='writedesktoplink', default
=False,
993 help='Write a .desktop Linux internet shortcut')
995 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
997 '-x', '--extract-audio',
998 action
='store_true', dest
='extractaudio', default
=False,
999 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
1000 postproc
.add_option(
1001 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
1002 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
1003 postproc
.add_option(
1004 '--audio-quality', metavar
='QUALITY',
1005 dest
='audioquality', default
='5',
1006 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)')
1007 postproc
.add_option(
1009 metavar
='FORMAT', dest
='remuxvideo', default
=None,
1011 'Remux the video into another container if necessary (currently supported: mp4|mkv). '
1012 'If target container does not support the video/audio codec, remuxing will fail'))
1013 postproc
.add_option(
1015 metavar
='FORMAT', dest
='recodevideo', default
=None,
1016 help='Re-encode the video into another format if re-encoding is necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
1017 postproc
.add_option(
1018 '--postprocessor-args', '--ppa',
1019 metavar
='NAME:ARGS', dest
='postprocessor_args', default
={}, type='str',
1020 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
1021 callback_kwargs
={'default_key': 'default-compat', 'allowed_keys': r'\w+(?:\+\w+)?', 'process': compat_shlex_split}
,
1023 'Give these arguments to the postprocessors. '
1024 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
1025 'to give the argument to the specified postprocessor/executable. Supported postprocessors are: '
1026 'SponSkrub, ExtractAudio, VideoRemuxer, VideoConvertor, EmbedSubtitle, Metadata, Merger, '
1027 'FixupStretched, FixupM4a, FixupM3u8, SubtitlesConvertor and EmbedThumbnail. '
1028 'The supported executables are: SponSkrub, FFmpeg, FFprobe, avconf, avprobe and AtomicParsley. '
1029 'You can use this option multiple times to give different arguments to different postprocessors. '
1030 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
1031 'only when being used by the specified postprocessor. '
1032 'You can use this option multiple times (Alias: --ppa)'))
1033 postproc
.add_option(
1034 '-k', '--keep-video',
1035 action
='store_true', dest
='keepvideo', default
=False,
1036 help='Keep the intermediate video file on disk after post-processing')
1037 postproc
.add_option(
1039 action
='store_false', dest
='keepvideo',
1040 help='Delete the intermediate video file after post-processing (default)')
1041 postproc
.add_option(
1042 '--post-overwrites',
1043 action
='store_false', dest
='nopostoverwrites',
1044 help='Overwrite post-processed files (default)')
1045 postproc
.add_option(
1046 '--no-post-overwrites',
1047 action
='store_true', dest
='nopostoverwrites', default
=False,
1048 help='Do not overwrite post-processed files')
1049 postproc
.add_option(
1051 action
='store_true', dest
='embedsubtitles', default
=False,
1052 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1053 postproc
.add_option(
1055 action
='store_false', dest
='embedsubtitles',
1056 help='Do not embed subtitles (default)')
1057 postproc
.add_option(
1058 '--embed-thumbnail',
1059 action
='store_true', dest
='embedthumbnail', default
=False,
1060 help='Embed thumbnail in the audio as cover art')
1061 postproc
.add_option(
1062 '--no-embed-thumbnail',
1063 action
='store_false', dest
='embedthumbnail',
1064 help='Do not embed thumbnail (default)')
1065 postproc
.add_option(
1067 action
='store_true', dest
='addmetadata', default
=False,
1068 help='Write metadata to the video file')
1069 postproc
.add_option(
1070 '--no-add-metadata',
1071 action
='store_false', dest
='addmetadata',
1072 help='Do not write metadata (default)')
1073 postproc
.add_option(
1074 '--metadata-from-title',
1075 metavar
='FORMAT', dest
='metafromtitle',
1077 'Parse additional metadata like song title / artist from the video title. '
1078 'The format syntax is the same as --output. Regular expression with '
1079 'named capture groups may also be used. '
1080 'The parsed parameters replace existing values. '
1081 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
1082 '"Coldplay - Paradise". '
1083 'Example (regex): --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"'))
1084 postproc
.add_option(
1086 action
='store_true', dest
='xattrs', default
=False,
1087 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1088 postproc
.add_option(
1090 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
1092 'Automatically correct known faults of the file. '
1093 'One of never (do nothing), warn (only emit a warning), '
1094 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
1095 postproc
.add_option(
1096 '--prefer-avconv', '--no-prefer-ffmpeg',
1097 action
='store_false', dest
='prefer_ffmpeg',
1098 help='Prefer avconv over ffmpeg for running the postprocessors (Alias: --no-prefer-ffmpeg)')
1099 postproc
.add_option(
1100 '--prefer-ffmpeg', '--no-prefer-avconv',
1101 action
='store_true', dest
='prefer_ffmpeg',
1102 help='Prefer ffmpeg over avconv for running the postprocessors (default) (Alias: --no-prefer-avconv)')
1103 postproc
.add_option(
1104 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
1105 dest
='ffmpeg_location',
1106 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory (Alias: --avconv-location)')
1107 postproc
.add_option(
1109 metavar
='CMD', dest
='exec_cmd',
1110 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 {}\'')
1111 postproc
.add_option(
1112 '--convert-subs', '--convert-subtitles',
1113 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
1114 help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
1116 sponskrub
= optparse
.OptionGroup(parser
, 'SponSkrub (SponsorBlock) Options', description
=(
1117 'SponSkrub (https://github.com/pukkandan/SponSkrub) is a utility to mark/remove sponsor segments '
1118 'from downloaded YouTube videos using SponsorBlock API (https://sponsor.ajay.app)'))
1119 sponskrub
.add_option(
1121 action
='store_true', dest
='sponskrub', default
=None,
1123 'Use sponskrub to mark sponsored sections. '
1124 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
1125 sponskrub
.add_option(
1127 action
='store_false', dest
='sponskrub',
1128 help='Do not use sponskrub')
1129 sponskrub
.add_option(
1130 '--sponskrub-cut', default
=False,
1131 action
='store_true', dest
='sponskrub_cut',
1132 help='Cut out the sponsor sections instead of simply marking them')
1133 sponskrub
.add_option(
1134 '--no-sponskrub-cut',
1135 action
='store_false', dest
='sponskrub_cut',
1136 help='Simply mark the sponsor sections, not cut them out (default)')
1137 sponskrub
.add_option(
1138 '--sponskrub-force', default
=False,
1139 action
='store_true', dest
='sponskrub_force',
1140 help='Run sponskrub even if the video was already downloaded')
1141 sponskrub
.add_option(
1142 '--no-sponskrub-force',
1143 action
='store_true', dest
='sponskrub_force',
1144 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
1145 sponskrub
.add_option(
1146 '--sponskrub-location', metavar
='PATH',
1147 dest
='sponskrub_path', default
='',
1148 help='Location of the sponskrub binary; either the path to the binary or its containing directory')
1149 sponskrub
.add_option(
1150 '--sponskrub-args', dest
='sponskrub_args', metavar
='ARGS',
1151 help=optparse
.SUPPRESS_HELP
)
1153 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
1154 extractor
.add_option(
1155 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1156 action
='store_true', dest
='dynamic_mpd', default
=True,
1157 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
1158 extractor
.add_option(
1159 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1160 action
='store_false', dest
='dynamic_mpd',
1161 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
1163 parser
.add_option_group(general
)
1164 parser
.add_option_group(network
)
1165 parser
.add_option_group(geo
)
1166 parser
.add_option_group(selection
)
1167 parser
.add_option_group(downloader
)
1168 parser
.add_option_group(filesystem
)
1169 parser
.add_option_group(thumbnail
)
1170 parser
.add_option_group(link
)
1171 parser
.add_option_group(verbosity
)
1172 parser
.add_option_group(workarounds
)
1173 parser
.add_option_group(video_format
)
1174 parser
.add_option_group(subtitles
)
1175 parser
.add_option_group(authentication
)
1176 parser
.add_option_group(adobe_pass
)
1177 parser
.add_option_group(postproc
)
1178 parser
.add_option_group(sponskrub
)
1179 parser
.add_option_group(extractor
)
1181 if overrideArguments
is not None:
1182 opts
, args
= parser
.parse_args(overrideArguments
)
1184 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
1186 def compat_conf(conf
):
1187 if sys
.version_info
< (3,):
1188 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
1192 'command-line': compat_conf(sys
.argv
[1:]),
1193 'custom': [], 'home': [], 'portable': [], 'user': [], 'system': []}
1194 paths
= {'command-line': False}
1195 opts
, args
= parser
.parse_args(configs
['command-line'])
1198 if '--config-location' in configs
['command-line']:
1199 location
= compat_expanduser(opts
.config_location
)
1200 if os
.path
.isdir(location
):
1201 location
= os
.path
.join(location
, 'youtube-dlc.conf')
1202 if not os
.path
.exists(location
):
1203 parser
.error('config-location %s does not exist.' % location
)
1204 configs
['custom'] = _readOptions(location
, default
=None)
1205 if configs
['custom'] is None:
1206 configs
['custom'] = []
1208 paths
['custom'] = location
1209 if '--ignore-config' in configs
['command-line']:
1211 if '--ignore-config' in configs
['custom']:
1214 def read_options(path
, user
=False):
1215 func
= _readUserConf
if user
else _readOptions
1216 current_path
= os
.path
.join(path
, 'yt-dlp.conf')
1217 config
= func(current_path
, default
=None)
1219 config
, current_path
= config
1221 current_path
= os
.path
.join(path
, 'youtube-dlc.conf')
1222 config
= func(current_path
, default
=None)
1224 config
, current_path
= config
1227 return config
, current_path
1229 def get_portable_path():
1230 path
= os
.path
.dirname(sys
.argv
[0])
1231 if os
.path
.abspath(sys
.argv
[0]) != os
.path
.abspath(sys
.executable
): # Not packaged
1232 path
= os
.path
.join(path
, '..')
1233 return os
.path
.abspath(path
)
1235 configs
['portable'], paths
['portable'] = read_options(get_portable_path())
1236 if '--ignore-config' in configs
['portable']:
1239 def get_home_path():
1240 opts
= parser
.parse_args(configs
['portable'] + configs
['custom'] + configs
['command-line'])[0]
1241 return expand_path(opts
.paths
.get('home', '')).strip()
1243 configs
['home'], paths
['home'] = read_options(get_home_path())
1244 if '--ignore-config' in configs
['home']:
1247 configs
['system'], paths
['system'] = read_options('/etc')
1248 if '--ignore-config' in configs
['system']:
1251 configs
['user'], paths
['user'] = read_options('', True)
1252 if '--ignore-config' in configs
['user']:
1253 configs
['system'], paths
['system'] = [], None
1256 argv
= configs
['system'] + configs
['user'] + configs
['home'] + configs
['portable'] + configs
['custom'] + configs
['command-line']
1257 opts
, args
= parser
.parse_args(argv
)
1259 for label
in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
1261 if paths
.get(key
) is None:
1264 write_string('[debug] %s config file: %s\n' % (label
, paths
[key
]))
1265 write_string('[debug] %s config: %s\n' % (label
, repr(_hide_login_info(configs
[key
]))))
1267 return parser
, opts
, args