1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

Improve custom config support (closes #10648)

This commit is contained in:
Sergey M․ 2016-12-31 23:41:37 +07:00
parent e66dca5e4a
commit b6ee45e9fa
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
2 changed files with 21 additions and 22 deletions

View File

@ -405,8 +405,7 @@ def parse_retries(retries):
'postprocessor_args': postprocessor_args, 'postprocessor_args': postprocessor_args,
'cn_verification_proxy': opts.cn_verification_proxy, 'cn_verification_proxy': opts.cn_verification_proxy,
'geo_verification_proxy': opts.geo_verification_proxy, 'geo_verification_proxy': opts.geo_verification_proxy,
'configfile': opts.configfile, 'config_location': opts.config_location,
} }
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:

View File

@ -179,9 +179,9 @@ def _scrub_eq(o):
'Do not read the user configuration in ~/.config/youtube-dl/config ' 'Do not read the user configuration in ~/.config/youtube-dl/config '
'(%APPDATA%/youtube-dl/config.txt on Windows)') '(%APPDATA%/youtube-dl/config.txt on Windows)')
general.add_option( general.add_option(
'--config-file', '--config-location',
dest='configfile', metavar='FILE', dest='config_location', metavar='PATH',
help='File to read configuration from.') help='Location of the configuration file; either the path to the config or its containing directory.')
general.add_option( general.add_option(
'--flat-playlist', '--flat-playlist',
action='store_const', dest='extract_flat', const='in_playlist', action='store_const', dest='extract_flat', const='in_playlist',
@ -851,30 +851,30 @@ def compat_conf(conf):
command_line_conf = compat_conf(sys.argv[1:]) command_line_conf = compat_conf(sys.argv[1:])
opts, args = parser.parse_args(command_line_conf) opts, args = parser.parse_args(command_line_conf)
if '--ignore-config' in command_line_conf: system_conf = user_conf = custom_conf = []
system_conf = []
user_conf = []
elif '--config-file' in command_line_conf:
if not os.path.isfile(opts.configfile):
parser.error('Config file {0} not found.'.format(opts.configfile))
else:
user_conf = _readOptions(opts.configfile)
system_conf = []
if '--config-location' in command_line_conf:
location = compat_expanduser(opts.config_location)
if os.path.isdir(location):
location = os.path.join(location, 'youtube-dl.conf')
if not os.path.exists(location):
parser.error('config-location %s does not exist.' % location)
custom_conf = _readOptions(location)
elif '--ignore-config' in command_line_conf:
pass
else: else:
system_conf = _readOptions('/etc/youtube-dl.conf') system_conf = _readOptions('/etc/youtube-dl.conf')
if '--ignore-config' in system_conf: if '--ignore-config' not in system_conf:
user_conf = []
else:
user_conf = _readUserConf() user_conf = _readUserConf()
argv = system_conf + user_conf + command_line_conf argv = system_conf + user_conf + command_line_conf
opts, args = parser.parse_args(argv) opts, args = parser.parse_args(argv)
if opts.verbose: if opts.verbose:
write_string('[debug] System config: ' + repr(_hide_login_info(system_conf)) + '\n') for conf_label, conf in (
write_string('[debug] User config: ' + repr(_hide_login_info(user_conf)) + '\n') ('System config', system_conf),
write_string('[debug] Command-line args: ' + repr(_hide_login_info(command_line_conf)) + '\n') ('User config', user_conf),
('Custom config', custom_conf),
('Command-line args', command_line_conf)):
write_string('[debug] %s: %s\n' % (conf_label, repr(_hide_login_info(conf))))
return parser, opts, args return parser, opts, args