Skip to content

Commit

Permalink
fix: Fixed multi-downloader not working problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
real-zony committed Apr 25, 2022
1 parent 61ca863 commit 0f84621
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 13 additions & 10 deletions src/ZonyLrcTools.Cli/Commands/SubCommand/DownloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,8 @@ private async ValueTask DownloadLyricFilesAsync(ImmutableList<MusicInfo> musicIn

private async Task DownloadLyricTaskLogicAsync(IEnumerable<ILyricDownloader> downloaderList, MusicInfo info)
{
async Task<bool> InternalDownloadLogicAsync(ILyricDownloader downloader)
async Task InternalDownloadLogicAsync(ILyricDownloader downloader)
{
_logger.LogMusicInfoWithInformation(info);

try
{
var lyric = await downloader.DownloadAsync(info.Name, info.Artist);
Expand All @@ -183,7 +181,7 @@ async Task<bool> InternalDownloadLogicAsync(ILyricDownloader downloader)

if (lyric.IsPruneMusic)
{
return true;
info.IsSuccessful = true;
}

await using var stream = new FileStream(lyricFilePath, FileMode.Create);
Expand All @@ -195,7 +193,7 @@ async Task<bool> InternalDownloadLogicAsync(ILyricDownloader downloader)
{
if (ex.ErrorCode == ErrorCodes.NoMatchingSong)
{
return false;
info.IsSuccessful = false;
}

_logger.LogWarningInfo(ex);
Expand All @@ -205,15 +203,20 @@ async Task<bool> InternalDownloadLogicAsync(ILyricDownloader downloader)
_logger.LogError($"下载歌词文件时发生错误:{ex.Message},歌曲名: {info.Name},歌手: {info.Artist}");
info.IsSuccessful = false;
}

return true;
finally
{
info.IsSuccessful = true;
}
}

foreach (var downloader in downloaderList)
{
if (await InternalDownloadLogicAsync(downloader))
await InternalDownloadLogicAsync(downloader);

if (info.IsSuccessful)
{
break;
_logger.LogSuccessful(info);
return;
}
}
}
Expand All @@ -238,7 +241,7 @@ private async ValueTask DownloadAlbumAsync(ImmutableList<MusicInfo> musicInfos)

private async Task DownloadAlbumTaskLogicAsync(IAlbumDownloader downloader, MusicInfo info)
{
_logger.LogMusicInfoWithInformation(info);
_logger.LogSuccessful(info);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public static void LogWarningInfo(this ILogger logger, ErrorCodeException except
}

/// <summary>
/// 使用 <see cref="LogLevel.Information"/> 级别打印歌曲信息
/// 使用 <see cref="LogLevel.Information"/> 级别打印歌曲下载成功信息
/// </summary>
/// <param name="logger">日志记录器的实例。</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}, 下载成功.");
}
}
}

0 comments on commit 0f84621

Please sign in to comment.