mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 20:30:41 +00:00
feat: Support skip exist lyric files.
This commit is contained in:
parent
2044a0b8fa
commit
61ca863770
@ -92,11 +92,34 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
|||||||
throw new ErrorCodeException(ErrorCodes.NoFilesWereScanned);
|
throw new ErrorCodeException(ErrorCodes.NoFilesWereScanned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files = RemoveExistLyricFiles(files);
|
||||||
|
|
||||||
_logger.LogInformation($"已经扫描到了 {files.Count} 个音乐文件。");
|
_logger.LogInformation($"已经扫描到了 {files.Count} 个音乐文件。");
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<string> RemoveExistLyricFiles(List<string> 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<ImmutableList<MusicInfo>> LoadMusicInfoAsync(IReadOnlyCollection<string> files)
|
private async Task<ImmutableList<MusicInfo>> LoadMusicInfoAsync(IReadOnlyCollection<string> files)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("开始加载音乐文件的标签信息...");
|
_logger.LogInformation("开始加载音乐文件的标签信息...");
|
||||||
@ -125,7 +148,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
|||||||
return downloader;
|
return downloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region > 歌词下载逻辑 <
|
#region > Lyric download logic <
|
||||||
|
|
||||||
private async ValueTask DownloadLyricFilesAsync(ImmutableList<MusicInfo> musicInfos)
|
private async ValueTask DownloadLyricFilesAsync(ImmutableList<MusicInfo> musicInfos)
|
||||||
{
|
{
|
||||||
@ -150,10 +173,12 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var lyric = await downloader.DownloadAsync(info.Name, info.Artist);
|
var lyric = await downloader.DownloadAsync(info.Name, info.Artist);
|
||||||
var filePath = Path.Combine(Path.GetDirectoryName(info.FilePath)!, $"{Path.GetFileNameWithoutExtension(info.FilePath)}.lrc");
|
var lyricFilePath = Path.Combine(Path.GetDirectoryName(info.FilePath)!,
|
||||||
if (File.Exists(filePath))
|
$"{Path.GetFileNameWithoutExtension(info.FilePath)}.lrc");
|
||||||
|
|
||||||
|
if (File.Exists(lyricFilePath))
|
||||||
{
|
{
|
||||||
return true;
|
File.Delete(lyricFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lyric.IsPruneMusic)
|
if (lyric.IsPruneMusic)
|
||||||
@ -161,7 +186,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
|||||||
return true;
|
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 using var sw = new StreamWriter(stream);
|
||||||
await sw.WriteAsync(lyric.ToString());
|
await sw.WriteAsync(lyric.ToString());
|
||||||
await sw.FlushAsync();
|
await sw.FlushAsync();
|
||||||
@ -195,7 +220,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region > 专辑图像下载逻辑 <
|
#region > Ablum image download logic <
|
||||||
|
|
||||||
private async ValueTask DownloadAlbumAsync(ImmutableList<MusicInfo> musicInfos)
|
private async ValueTask DownloadAlbumAsync(ImmutableList<MusicInfo> musicInfos)
|
||||||
{
|
{
|
||||||
|
@ -25,5 +25,10 @@ public class LyricConfigOption
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否启用歌词翻译功能。
|
/// 是否启用歌词翻译功能。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsEnableTranslation { get; set; } = false;
|
public bool IsEnableTranslation { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 如果歌词文件已经存在,是否跳过这些文件
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSkipExistLyricFiles { get; set; } = false;
|
||||||
}
|
}
|
@ -34,7 +34,7 @@ globalOption:
|
|||||||
# 支持的歌词下载器。
|
# 支持的歌词下载器。
|
||||||
plugin:
|
plugin:
|
||||||
- name: NetEase # 基于网易云音乐的歌词下载器。
|
- name: NetEase # 基于网易云音乐的歌词下载器。
|
||||||
priority: 1 # 优先级,升序排列。
|
priority: 1 # 优先级,升序排列,改为 -1 时禁用。
|
||||||
- name: QQ # 基于 QQ 音乐的歌词下载器。
|
- name: QQ # 基于 QQ 音乐的歌词下载器。
|
||||||
priority: 2
|
priority: 2
|
||||||
- name: KuGou # 基于酷狗音乐的歌词下载器。
|
- name: KuGou # 基于酷狗音乐的歌词下载器。
|
||||||
@ -43,4 +43,5 @@ globalOption:
|
|||||||
config:
|
config:
|
||||||
isOneLine: true # 双语歌词是否合并为一行展示。
|
isOneLine: true # 双语歌词是否合并为一行展示。
|
||||||
lineBreak: "\n" # 换行符的类型,记得使用双引号指定。
|
lineBreak: "\n" # 换行符的类型,记得使用双引号指定。
|
||||||
isEnableTranslation: true # 是否启用翻译歌词。
|
isEnableTranslation: true # 是否启用翻译歌词。
|
||||||
|
isSkipExistLyricFiles: false # 如果歌词文件已经存在,是否跳过这些文件。
|
Loading…
x
Reference in New Issue
Block a user