From cda12e0d3c0a3bb6b03f01aeed0bac352e872eb0 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Thu, 1 Sep 2022 10:31:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96`--save-name`=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E9=9D=9E=E6=B3=95=E5=AD=97=E7=AC=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs | 17 +++++++++++++++-- .../DownloadManager/SimpleDownloadManager.cs | 2 -- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs index 9133edf..7c5cabc 100644 --- a/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs +++ b/src/N_m3u8DL-RE/CommandLine/CommandInvoker.cs @@ -19,7 +19,7 @@ namespace N_m3u8DL_RE.CommandLine private readonly static Argument Input = new(name: "input", description: ResString.cmd_Input); private readonly static Option TmpDir = new(new string[] { "--tmp-dir" }, description: ResString.cmd_tmpDir); private readonly static Option SaveDir = new(new string[] { "--save-dir" }, description: ResString.cmd_saveDir); - private readonly static Option SaveName = new(new string[] { "--save-name" }, description: ResString.cmd_saveName); + private readonly static Option SaveName = new(new string[] { "--save-name" }, description: ResString.cmd_saveName, parseArgument: ParseSaveName); private readonly static Option SavePattern = new(new string[] { "--save-pattern" }, description: ResString.cmd_savePattern, getDefaultValue: () => "____"); private readonly static Option UILanguage = new Option(new string[] { "--ui-language" }, description: ResString.cmd_uiLanguage).FromAmong("en-US", "zh-CN", "zh-TW"); private readonly static Option UrlProcessorArgs = new(new string[] { "--urlprocessor-args" }, description: ResString.cmd_urlProcessorArgs); @@ -54,6 +54,19 @@ namespace N_m3u8DL_RE.CommandLine private readonly static Option AudioFilter = new(new string[] { "-sa", "--select-audio" }, description: ResString.cmd_selectAudio, parseArgument: ParseStreamFilter) { ArgumentHelpName = "OPTIONS" }; private readonly static Option SubtitleFilter = new(new string[] { "-ss", "--select-subtitle" }, description: ResString.cmd_selectSubtitle, parseArgument: ParseStreamFilter) { ArgumentHelpName = "OPTIONS" }; + + private static string? ParseSaveName(ArgumentResult result) + { + var input = result.Tokens.First().Value; + var newName = ConvertUtil.GetValidFileName(input); + if (string.IsNullOrEmpty(newName)) + { + result.ErrorMessage = "Invalid save name!"; + return null; + } + return newName; + } + /// /// 流过滤器 /// @@ -291,7 +304,7 @@ namespace N_m3u8DL_RE.CommandLine public static async Task InvokeArgs(string[] args, Func action) { - var rootCommand = new RootCommand("N_m3u8DL-RE (Beta version) 20220830") + var rootCommand = new RootCommand("N_m3u8DL-RE (Beta version) 20220901") { Input, TmpDir, SaveDir, SaveName, BaseUrl, ThreadCount, DownloadRetryCount, AutoSelect, SkipMerge, SkipDownload, CheckSegmentsCount, BinaryMerge, DelAfterDone, WriteMetaJson, AppendUrlParams, ConcurrentDownload, Headers, /**SavePattern,**/ SubOnly, SubtitleFormat, AutoSubtitleFix, diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index dc92b42..57f7dd7 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -124,8 +124,6 @@ namespace N_m3u8DL_RE.DownloadManager var type = streamSpec.MediaType ?? Common.Enum.MediaType.VIDEO; var dirName = $"{DownloaderConfig.MyOptions.SaveName ?? NowDateTime.ToString("yyyy-MM-dd_HH-mm-ss")}_{task.Id}_{streamSpec.GroupId}_{streamSpec.Codecs}_{streamSpec.Bandwidth}_{streamSpec.Language}"; - //去除非法字符 - dirName = ConvertUtil.GetValidFileName(dirName, filterSlash: true); var tmpDir = Path.Combine(DownloaderConfig.MyOptions.TmpDir ?? Environment.CurrentDirectory, dirName); var saveDir = DownloaderConfig.MyOptions.SaveDir ?? Environment.CurrentDirectory; var saveName = DownloaderConfig.MyOptions.SaveName != null ? $"{DownloaderConfig.MyOptions.SaveName}.{type}.{streamSpec.Language}".TrimEnd('.') : dirName;