- def read_options(name, path, user=False):
- ''' loads config files and returns ignoreconfig '''
- # 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:
- current_path = os.path.realpath(current_path)
- if current_path in paths.values():
- return False
- configs[name], paths[name] = config, current_path
- return parser.parse_args(config)[0].ignoreconfig
- return False
-
- def get_configs():
- opts, _ = parser.parse_args(configs['command-line'])
- if opts.config_location is not None:
- 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)
- config = _readOptions(location, default=None)
- if config:
- configs['custom'], paths['custom'] = config, location
-
- if opts.ignoreconfig:
- return
- if parser.parse_args(configs['custom'])[0].ignoreconfig:
- return
- if read_options('portable', get_executable_path()):
- return
- opts, _ = parser.parse_args(configs['portable'] + configs['custom'] + configs['command-line'])
- if read_options('home', expand_path(opts.paths.get('home', '')).strip()):
- return
- if read_options('system', '/etc'):
- return
- if read_options('user', None, user=True):
- 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 ('Command-line', 'Custom', 'Portable', 'Home', 'User', 'System'):
- key = label.lower()
- if paths.get(key):
- write_string(f'[debug] {label} config file: {paths[key]}\n')
- if paths.get(key) is not None:
- write_string(f'[debug] {label} config: {_hide_login_info(configs[key])!r}\n')
-
- return parser, opts, args