- def get_configs():
- if '--config-location' in configs['command-line']:
- location = compat_expanduser(opts.config_location)
- if os.path.isdir(location):
- location = os.path.join(location, 'yt-dlp.conf')
- if not os.path.exists(location):
- parser.error('config-location %s does not exist.' % location)
- configs['custom'] = _readOptions(location, default=None)
- if configs['custom'] is None:
- configs['custom'] = []
- else:
- paths['custom'] = location
- if '--ignore-config' in configs['command-line']:
- return
- if '--ignore-config' in configs['custom']:
- return
-
- def read_options(path, user=False):
- # Multiple package names can be given here
- # Eg: ('yt-dlp', 'youtube-dlc', 'youtube-dl') will look for
- # the configuration file of any of these three packages
- for package in ('yt-dlp',):
- if user:
- config, current_path = _readUserConf(package, default=None)
- else:
- current_path = os.path.join(path, '%s.conf' % package)
- config = _readOptions(current_path, default=None)
- if config is not None:
- return config, current_path
- return [], None
-
- configs['portable'], paths['portable'] = read_options(get_executable_path())
- if '--ignore-config' in configs['portable']:
- return
-
- def get_home_path():
- opts = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line'])[0]
- return expand_path(opts.paths.get('home', '')).strip()
-
- configs['home'], paths['home'] = read_options(get_home_path())
- if '--ignore-config' in configs['home']:
- return
-
- configs['system'], paths['system'] = read_options('/etc')
- if '--ignore-config' in configs['system']:
- return
-
- configs['user'], paths['user'] = read_options('', True)
- if '--ignore-config' in configs['user']:
- configs['system'], paths['system'] = [], None
-
- get_configs()
- argv = configs['system'] + configs['user'] + configs['home'] + configs['portable'] + configs['custom'] + configs['command-line']
- opts, args = parser.parse_args(argv)
- if opts.verbose:
- for label in ('System', 'User', 'Portable', 'Home', 'Custom', 'Command-line'):
- key = label.lower()
- if paths.get(key) is None:
- continue
- if paths[key]:
- write_string('[debug] %s config file: %s\n' % (label, paths[key]))
- write_string('[debug] %s config: %s\n' % (label, repr(_hide_login_info(configs[key]))))
-
- return parser, opts, args