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)
57 def _readUserConf(package_name
, default
=[]):
59 xdg_config_home
= compat_getenv('XDG_CONFIG_HOME') or compat_expanduser('~/.config')
60 userConfFile
= os
.path
.join(xdg_config_home
, package_name
, 'config')
61 if not os
.path
.isfile(userConfFile
):
62 userConfFile
= os
.path
.join(xdg_config_home
, '%s.conf' % package_name
)
63 userConf
= _readOptions(userConfFile
, default
=None)
64 if userConf
is not None:
68 appdata_dir
= compat_getenv('appdata')
70 userConfFile
= os
.path
.join(appdata_dir
, package_name
, 'config')
71 userConf
= _readOptions(userConfFile
, default
=None)
73 userConf
= _readOptions('%s.txt' % userConfFile
, default
=None)
74 if userConf
is not None:
78 userConfFile
= os
.path
.join(compat_expanduser('~'), '%s.conf' % package_name
)
79 userConf
= _readOptions(userConfFile
, default
=None)
81 userConf
= _readOptions('%s.txt' % userConfFile
, default
=None)
82 if userConf
is not None:
87 def _format_option_string(option
):
88 ''' ('-o', '--option') -> -o, --format METAVAR'''
92 if option
._short
_opts
:
93 opts
.append(option
._short
_opts
[0])
95 opts
.append(option
._long
_opts
[0])
99 if option
.takes_value():
100 opts
.append(' %s' % option
.metavar
)
104 def _comma_separated_values_options_callback(option
, opt_str
, value
, parser
):
105 setattr(parser
.values
, option
.dest
, value
.split(','))
107 def _dict_from_multiple_values_options_callback(
108 option
, opt_str
, value
, parser
, allowed_keys
=r
'[\w-]+', delimiter
=':', default_key
=None, process
=None):
110 out_dict
= getattr(parser
.values
, option
.dest
)
111 mobj
= re
.match(r
'(?i)(?P<key>%s)%s(?P<val>.*)$' % (allowed_keys
, delimiter
), value
)
113 key
, val
= mobj
.group('key').lower(), mobj
.group('val')
114 elif default_key
is not None:
115 key
, val
= default_key
, value
117 raise optparse
.OptionValueError(
118 'wrong %s formatting; it should be %s, not "%s"' % (opt_str
, option
.metavar
, value
))
119 out_dict
[key
] = process(val
) if callable(process
) else val
121 # No need to wrap help messages if we're on a wide console
122 columns
= compat_get_terminal_size().columns
123 max_width
= columns
if columns
else 80
124 max_help_position
= 80
126 fmt
= optparse
.IndentedHelpFormatter(width
=max_width
, max_help_position
=max_help_position
)
127 fmt
.format_option_strings
= _format_option_string
130 'version': __version__
,
132 'usage': '%prog [OPTIONS] URL [URL...]',
133 'conflict_handler': 'resolve',
136 parser
= optparse
.OptionParser(**compat_kwargs(kw
))
138 general
= optparse
.OptionGroup(parser
, 'General Options')
142 help='Print this help text and exit')
146 help='Print program version and exit')
149 action
='store_true', dest
='update_self',
150 help='[BROKEN] Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
152 '-i', '--ignore-errors', '--no-abort-on-error',
153 action
='store_true', dest
='ignoreerrors', default
=True,
154 help='Continue on download errors, for example to skip unavailable videos in a playlist (default) (Alias: --no-abort-on-error)')
156 '--abort-on-error', '--no-ignore-errors',
157 action
='store_false', dest
='ignoreerrors',
158 help='Abort downloading of further videos if an error occurs (Alias: --no-ignore-errors)')
161 action
='store_true', dest
='dump_user_agent', default
=False,
162 help='Display the current browser identification')
165 action
='store_true', dest
='list_extractors', default
=False,
166 help='List all supported extractors')
168 '--extractor-descriptions',
169 action
='store_true', dest
='list_extractor_descriptions', default
=False,
170 help='Output descriptions of all supported extractors')
172 '--force-generic-extractor',
173 action
='store_true', dest
='force_generic_extractor', default
=False,
174 help='Force extraction to use the generic extractor')
177 dest
='default_search', metavar
='PREFIX',
178 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')
180 '--ignore-config', '--no-config',
183 'Disable loading any configuration files except the one provided by --config-location. '
184 'When given inside a configuration file, no further configuration files are loaded. '
185 'Additionally, (for backward compatibility) if this option is found inside the '
186 'system configuration file, the user configuration is not loaded'))
189 dest
='config_location', metavar
='PATH',
190 help='Location of the configuration file; either the path to the config or its containing directory')
193 action
='store_const', dest
='extract_flat', const
='in_playlist', default
=False,
194 help='Do not extract the videos of a playlist, only list them')
197 action
='store_true', dest
='extract_flat',
198 help='Do not resolve the video urls')
200 '--no-flat-playlist',
201 action
='store_false', dest
='extract_flat',
202 help='Extract the videos of a playlist')
205 action
='store_true', dest
='mark_watched', default
=False,
206 help='Mark videos watched (YouTube only)')
209 action
='store_false', dest
='mark_watched', default
=False,
210 help='Do not mark videos watched')
213 action
='store_true', dest
='no_color',
215 help='Do not emit color codes in output')
217 network
= optparse
.OptionGroup(parser
, 'Network Options')
219 '--proxy', dest
='proxy',
220 default
=None, metavar
='URL',
222 'Use the specified HTTP/HTTPS/SOCKS proxy. To enable '
223 'SOCKS proxy, specify a proper scheme. For example '
224 'socks5://127.0.0.1:1080/. Pass in an empty string (--proxy "") '
225 'for direct connection'))
228 dest
='socket_timeout', type=float, default
=None, metavar
='SECONDS',
229 help='Time to wait before giving up, in seconds')
232 metavar
='IP', dest
='source_address', default
=None,
233 help='Client-side IP address to bind to',
236 '-4', '--force-ipv4',
237 action
='store_const', const
='0.0.0.0', dest
='source_address',
238 help='Make all connections via IPv4',
241 '-6', '--force-ipv6',
242 action
='store_const', const
='::', dest
='source_address',
243 help='Make all connections via IPv6',
246 geo
= optparse
.OptionGroup(parser
, 'Geo Restriction')
248 '--geo-verification-proxy',
249 dest
='geo_verification_proxy', default
=None, metavar
='URL',
251 'Use this proxy to verify the IP address for some geo-restricted sites. '
252 'The default proxy specified by --proxy (or none, if the option is not present) is used for the actual downloading'))
254 '--cn-verification-proxy',
255 dest
='cn_verification_proxy', default
=None, metavar
='URL',
256 help=optparse
.SUPPRESS_HELP
)
259 action
='store_true', dest
='geo_bypass', default
=True,
260 help='Bypass geographic restriction via faking X-Forwarded-For HTTP header')
263 action
='store_false', dest
='geo_bypass', default
=True,
264 help='Do not bypass geographic restriction via faking X-Forwarded-For HTTP header')
266 '--geo-bypass-country', metavar
='CODE',
267 dest
='geo_bypass_country', default
=None,
268 help='Force bypass geographic restriction with explicitly provided two-letter ISO 3166-2 country code')
270 '--geo-bypass-ip-block', metavar
='IP_BLOCK',
271 dest
='geo_bypass_ip_block', default
=None,
272 help='Force bypass geographic restriction with explicitly provided IP block in CIDR notation')
274 selection
= optparse
.OptionGroup(parser
, 'Video Selection')
275 selection
.add_option(
277 dest
='playliststart', metavar
='NUMBER', default
=1, type=int,
278 help='Playlist video to start at (default is %default)')
279 selection
.add_option(
281 dest
='playlistend', metavar
='NUMBER', default
=None, type=int,
282 help='Playlist video to end at (default is last)')
283 selection
.add_option(
285 dest
='playlist_items', metavar
='ITEM_SPEC', default
=None,
286 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')
287 selection
.add_option(
289 dest
='matchtitle', metavar
='REGEX',
290 help='Download only matching titles (regex or caseless sub-string)')
291 selection
.add_option(
293 dest
='rejecttitle', metavar
='REGEX',
294 help='Skip download for matching titles (regex or caseless sub-string)')
295 selection
.add_option(
297 dest
='max_downloads', metavar
='NUMBER', type=int, default
=None,
298 help='Abort after downloading NUMBER files')
299 selection
.add_option(
301 metavar
='SIZE', dest
='min_filesize', default
=None,
302 help='Do not download any videos smaller than SIZE (e.g. 50k or 44.6m)')
303 selection
.add_option(
305 metavar
='SIZE', dest
='max_filesize', default
=None,
306 help='Do not download any videos larger than SIZE (e.g. 50k or 44.6m)')
307 selection
.add_option(
309 metavar
='DATE', dest
='date', default
=None,
311 'Download only videos uploaded in this date. '
312 'The date can be "YYYYMMDD" or in the format '
313 '"(now|today)[+-][0-9](day|week|month|year)(s)?"'))
314 selection
.add_option(
316 metavar
='DATE', dest
='datebefore', default
=None,
318 'Download only videos uploaded on or before this date. '
319 'The date formats accepted is the same as --date'))
320 selection
.add_option(
322 metavar
='DATE', dest
='dateafter', default
=None,
324 'Download only videos uploaded on or after this date. '
325 'The date formats accepted is the same as --date'))
326 selection
.add_option(
328 metavar
='COUNT', dest
='min_views', default
=None, type=int,
329 help='Do not download any videos with less than COUNT views')
330 selection
.add_option(
332 metavar
='COUNT', dest
='max_views', default
=None, type=int,
333 help='Do not download any videos with more than COUNT views')
334 selection
.add_option(
336 metavar
='FILTER', dest
='match_filter', default
=None,
338 'Generic video filter. '
339 'Specify any key (see "OUTPUT TEMPLATE" for a list of available keys) to '
340 'match if the key is present, '
341 '!key to check if the key is not present, '
342 'key>NUMBER (like "comment_count > 12", also works with '
343 '>=, <, <=, !=, =) to compare against a number, '
344 'key = \'LITERAL\' (like "uploader = \'Mike Smith\'", also works with !=) '
345 'to match against a string literal '
346 'and & to require multiple matches. '
347 'Values which are not known are excluded unless you '
348 'put a question mark (?) after the operator. '
349 'For example, to only match videos that have been liked more than '
350 '100 times and disliked less than 50 times (or the dislike '
351 'functionality is not available at the given service), but who '
352 'also have a description, use --match-filter '
353 '"like_count > 100 & dislike_count <? 50 & description"'))
354 selection
.add_option(
356 metavar
='FILTER', dest
='match_filter', action
='store_const', const
=None,
357 help='Do not use generic video filter (default)')
358 selection
.add_option(
360 action
='store_true', dest
='noplaylist', default
=False,
361 help='Download only the video, if the URL refers to a video and a playlist')
362 selection
.add_option(
364 action
='store_false', dest
='noplaylist', default
=False,
365 help='Download the playlist, if the URL refers to a video and a playlist')
366 selection
.add_option(
368 metavar
='YEARS', dest
='age_limit', default
=None, type=int,
369 help='Download only videos suitable for the given age')
370 selection
.add_option(
371 '--download-archive', metavar
='FILE',
372 dest
='download_archive',
373 help='Download only videos not listed in the archive file. Record the IDs of all downloaded videos in it')
374 selection
.add_option(
375 '--break-on-existing',
376 action
='store_true', dest
='break_on_existing', default
=False,
377 help='Stop the download process when encountering a file that is in the archive')
378 selection
.add_option(
380 action
='store_true', dest
='break_on_reject', default
=False,
381 help='Stop the download process when encountering a file that has been filtered out')
382 selection
.add_option(
383 '--no-download-archive',
384 dest
='download_archive', action
="store_const", const
=None,
385 help='Do not use archive file (default)')
386 selection
.add_option(
388 dest
='include_ads', action
='store_true',
389 help='Download advertisements as well (experimental)')
390 selection
.add_option(
392 dest
='include_ads', action
='store_false',
393 help='Do not download advertisements (default)')
395 authentication
= optparse
.OptionGroup(parser
, 'Authentication Options')
396 authentication
.add_option(
398 dest
='username', metavar
='USERNAME',
399 help='Login with this account ID')
400 authentication
.add_option(
402 dest
='password', metavar
='PASSWORD',
403 help='Account password. If this option is left out, youtube-dlc will ask interactively')
404 authentication
.add_option(
406 dest
='twofactor', metavar
='TWOFACTOR',
407 help='Two-factor authentication code')
408 authentication
.add_option(
410 action
='store_true', dest
='usenetrc', default
=False,
411 help='Use .netrc authentication data')
412 authentication
.add_option(
414 dest
='videopassword', metavar
='PASSWORD',
415 help='Video password (vimeo, youku)')
417 adobe_pass
= optparse
.OptionGroup(parser
, 'Adobe Pass Options')
418 adobe_pass
.add_option(
420 dest
='ap_mso', metavar
='MSO',
421 help='Adobe Pass multiple-system operator (TV provider) identifier, use --ap-list-mso for a list of available MSOs')
422 adobe_pass
.add_option(
424 dest
='ap_username', metavar
='USERNAME',
425 help='Multiple-system operator account login')
426 adobe_pass
.add_option(
428 dest
='ap_password', metavar
='PASSWORD',
429 help='Multiple-system operator account password. If this option is left out, youtube-dlc will ask interactively')
430 adobe_pass
.add_option(
432 action
='store_true', dest
='ap_list_mso', default
=False,
433 help='List all supported multiple-system operators')
435 video_format
= optparse
.OptionGroup(parser
, 'Video Format Options')
436 video_format
.add_option(
438 action
='store', dest
='format', metavar
='FORMAT', default
=None,
439 help='Video format code, see "FORMAT SELECTION" for more details')
440 video_format
.add_option(
441 '-S', '--format-sort', metavar
='SORTORDER',
442 dest
='format_sort', default
=[],
443 action
='callback', callback
=_comma_separated_values_options_callback
, type='str',
444 help='Sort the formats by the fields given, see "Sorting Formats" for more details')
445 video_format
.add_option(
446 '--format-sort-force', '--S-force',
447 action
='store_true', dest
='format_sort_force', metavar
='FORMAT', default
=False,
449 'Force user specified sort order to have precedence over all fields, '
450 'see "Sorting Formats" for more details'))
451 video_format
.add_option(
452 '--no-format-sort-force',
453 action
='store_false', dest
='format_sort_force', metavar
='FORMAT', default
=False,
455 'Some fields have precedence over the user specified sort order (default), '
456 'see "Sorting Formats" for more details'))
457 video_format
.add_option(
458 '--video-multistreams',
459 action
='store_true', dest
='allow_multiple_video_streams', default
=False,
460 help='Allow multiple video streams to be merged into a single file')
461 video_format
.add_option(
462 '--no-video-multistreams',
463 action
='store_false', dest
='allow_multiple_video_streams',
464 help='Only one video stream is downloaded for each output file (default)')
465 video_format
.add_option(
466 '--audio-multistreams',
467 action
='store_true', dest
='allow_multiple_audio_streams', default
=False,
468 help='Allow multiple audio streams to be merged into a single file')
469 video_format
.add_option(
470 '--no-audio-multistreams',
471 action
='store_false', dest
='allow_multiple_audio_streams',
472 help='Only one audio stream is downloaded for each output file (default)')
473 video_format
.add_option(
475 action
='store_const', dest
='format', const
='all',
476 help='Download all available video formats')
477 video_format
.add_option(
478 '--prefer-free-formats',
479 action
='store_true', dest
='prefer_free_formats', default
=False,
480 help='Prefer free video formats over non-free formats of same quality')
481 video_format
.add_option(
482 '-F', '--list-formats',
483 action
='store_true', dest
='listformats',
484 help='List all available formats of requested videos')
485 video_format
.add_option(
486 '--list-formats-as-table',
487 action
='store_true', dest
='listformats_table', default
=True,
488 help='Present the output of -F in tabular form (default)')
489 video_format
.add_option(
490 '--list-formats-old', '--no-list-formats-as-table',
491 action
='store_false', dest
='listformats_table',
492 help='Present the output of -F in the old form (Alias: --no-list-formats-as-table)')
493 video_format
.add_option(
494 '--youtube-include-dash-manifest', '--no-youtube-skip-dash-manifest',
495 action
='store_true', dest
='youtube_include_dash_manifest', default
=True,
496 help='Download the DASH manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-dash-manifest)')
497 video_format
.add_option(
498 '--youtube-skip-dash-manifest', '--no-youtube-include-dash-manifest',
499 action
='store_false', dest
='youtube_include_dash_manifest',
500 help='Do not download the DASH manifests and related data on YouTube videos (Alias: --no-youtube-include-dash-manifest)')
501 video_format
.add_option(
502 '--youtube-include-hls-manifest', '--no-youtube-skip-hls-manifest',
503 action
='store_true', dest
='youtube_include_hls_manifest', default
=True,
504 help='Download the HLS manifests and related data on YouTube videos (default) (Alias: --no-youtube-skip-hls-manifest)')
505 video_format
.add_option(
506 '--youtube-skip-hls-manifest', '--no-youtube-include-hls-manifest',
507 action
='store_false', dest
='youtube_include_hls_manifest',
508 help='Do not download the HLS manifests and related data on YouTube videos (Alias: --no-youtube-include-hls-manifest)')
509 video_format
.add_option(
510 '--merge-output-format',
511 action
='store', dest
='merge_output_format', metavar
='FORMAT', default
=None,
513 'If a merge is required (e.g. bestvideo+bestaudio), '
514 'output to given container format. One of mkv, mp4, ogg, webm, flv. '
515 'Ignored if no merge is required'))
517 subtitles
= optparse
.OptionGroup(parser
, 'Subtitle Options')
518 subtitles
.add_option(
519 '--write-subs', '--write-srt',
520 action
='store_true', dest
='writesubtitles', default
=False,
521 help='Write subtitle file')
522 subtitles
.add_option(
523 '--no-write-subs', '--no-write-srt',
524 action
='store_false', dest
='writesubtitles',
525 help='Do not write subtitle file (default)')
526 subtitles
.add_option(
527 '--write-auto-subs', '--write-automatic-subs',
528 action
='store_true', dest
='writeautomaticsub', default
=False,
529 help='Write automatically generated subtitle file (YouTube only)')
530 subtitles
.add_option(
531 '--no-write-auto-subs', '--no-write-automatic-subs',
532 action
='store_false', dest
='writeautomaticsub', default
=False,
533 help='Do not write automatically generated subtitle file (default)')
534 subtitles
.add_option(
536 action
='store_true', dest
='allsubtitles', default
=False,
537 help='Download all the available subtitles of the video')
538 subtitles
.add_option(
540 action
='store_true', dest
='listsubtitles', default
=False,
541 help='List all available subtitles for the video')
542 subtitles
.add_option(
544 action
='store', dest
='subtitlesformat', metavar
='FORMAT', default
='best',
545 help='Subtitle format, accepts formats preference, for example: "srt" or "ass/srt/best"')
546 subtitles
.add_option(
547 '--sub-lang', '--sub-langs', '--srt-lang',
548 action
='callback', dest
='subtitleslangs', metavar
='LANGS', type='str',
549 default
=[], callback
=_comma_separated_values_options_callback
,
550 help='Languages of the subtitles to download (optional) separated by commas, use --list-subs for available language tags')
552 downloader
= optparse
.OptionGroup(parser
, 'Download Options')
553 downloader
.add_option(
554 '-r', '--limit-rate', '--rate-limit',
555 dest
='ratelimit', metavar
='RATE',
556 help='Maximum download rate in bytes per second (e.g. 50K or 4.2M)')
557 downloader
.add_option(
559 dest
='retries', metavar
='RETRIES', default
=10,
560 help='Number of retries (default is %default), or "infinite"')
561 downloader
.add_option(
562 '--fragment-retries',
563 dest
='fragment_retries', metavar
='RETRIES', default
=10,
564 help='Number of retries for a fragment (default is %default), or "infinite" (DASH, hlsnative and ISM)')
565 downloader
.add_option(
566 '--skip-unavailable-fragments', '--no-abort-on-unavailable-fragment',
567 action
='store_true', dest
='skip_unavailable_fragments', default
=True,
568 help='Skip unavailable fragments for DASH, hlsnative and ISM (default) (Alias: --no-abort-on-unavailable-fragment)')
569 downloader
.add_option(
570 '--abort-on-unavailable-fragment', '--no-skip-unavailable-fragments',
571 action
='store_false', dest
='skip_unavailable_fragments',
572 help='Abort downloading if a fragment is unavailable (Alias: --no-skip-unavailable-fragments)')
573 downloader
.add_option(
575 action
='store_true', dest
='keep_fragments', default
=False,
576 help='Keep downloaded fragments on disk after downloading is finished')
577 downloader
.add_option(
578 '--no-keep-fragments',
579 action
='store_false', dest
='keep_fragments',
580 help='Delete downloaded fragments after downloading is finished (default)')
581 downloader
.add_option(
583 dest
='buffersize', metavar
='SIZE', default
='1024',
584 help='Size of download buffer (e.g. 1024 or 16K) (default is %default)')
585 downloader
.add_option(
587 action
='store_false', dest
='noresizebuffer',
588 help='The buffer size is automatically resized from an initial value of --buffer-size (default)')
589 downloader
.add_option(
590 '--no-resize-buffer',
591 action
='store_true', dest
='noresizebuffer', default
=False,
592 help='Do not automatically adjust the buffer size')
593 downloader
.add_option(
595 dest
='http_chunk_size', metavar
='SIZE', default
=None,
597 'Size of a chunk for chunk-based HTTP downloading (e.g. 10485760 or 10M) (default is disabled). '
598 'May be useful for bypassing bandwidth throttling imposed by a webserver (experimental)'))
599 downloader
.add_option(
601 action
='store_true', dest
='test', default
=False,
602 help=optparse
.SUPPRESS_HELP
)
603 downloader
.add_option(
604 '--playlist-reverse',
606 help='Download playlist videos in reverse order')
607 downloader
.add_option(
608 '--no-playlist-reverse',
609 action
='store_false', dest
='playlist_reverse',
610 help='Download playlist videos in default order (default)')
611 downloader
.add_option(
614 help='Download playlist videos in random order')
615 downloader
.add_option(
616 '--xattr-set-filesize',
617 dest
='xattr_set_filesize', action
='store_true',
618 help='Set file xattribute ytdl.filesize with expected file size')
619 downloader
.add_option(
620 '--hls-prefer-native',
621 dest
='hls_prefer_native', action
='store_true', default
=None,
622 help='Use the native HLS downloader instead of ffmpeg')
623 downloader
.add_option(
624 '--hls-prefer-ffmpeg',
625 dest
='hls_prefer_native', action
='store_false', default
=None,
626 help='Use ffmpeg instead of the native HLS downloader')
627 downloader
.add_option(
629 dest
='hls_use_mpegts', action
='store_true',
631 'Use the mpegts container for HLS videos, allowing to play the '
632 'video while downloading (some players may not be able to play it)'))
633 downloader
.add_option(
634 '--external-downloader',
635 dest
='external_downloader', metavar
='NAME',
637 'Use the specified external downloader. '
638 'Currently supports %s' % ', '.join(list_external_downloaders())))
639 downloader
.add_option(
640 '--downloader-args', '--external-downloader-args',
641 metavar
='NAME:ARGS', dest
='external_downloader_args', default
={}, type='str',
642 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
643 callback_kwargs
={'default_key': 'default', 'process': compat_shlex_split}
,
645 'Give these arguments to the external downloader. '
646 'Specify the downloader name and the arguments separated by a colon ":". '
647 'You can use this option multiple times (Alias: --external-downloader-args)'))
649 workarounds
= optparse
.OptionGroup(parser
, 'Workarounds')
650 workarounds
.add_option(
652 dest
='encoding', metavar
='ENCODING',
653 help='Force the specified encoding (experimental)')
654 workarounds
.add_option(
655 '--no-check-certificate',
656 action
='store_true', dest
='no_check_certificate', default
=False,
657 help='Suppress HTTPS certificate validation')
658 workarounds
.add_option(
659 '--prefer-insecure', '--prefer-unsecure',
660 action
='store_true', dest
='prefer_insecure',
661 help='Use an unencrypted connection to retrieve information about the video. (Currently supported only for YouTube)')
662 workarounds
.add_option(
664 metavar
='UA', dest
='user_agent',
665 help='Specify a custom user agent')
666 workarounds
.add_option(
668 metavar
='URL', dest
='referer', default
=None,
669 help='Specify a custom referer, use if the video access is restricted to one domain',
671 workarounds
.add_option(
673 metavar
='FIELD:VALUE', dest
='headers', default
={}, type='str',
674 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
675 help='Specify a custom HTTP header and its value, separated by a colon ":". You can use this option multiple times',
677 workarounds
.add_option(
679 dest
='bidi_workaround', action
='store_true',
680 help='Work around terminals that lack bidirectional text support. Requires bidiv or fribidi executable in PATH')
681 workarounds
.add_option(
682 '--sleep-interval', '--min-sleep-interval', metavar
='SECONDS',
683 dest
='sleep_interval', type=float,
685 'Number of seconds to sleep before each download when used alone '
686 'or a lower bound of a range for randomized sleep before each download '
687 '(minimum possible number of seconds to sleep) when used along with '
688 '--max-sleep-interval'))
689 workarounds
.add_option(
690 '--max-sleep-interval', metavar
='SECONDS',
691 dest
='max_sleep_interval', type=float,
693 'Upper bound of a range for randomized sleep before each download '
694 '(maximum possible number of seconds to sleep). Must only be used '
695 'along with --min-sleep-interval'))
696 workarounds
.add_option(
697 '--sleep-subtitles', metavar
='SECONDS',
698 dest
='sleep_interval_subtitles', default
=0, type=int,
699 help='Enforce sleep interval on subtitles as well')
701 verbosity
= optparse
.OptionGroup(parser
, 'Verbosity / Simulation Options')
702 verbosity
.add_option(
704 action
='store_true', dest
='quiet', default
=False,
705 help='Activate quiet mode')
706 verbosity
.add_option(
708 dest
='no_warnings', action
='store_true', default
=False,
709 help='Ignore warnings')
710 verbosity
.add_option(
712 action
='store_true', dest
='simulate', default
=False,
713 help='Do not download the video and do not write anything to disk')
714 verbosity
.add_option(
715 '--skip-download', '--no-download',
716 action
='store_true', dest
='skip_download', default
=False,
717 help='Do not download the video')
718 verbosity
.add_option(
720 action
='store_true', dest
='geturl', default
=False,
721 help='Simulate, quiet but print URL')
722 verbosity
.add_option(
724 action
='store_true', dest
='gettitle', default
=False,
725 help='Simulate, quiet but print title')
726 verbosity
.add_option(
728 action
='store_true', dest
='getid', default
=False,
729 help='Simulate, quiet but print id')
730 verbosity
.add_option(
732 action
='store_true', dest
='getthumbnail', default
=False,
733 help='Simulate, quiet but print thumbnail URL')
734 verbosity
.add_option(
736 action
='store_true', dest
='getdescription', default
=False,
737 help='Simulate, quiet but print video description')
738 verbosity
.add_option(
740 action
='store_true', dest
='getduration', default
=False,
741 help='Simulate, quiet but print video length')
742 verbosity
.add_option(
744 action
='store_true', dest
='getfilename', default
=False,
745 help='Simulate, quiet but print output filename')
746 verbosity
.add_option(
748 action
='store_true', dest
='getformat', default
=False,
749 help='Simulate, quiet but print output format')
750 verbosity
.add_option(
752 action
='store_true', dest
='dumpjson', default
=False,
753 help='Simulate, quiet but print JSON information. See "OUTPUT TEMPLATE" for a description of available keys')
754 verbosity
.add_option(
755 '-J', '--dump-single-json',
756 action
='store_true', dest
='dump_single_json', default
=False,
758 'Simulate, quiet but print JSON information for each command-line argument. '
759 'If the URL refers to a playlist, dump the whole playlist information in a single line'))
760 verbosity
.add_option(
762 action
='store_true', dest
='print_json', default
=False,
763 help='Be quiet and print the video information as JSON (video is still being downloaded)')
764 verbosity
.add_option(
765 '--force-write-archive', '--force-write-download-archive', '--force-download-archive',
766 action
='store_true', dest
='force_write_download_archive', default
=False,
768 'Force download archive entries to be written as far as no errors occur,'
769 'even if -s or another simulation switch is used (Alias: --force-download-archive)'))
770 verbosity
.add_option(
772 action
='store_true', dest
='progress_with_newline', default
=False,
773 help='Output progress bar as new lines')
774 verbosity
.add_option(
776 action
='store_true', dest
='noprogress', default
=False,
777 help='Do not print progress bar')
778 verbosity
.add_option(
780 action
='store_true', dest
='consoletitle', default
=False,
781 help='Display progress in console titlebar')
782 verbosity
.add_option(
784 action
='store_true', dest
='verbose', default
=False,
785 help='Print various debugging information')
786 verbosity
.add_option(
787 '--dump-pages', '--dump-intermediate-pages',
788 action
='store_true', dest
='dump_intermediate_pages', default
=False,
789 help='Print downloaded pages encoded using base64 to debug problems (very verbose)')
790 verbosity
.add_option(
792 action
='store_true', dest
='write_pages', default
=False,
793 help='Write downloaded intermediary pages to files in the current directory to debug problems')
794 verbosity
.add_option(
795 '--youtube-print-sig-code',
796 action
='store_true', dest
='youtube_print_sig_code', default
=False,
797 help=optparse
.SUPPRESS_HELP
)
798 verbosity
.add_option(
799 '--print-traffic', '--dump-headers',
800 dest
='debug_printtraffic', action
='store_true', default
=False,
801 help='Display sent and read HTTP traffic')
802 verbosity
.add_option(
804 dest
='call_home', action
='store_true', default
=False,
805 help='[Broken] Contact the youtube-dlc server for debugging')
806 verbosity
.add_option(
808 dest
='call_home', action
='store_false',
809 help='Do not contact the youtube-dlc server for debugging (default)')
811 filesystem
= optparse
.OptionGroup(parser
, 'Filesystem Options')
812 filesystem
.add_option(
813 '-a', '--batch-file',
814 dest
='batchfile', metavar
='FILE',
815 help="File containing URLs to download ('-' for stdin), one URL per line. "
816 "Lines starting with '#', ';' or ']' are considered as comments and ignored")
817 filesystem
.add_option(
818 '--id', default
=False,
819 action
='store_true', dest
='useid', help=optparse
.SUPPRESS_HELP
)
820 filesystem
.add_option(
822 dest
='outtmpl', metavar
='TEMPLATE',
823 help='Output filename template, see "OUTPUT TEMPLATE" for details')
824 filesystem
.add_option(
826 dest
='autonumber_size', metavar
='NUMBER', type=int,
827 help=optparse
.SUPPRESS_HELP
)
828 filesystem
.add_option(
829 '--autonumber-start',
830 dest
='autonumber_start', metavar
='NUMBER', default
=1, type=int,
831 help='Specify the start value for %(autonumber)s (default is %default)')
832 filesystem
.add_option(
833 '--restrict-filenames',
834 action
='store_true', dest
='restrictfilenames', default
=False,
835 help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames')
836 filesystem
.add_option(
837 '--no-restrict-filenames',
838 action
='store_false', dest
='restrictfilenames', default
=False,
839 help='Allow Unicode characters, "&" and spaces in filenames (default)')
840 filesystem
.add_option(
841 '-A', '--auto-number',
842 action
='store_true', dest
='autonumber', default
=False,
843 help=optparse
.SUPPRESS_HELP
)
844 filesystem
.add_option(
846 action
='store_true', dest
='usetitle', default
=False,
847 help=optparse
.SUPPRESS_HELP
)
848 filesystem
.add_option(
849 '-l', '--literal', default
=False,
850 action
='store_true', dest
='usetitle',
851 help=optparse
.SUPPRESS_HELP
)
852 filesystem
.add_option(
853 '-w', '--no-overwrites',
854 action
='store_false', dest
='overwrites', default
=None,
855 help='Do not overwrite any files')
856 filesystem
.add_option(
857 '--force-overwrites', '--yes-overwrites',
858 action
='store_true', dest
='overwrites',
859 help='Overwrite all video and metadata files. This option includes --no-continue')
860 filesystem
.add_option(
861 '--no-force-overwrites',
862 action
='store_const', dest
='overwrites', const
=None,
863 help='Do not overwrite the video, but overwrite related files (default)')
864 filesystem
.add_option(
866 action
='store_true', dest
='continue_dl', default
=True,
867 help='Resume partially downloaded files (default)')
868 filesystem
.add_option(
870 action
='store_false', dest
='continue_dl',
871 help='Restart download of partially downloaded files from beginning')
872 filesystem
.add_option(
874 action
='store_false', dest
='nopart', default
=False,
875 help='Use .part files instead of writing directly into output file (default)')
876 filesystem
.add_option(
878 action
='store_true', dest
='nopart',
879 help='Do not use .part files - write directly into output file')
880 filesystem
.add_option(
882 action
='store_true', dest
='updatetime', default
=True,
883 help='Use the Last-modified header to set the file modification time (default)')
884 filesystem
.add_option(
886 action
='store_false', dest
='updatetime',
887 help='Do not use the Last-modified header to set the file modification time')
888 filesystem
.add_option(
889 '--write-description',
890 action
='store_true', dest
='writedescription', default
=False,
891 help='Write video description to a .description file')
892 filesystem
.add_option(
893 '--no-write-description',
894 action
='store_false', dest
='writedescription',
895 help='Do not write video description (default)')
896 filesystem
.add_option(
898 action
='store_true', dest
='writeinfojson', default
=False,
899 help='Write video metadata to a .info.json file')
900 filesystem
.add_option(
901 '--no-write-info-json',
902 action
='store_false', dest
='writeinfojson',
903 help='Do not write video metadata (default)')
904 filesystem
.add_option(
905 '--write-annotations',
906 action
='store_true', dest
='writeannotations', default
=False,
907 help='Write video annotations to a .annotations.xml file')
908 filesystem
.add_option(
909 '--no-write-annotations',
910 action
='store_false', dest
='writeannotations',
911 help='Do not write video annotations (default)')
912 filesystem
.add_option(
913 '--load-info-json', '--load-info',
914 dest
='load_info_filename', metavar
='FILE',
915 help='JSON file containing the video information (created with the "--write-info-json" option)')
916 filesystem
.add_option(
918 dest
='cookiefile', metavar
='FILE',
919 help='File to read cookies from and dump cookie jar in')
920 filesystem
.add_option(
922 action
='store_const', const
=None, dest
='cookiefile', metavar
='FILE',
923 help='Do not read/dump cookies (default)')
924 filesystem
.add_option(
925 '--cache-dir', dest
='cachedir', default
=None, metavar
='DIR',
926 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')
927 filesystem
.add_option(
928 '--no-cache-dir', action
='store_false', dest
='cachedir',
929 help='Disable filesystem caching')
930 filesystem
.add_option(
932 action
='store_true', dest
='rm_cachedir',
933 help='Delete all filesystem cache files')
934 filesystem
.add_option(
935 '--trim-file-name', metavar
='LENGTH',
936 dest
='trim_file_name', default
=0, type=int,
937 help='Limit the filename length (extension excluded)')
939 thumbnail
= optparse
.OptionGroup(parser
, 'Thumbnail Images')
940 thumbnail
.add_option(
942 action
='store_true', dest
='writethumbnail', default
=False,
943 help='Write thumbnail image to disk')
944 thumbnail
.add_option(
945 '--no-write-thumbnail',
946 action
='store_false', dest
='writethumbnail',
947 help='Do not write thumbnail image to disk (default)')
948 thumbnail
.add_option(
949 '--write-all-thumbnails',
950 action
='store_true', dest
='write_all_thumbnails', default
=False,
951 help='Write all thumbnail image formats to disk')
952 thumbnail
.add_option(
954 action
='store_true', dest
='list_thumbnails', default
=False,
955 help='Simulate and list all available thumbnail formats')
957 link
= optparse
.OptionGroup(parser
, 'Internet Shortcut Options')
960 action
='store_true', dest
='writelink', default
=False,
961 help='Write an internet shortcut file, depending on the current platform (.url, .webloc or .desktop). The URL may be cached by the OS')
964 action
='store_true', dest
='writeurllink', default
=False,
965 help='Write a .url Windows internet shortcut. The OS caches the URL based on the file path')
967 '--write-webloc-link',
968 action
='store_true', dest
='writewebloclink', default
=False,
969 help='Write a .webloc macOS internet shortcut')
971 '--write-desktop-link',
972 action
='store_true', dest
='writedesktoplink', default
=False,
973 help='Write a .desktop Linux internet shortcut')
975 postproc
= optparse
.OptionGroup(parser
, 'Post-Processing Options')
977 '-x', '--extract-audio',
978 action
='store_true', dest
='extractaudio', default
=False,
979 help='Convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)')
981 '--audio-format', metavar
='FORMAT', dest
='audioformat', default
='best',
982 help='Specify audio format: "best", "aac", "flac", "mp3", "m4a", "opus", "vorbis", or "wav"; "%default" by default; No effect without -x')
984 '--audio-quality', metavar
='QUALITY',
985 dest
='audioquality', default
='5',
986 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)')
989 metavar
='FORMAT', dest
='remuxvideo', default
=None,
991 'Remux the video into another container if necessary (currently supported: mp4|mkv). '
992 'If target container does not support the video/audio codec, remuxing will fail'))
995 metavar
='FORMAT', dest
='recodevideo', default
=None,
996 help='Re-encode the video into another format if re-encoding is necessary (currently supported: mp4|flv|ogg|webm|mkv|avi)')
998 '--postprocessor-args', '--ppa',
999 metavar
='NAME:ARGS', dest
='postprocessor_args', default
={}, type='str',
1000 action
='callback', callback
=_dict_from_multiple_values_options_callback
,
1001 callback_kwargs
={'default_key': 'default-compat', 'allowed_keys': r'\w+(?:\+\w+)?', 'process': compat_shlex_split}
,
1003 'Give these arguments to the postprocessors. '
1004 'Specify the postprocessor/executable name and the arguments separated by a colon ":" '
1005 'to give the argument to the specified postprocessor/executable. Supported postprocessors are: '
1006 'SponSkrub, ExtractAudio, VideoRemuxer, VideoConvertor, EmbedSubtitle, Metadata, Merger, '
1007 'FixupStretched, FixupM4a, FixupM3u8, SubtitlesConvertor and EmbedThumbnail. '
1008 'The supported executables are: SponSkrub, FFmpeg, FFprobe, avconf, avprobe and AtomicParsley. '
1009 'You can use this option multiple times to give different arguments to different postprocessors. '
1010 'You can also specify "PP+EXE:ARGS" to give the arguments to the specified executable '
1011 'only when being used by the specified postprocessor. '
1012 'You can use this option multiple times (Alias: --ppa)'))
1013 postproc
.add_option(
1014 '-k', '--keep-video',
1015 action
='store_true', dest
='keepvideo', default
=False,
1016 help='Keep the intermediate video file on disk after post-processing')
1017 postproc
.add_option(
1019 action
='store_false', dest
='keepvideo',
1020 help='Delete the intermediate video file after post-processing (default)')
1021 postproc
.add_option(
1022 '--post-overwrites',
1023 action
='store_false', dest
='nopostoverwrites',
1024 help='Overwrite post-processed files (default)')
1025 postproc
.add_option(
1026 '--no-post-overwrites',
1027 action
='store_true', dest
='nopostoverwrites', default
=False,
1028 help='Do not overwrite post-processed files')
1029 postproc
.add_option(
1031 action
='store_true', dest
='embedsubtitles', default
=False,
1032 help='Embed subtitles in the video (only for mp4, webm and mkv videos)')
1033 postproc
.add_option(
1035 action
='store_false', dest
='embedsubtitles',
1036 help='Do not embed subtitles (default)')
1037 postproc
.add_option(
1038 '--embed-thumbnail',
1039 action
='store_true', dest
='embedthumbnail', default
=False,
1040 help='Embed thumbnail in the audio as cover art')
1041 postproc
.add_option(
1042 '--no-embed-thumbnail',
1043 action
='store_false', dest
='embedthumbnail',
1044 help='Do not embed thumbnail (default)')
1045 postproc
.add_option(
1047 action
='store_true', dest
='addmetadata', default
=False,
1048 help='Write metadata to the video file')
1049 postproc
.add_option(
1050 '--no-add-metadata',
1051 action
='store_false', dest
='addmetadata',
1052 help='Do not write metadata (default)')
1053 postproc
.add_option(
1054 '--metadata-from-title',
1055 metavar
='FORMAT', dest
='metafromtitle',
1057 'Parse additional metadata like song title / artist from the video title. '
1058 'The format syntax is the same as --output. Regular expression with '
1059 'named capture groups may also be used. '
1060 'The parsed parameters replace existing values. '
1061 'Example: --metadata-from-title "%(artist)s - %(title)s" matches a title like '
1062 '"Coldplay - Paradise". '
1063 'Example (regex): --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"'))
1064 postproc
.add_option(
1066 action
='store_true', dest
='xattrs', default
=False,
1067 help='Write metadata to the video file\'s xattrs (using dublin core and xdg standards)')
1068 postproc
.add_option(
1070 metavar
='POLICY', dest
='fixup', default
='detect_or_warn',
1072 'Automatically correct known faults of the file. '
1073 'One of never (do nothing), warn (only emit a warning), '
1074 'detect_or_warn (the default; fix file if we can, warn otherwise)'))
1075 postproc
.add_option(
1076 '--prefer-avconv', '--no-prefer-ffmpeg',
1077 action
='store_false', dest
='prefer_ffmpeg',
1078 help='Prefer avconv over ffmpeg for running the postprocessors (Alias: --no-prefer-ffmpeg)')
1079 postproc
.add_option(
1080 '--prefer-ffmpeg', '--no-prefer-avconv',
1081 action
='store_true', dest
='prefer_ffmpeg',
1082 help='Prefer ffmpeg over avconv for running the postprocessors (default) (Alias: --no-prefer-avconv)')
1083 postproc
.add_option(
1084 '--ffmpeg-location', '--avconv-location', metavar
='PATH',
1085 dest
='ffmpeg_location',
1086 help='Location of the ffmpeg/avconv binary; either the path to the binary or its containing directory (Alias: --avconv-location)')
1087 postproc
.add_option(
1089 metavar
='CMD', dest
='exec_cmd',
1090 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 {}\'')
1091 postproc
.add_option(
1092 '--convert-subs', '--convert-subtitles',
1093 metavar
='FORMAT', dest
='convertsubtitles', default
=None,
1094 help='Convert the subtitles to other format (currently supported: srt|ass|vtt|lrc)')
1096 sponskrub
= optparse
.OptionGroup(parser
, 'SponSkrub (SponsorBlock) Options', description
=(
1097 'SponSkrub (https://github.com/pukkandan/SponSkrub) is a utility to mark/remove sponsor segments '
1098 'from downloaded YouTube videos using SponsorBlock API (https://sponsor.ajay.app)'))
1099 sponskrub
.add_option(
1101 action
='store_true', dest
='sponskrub', default
=None,
1103 'Use sponskrub to mark sponsored sections. '
1104 'This is enabled by default if the sponskrub binary exists (Youtube only)'))
1105 sponskrub
.add_option(
1107 action
='store_false', dest
='sponskrub',
1108 help='Do not use sponskrub')
1109 sponskrub
.add_option(
1110 '--sponskrub-cut', default
=False,
1111 action
='store_true', dest
='sponskrub_cut',
1112 help='Cut out the sponsor sections instead of simply marking them')
1113 sponskrub
.add_option(
1114 '--no-sponskrub-cut',
1115 action
='store_false', dest
='sponskrub_cut',
1116 help='Simply mark the sponsor sections, not cut them out (default)')
1117 sponskrub
.add_option(
1118 '--sponskrub-force', default
=False,
1119 action
='store_true', dest
='sponskrub_force',
1120 help='Run sponskrub even if the video was already downloaded')
1121 sponskrub
.add_option(
1122 '--no-sponskrub-force',
1123 action
='store_true', dest
='sponskrub_force',
1124 help='Do not cut out the sponsor sections if the video was already downloaded (default)')
1125 sponskrub
.add_option(
1126 '--sponskrub-location', metavar
='PATH',
1127 dest
='sponskrub_path', default
='',
1128 help='Location of the sponskrub binary; either the path to the binary or its containing directory')
1129 sponskrub
.add_option(
1130 '--sponskrub-args', dest
='sponskrub_args', metavar
='ARGS',
1131 help=optparse
.SUPPRESS_HELP
)
1133 extractor
= optparse
.OptionGroup(parser
, 'Extractor Options')
1134 extractor
.add_option(
1135 '--allow-dynamic-mpd', '--no-ignore-dynamic-mpd',
1136 action
='store_true', dest
='dynamic_mpd', default
=True,
1137 help='Process dynamic DASH manifests (default) (Alias: --no-ignore-dynamic-mpd)')
1138 extractor
.add_option(
1139 '--ignore-dynamic-mpd', '--no-allow-dynamic-mpd',
1140 action
='store_false', dest
='dynamic_mpd',
1141 help='Do not process dynamic DASH manifests (Alias: --no-allow-dynamic-mpd)')
1143 parser
.add_option_group(general
)
1144 parser
.add_option_group(network
)
1145 parser
.add_option_group(geo
)
1146 parser
.add_option_group(selection
)
1147 parser
.add_option_group(downloader
)
1148 parser
.add_option_group(filesystem
)
1149 parser
.add_option_group(thumbnail
)
1150 parser
.add_option_group(link
)
1151 parser
.add_option_group(verbosity
)
1152 parser
.add_option_group(workarounds
)
1153 parser
.add_option_group(video_format
)
1154 parser
.add_option_group(subtitles
)
1155 parser
.add_option_group(authentication
)
1156 parser
.add_option_group(adobe_pass
)
1157 parser
.add_option_group(postproc
)
1158 parser
.add_option_group(sponskrub
)
1159 parser
.add_option_group(extractor
)
1161 if overrideArguments
is not None:
1162 opts
, args
= parser
.parse_args(overrideArguments
)
1164 write_string('[debug] Override config: ' + repr(overrideArguments
) + '\n')
1166 def compat_conf(conf
):
1167 if sys
.version_info
< (3,):
1168 return [a
.decode(preferredencoding(), 'replace') for a
in conf
]
1172 'command_line': compat_conf(sys
.argv
[1:]),
1173 'custom': [], 'portable': [], 'user': [], 'system': []}
1174 opts
, args
= parser
.parse_args(configs
['command_line'])
1177 if '--config-location' in configs
['command_line']:
1178 location
= compat_expanduser(opts
.config_location
)
1179 if os
.path
.isdir(location
):
1180 location
= os
.path
.join(location
, 'youtube-dlc.conf')
1181 if not os
.path
.exists(location
):
1182 parser
.error('config-location %s does not exist.' % location
)
1183 configs
['custom'] = _readOptions(location
)
1185 if '--ignore-config' in configs
['command_line']:
1187 if '--ignore-config' in configs
['custom']:
1190 def get_portable_path():
1191 path
= os
.path
.dirname(sys
.argv
[0])
1192 if os
.path
.abspath(sys
.argv
[0]) != os
.path
.abspath(sys
.executable
): # Not packaged
1193 path
= os
.path
.join(path
, '..')
1194 return os
.path
.abspath(path
)
1196 run_path
= get_portable_path()
1197 configs
['portable'] = _readOptions(os
.path
.join(run_path
, 'yt-dlp.conf'), default
=None)
1198 if configs
['portable'] is None:
1199 configs
['portable'] = _readOptions(os
.path
.join(run_path
, 'youtube-dlc.conf'))
1201 if '--ignore-config' in configs
['portable']:
1203 configs
['system'] = _readOptions('/etc/yt-dlp.conf', default
=None)
1204 if configs
['system'] is None:
1205 configs
['system'] = _readOptions('/etc/youtube-dlc.conf')
1207 if '--ignore-config' in configs
['system']:
1209 configs
['user'] = _readUserConf('yt-dlp', default
=None)
1210 if configs
['user'] is None:
1211 configs
['user'] = _readUserConf('youtube-dlc')
1212 if '--ignore-config' in configs
['user']:
1213 configs
['system'] = []
1216 argv
= configs
['system'] + configs
['user'] + configs
['portable'] + configs
['custom'] + configs
['command_line']
1217 opts
, args
= parser
.parse_args(argv
)
1219 for conf_label
, conf
in (
1220 ('System config', configs
['system']),
1221 ('User config', configs
['user']),
1222 ('Portable config', configs
['portable']),
1223 ('Custom config', configs
['custom']),
1224 ('Command-line args', configs
['command_line'])):
1225 write_string('[debug] %s: %s\n' % (conf_label
, repr(_hide_login_info(conf
))))
1227 return parser
, opts
, args