diff --git a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs index 7a62826..017659c 100644 --- a/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs +++ b/src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs @@ -92,11 +92,34 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand throw new ErrorCodeException(ErrorCodes.NoFilesWereScanned); } + files = RemoveExistLyricFiles(files); + _logger.LogInformation($"已经扫描到了 {files.Count} 个音乐文件。"); return files; } + private List RemoveExistLyricFiles(List filePaths) + { + if (!_options.Provider.Lyric.Config.IsSkipExistLyricFiles) + { + return filePaths; + } + + return filePaths + .Where(path => + { + if (!File.Exists(Path.ChangeExtension(path, ".lrc"))) + { + return true; + } + + _logger.LogWarning($"已经存在歌词文件 {path},跳过。"); + return false; + }) + .ToList(); + } + private async Task> LoadMusicInfoAsync(IReadOnlyCollection files) { _logger.LogInformation("开始加载音乐文件的标签信息..."); @@ -125,7 +148,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand return downloader; } - #region > 歌词下载逻辑 < + #region > Lyric download logic < private async ValueTask DownloadLyricFilesAsync(ImmutableList musicInfos) { @@ -150,10 +173,12 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand try { var lyric = await downloader.DownloadAsync(info.Name, info.Artist); - var filePath = Path.Combine(Path.GetDirectoryName(info.FilePath)!, $"{Path.GetFileNameWithoutExtension(info.FilePath)}.lrc"); - if (File.Exists(filePath)) + var lyricFilePath = Path.Combine(Path.GetDirectoryName(info.FilePath)!, + $"{Path.GetFileNameWithoutExtension(info.FilePath)}.lrc"); + + if (File.Exists(lyricFilePath)) { - return true; + File.Delete(lyricFilePath); } if (lyric.IsPruneMusic) @@ -161,7 +186,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand return true; } - await using var stream = new FileStream(filePath, FileMode.Create); + await using var stream = new FileStream(lyricFilePath, FileMode.Create); await using var sw = new StreamWriter(stream); await sw.WriteAsync(lyric.ToString()); await sw.FlushAsync(); @@ -195,7 +220,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand #endregion - #region > 专辑图像下载逻辑 < + #region > Ablum image download logic < private async ValueTask DownloadAlbumAsync(ImmutableList musicInfos) { diff --git a/src/ZonyLrcTools.Cli/Config/LyricOption.cs b/src/ZonyLrcTools.Cli/Config/LyricOption.cs index cab1530..a92ac5f 100644 --- a/src/ZonyLrcTools.Cli/Config/LyricOption.cs +++ b/src/ZonyLrcTools.Cli/Config/LyricOption.cs @@ -25,5 +25,10 @@ public class LyricConfigOption /// /// 是否启用歌词翻译功能。 /// - public bool IsEnableTranslation { get; set; } = false; + public bool IsEnableTranslation { get; set; } = true; + + /// + /// 如果歌词文件已经存在,是否跳过这些文件 + /// + public bool IsSkipExistLyricFiles { get; set; } = false; } \ No newline at end of file diff --git a/src/ZonyLrcTools.Cli/config.yaml b/src/ZonyLrcTools.Cli/config.yaml index 1b9b58c..7a20e0f 100644 --- a/src/ZonyLrcTools.Cli/config.yaml +++ b/src/ZonyLrcTools.Cli/config.yaml @@ -34,7 +34,7 @@ globalOption: # 支持的歌词下载器。 plugin: - name: NetEase # 基于网易云音乐的歌词下载器。 - priority: 1 # 优先级,升序排列。 + priority: 1 # 优先级,升序排列,改为 -1 时禁用。 - name: QQ # 基于 QQ 音乐的歌词下载器。 priority: 2 - name: KuGou # 基于酷狗音乐的歌词下载器。 @@ -43,4 +43,5 @@ globalOption: config: isOneLine: true # 双语歌词是否合并为一行展示。 lineBreak: "\n" # 换行符的类型,记得使用双引号指定。 - isEnableTranslation: true # 是否启用翻译歌词。 \ No newline at end of file + isEnableTranslation: true # 是否启用翻译歌词。 + isSkipExistLyricFiles: false # 如果歌词文件已经存在,是否跳过这些文件。 \ No newline at end of file