diff --git a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs index 096c6d9..24dc471 100644 --- a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs @@ -50,7 +50,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand [Option("-d|--dir", CommandOptionType.SingleValue, Description = "指定需要扫描的目录。")] [DirectoryExists] - public string Directory { get; set; } + public string SongsDirectory { get; set; } [Option("-l|--lyric", CommandOptionType.NoValue, Description = "指定程序需要下载歌词文件。")] public bool DownloadLyric { get; set; } @@ -61,6 +61,8 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand [Option("-n|--number", CommandOptionType.SingleValue, Description = "指定下载时候的线程数量。(默认值 2)")] public int ParallelNumber { get; set; } = 2; + [Option] public string ErrorMessage { get; set; } = Path.Combine(Directory.GetCurrentDirectory(), "error.log"); + #endregion protected override async Task OnExecuteAsync(CommandLineApplication app) @@ -83,7 +85,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand private async Task> ScanMusicFilesAsync() { - var files = (await _fileScanner.ScanAsync(Directory, _options.SupportFileExtensions)) + var files = (await _fileScanner.ScanAsync(SongsDirectory, _options.SupportFileExtensions)) .SelectMany(t => t.FilePaths) .ToList(); @@ -180,9 +182,11 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand File.Delete(lyricFilePath); } + info.IsSuccessful = true; + if (lyric.IsPruneMusic) { - info.IsSuccessful = true; + return; } await using var stream = new FileStream(lyricFilePath, FileMode.Create); @@ -205,10 +209,6 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand _logger.LogError($"下载歌词文件时发生错误:{ex.Message},歌曲名: {info.Name},歌手: {info.Artist}。"); info.IsSuccessful = false; } - finally - { - info.IsSuccessful = true; - } } foreach (var downloader in downloaderList) diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/KuGouLyricDownloaderTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/KuGouLyricDownloaderTests.cs index 89b8c87..dd9ddca 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/KuGouLyricDownloaderTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/KuGouLyricDownloaderTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Shouldly; using Xunit; diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/NetEaseLyricDownloaderTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/NetEaseLyricDownloaderTests.cs index 420ac63..92fb102 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/NetEaseLyricDownloaderTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyric/NetEaseLyricDownloaderTests.cs @@ -69,5 +69,13 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyric lyric.ShouldNotBeNull(); } + + [Fact] + public async Task UnknownIssue_Test() + { + var lyric = await _lyricDownloader.DownloadAsync("主題歌Arrietty's Song", "Cécile Corbel"); + + lyric.ShouldNotBeNull(); + } } } \ No newline at end of file