优化复杂命令行默认值解析

This commit is contained in:
nilaoda 2022-08-26 23:50:19 +08:00
parent 2310d0472a
commit 8ac945fe29
1 changed files with 9 additions and 5 deletions

View File

@ -72,8 +72,8 @@ namespace N_m3u8DL_RE.CommandLine
foreach (var item in result.Tokens) foreach (var item in result.Tokens)
{ {
var p = new ComplexParamParser(item.Value); var p = new ComplexParamParser(item.Value);
var path = p.GetValue("path"); var path = p.GetValue("path") ?? item.Value; //若未获取到直接整个字符串作为path
var lang = p.GetValue("lang") ?? "und"; var lang = p.GetValue("lang");
var name = p.GetValue("name"); var name = p.GetValue("name");
if (string.IsNullOrEmpty(path) || !File.Exists(path)) if (string.IsNullOrEmpty(path) || !File.Exists(path))
{ {
@ -99,9 +99,10 @@ namespace N_m3u8DL_RE.CommandLine
/// <returns></returns> /// <returns></returns>
private static MuxOptions? ParseMuxAfterDone(ArgumentResult result) private static MuxOptions? ParseMuxAfterDone(ArgumentResult result)
{ {
var p = new ComplexParamParser(result.Tokens.First().Value); var v = result.Tokens.First().Value;
var p = new ComplexParamParser(v);
//混流格式 //混流格式
var format = p.GetValue("format"); var format = p.GetValue("format") ?? v; //若未获取到直接整个字符串作为format解析
if (format != "mp4" && format != "mkv") if (format != "mp4" && format != "mkv")
{ {
result.ErrorMessage = $"format={format} not valid"; result.ErrorMessage = $"format={format} not valid";
@ -150,7 +151,6 @@ namespace N_m3u8DL_RE.CommandLine
var option = new MyOption var option = new MyOption
{ {
Input = bindingContext.ParseResult.GetValueForArgument(Input), Input = bindingContext.ParseResult.GetValueForArgument(Input),
Headers = bindingContext.ParseResult.GetValueForOption(Headers)!,
LogLevel = bindingContext.ParseResult.GetValueForOption(LogLevel), LogLevel = bindingContext.ParseResult.GetValueForOption(LogLevel),
AutoSelect = bindingContext.ParseResult.GetValueForOption(AutoSelect), AutoSelect = bindingContext.ParseResult.GetValueForOption(AutoSelect),
SkipMerge = bindingContext.ParseResult.GetValueForOption(SkipMerge), SkipMerge = bindingContext.ParseResult.GetValueForOption(SkipMerge),
@ -182,6 +182,10 @@ namespace N_m3u8DL_RE.CommandLine
ConcurrentDownload = bindingContext.ParseResult.GetValueForOption(ConcurrentDownload), ConcurrentDownload = bindingContext.ParseResult.GetValueForOption(ConcurrentDownload),
}; };
var parsedHeaders = bindingContext.ParseResult.GetValueForOption(Headers);
if (parsedHeaders != null)
option.Headers = parsedHeaders;
//以用户选择语言为准优先 //以用户选择语言为准优先
if (option.UILanguage != null) if (option.UILanguage != null)