fix: Fixed multi-downloader not working problem.

This commit is contained in:
real-zony 2022-04-25 12:16:00 +08:00
parent 61ca863770
commit 0f84621919
2 changed files with 16 additions and 13 deletions

View File

@ -166,10 +166,8 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
private async Task DownloadLyricTaskLogicAsync(IEnumerable<ILyricDownloader> downloaderList, MusicInfo info) private async Task DownloadLyricTaskLogicAsync(IEnumerable<ILyricDownloader> downloaderList, MusicInfo info)
{ {
async Task<bool> InternalDownloadLogicAsync(ILyricDownloader downloader) async Task InternalDownloadLogicAsync(ILyricDownloader downloader)
{ {
_logger.LogMusicInfoWithInformation(info);
try try
{ {
var lyric = await downloader.DownloadAsync(info.Name, info.Artist); var lyric = await downloader.DownloadAsync(info.Name, info.Artist);
@ -183,7 +181,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
if (lyric.IsPruneMusic) if (lyric.IsPruneMusic)
{ {
return true; info.IsSuccessful = true;
} }
await using var stream = new FileStream(lyricFilePath, FileMode.Create); await using var stream = new FileStream(lyricFilePath, FileMode.Create);
@ -195,7 +193,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
{ {
if (ex.ErrorCode == ErrorCodes.NoMatchingSong) if (ex.ErrorCode == ErrorCodes.NoMatchingSong)
{ {
return false; info.IsSuccessful = false;
} }
_logger.LogWarningInfo(ex); _logger.LogWarningInfo(ex);
@ -205,15 +203,20 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
_logger.LogError($"下载歌词文件时发生错误:{ex.Message},歌曲名: {info.Name},歌手: {info.Artist}。"); _logger.LogError($"下载歌词文件时发生错误:{ex.Message},歌曲名: {info.Name},歌手: {info.Artist}。");
info.IsSuccessful = false; info.IsSuccessful = false;
} }
finally
return true; {
info.IsSuccessful = true;
}
} }
foreach (var downloader in downloaderList) foreach (var downloader in downloaderList)
{ {
if (await InternalDownloadLogicAsync(downloader)) await InternalDownloadLogicAsync(downloader);
if (info.IsSuccessful)
{ {
break; _logger.LogSuccessful(info);
return;
} }
} }
} }
@ -238,7 +241,7 @@ namespace ZonyLrcTools.Cli.Commands.SubCommand
private async Task DownloadAlbumTaskLogicAsync(IAlbumDownloader downloader, MusicInfo info) private async Task DownloadAlbumTaskLogicAsync(IAlbumDownloader downloader, MusicInfo info)
{ {
_logger.LogMusicInfoWithInformation(info); _logger.LogSuccessful(info);
try try
{ {

View File

@ -41,13 +41,13 @@ namespace ZonyLrcTools.Cli.Infrastructure.Extensions
} }
/// <summary> /// <summary>
/// 使用 <see cref="LogLevel.Information"/> 级别打印歌曲信息。 /// 使用 <see cref="LogLevel.Information"/> 级别打印歌曲下载成功信息。
/// </summary> /// </summary>
/// <param name="logger">日志记录器的实例。</param> /// <param name="logger">日志记录器的实例。</param>
/// <param name="musicInfo">需要打印的歌曲信息。</param> /// <param name="musicInfo">需要打印的歌曲信息。</param>
public static void LogMusicInfoWithInformation(this ILogger logger, MusicInfo musicInfo) public static void LogSuccessful(this ILogger logger, MusicInfo musicInfo)
{ {
logger.LogInformation($"歌曲名: {musicInfo.Name}, 艺术家: {musicInfo.Artist}, 歌曲路径: {musicInfo.FilePath}"); logger.LogInformation($"歌曲名: {musicInfo.Name}, 艺术家: {musicInfo.Artist}, 下载成功.");
} }
} }
} }