diff --git a/src/ZonyLrcTools.Common/Lyrics/Providers/KuGou/KuGourLyricsProvider.cs b/src/ZonyLrcTools.Common/Lyrics/Providers/KuGou/KuGourLyricsProvider.cs index 38497c5..712ae4e 100644 --- a/src/ZonyLrcTools.Common/Lyrics/Providers/KuGou/KuGourLyricsProvider.cs +++ b/src/ZonyLrcTools.Common/Lyrics/Providers/KuGou/KuGourLyricsProvider.cs @@ -40,6 +40,11 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou var accessKeyResponse = await _warpHttpClient.GetAsync(KuGouGetLyricAccessKeyUrl, new GetLyricAccessKeyRequest(searchResult.Data.List[0].FileHash)); + if (accessKeyResponse.AccessKeyDataObjects.Count == 0) + { + throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args); + } + var accessKeyObject = accessKeyResponse.AccessKeyDataObjects[0]; return await _warpHttpClient.GetAsync(KuGouGetLyricUrl, new GetLyricRequest(accessKeyObject.Id, accessKeyObject.AccessKey)); @@ -60,7 +65,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.KuGou protected virtual void ValidateSongSearchResponse(SongSearchResponse response, LyricsProviderArgs args) { - if (response.ErrorCode != 0 && response.Status != 1 || response.Data.List == null) + if ((response.ErrorCode != 0 && response.Status != 1) || response.Data.List.Count == 0) { throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args); } diff --git a/tests/ZonyLrcTools.Tests/Infrastructure/Lyrics/KuGouLyricProviderTests.cs b/tests/ZonyLrcTools.Tests/Infrastructure/Lyrics/KuGouLyricProviderTests.cs index ea36905..0adf68d 100644 --- a/tests/ZonyLrcTools.Tests/Infrastructure/Lyrics/KuGouLyricProviderTests.cs +++ b/tests/ZonyLrcTools.Tests/Infrastructure/Lyrics/KuGouLyricProviderTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using Shouldly; using Xunit; +using ZonyLrcTools.Common.Infrastructure.Exceptions; using ZonyLrcTools.Common.Lyrics; namespace ZonyLrcTools.Tests.Infrastructure.Lyrics @@ -25,5 +26,18 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics lyric.ShouldNotBeNull(); lyric.IsPruneMusic.ShouldBe(false); } + + [Fact] + public async Task DownloadAsync_Issue133_Test() + { + await Should.ThrowAsync(_lyricsProvider.DownloadAsync("天ノ弱", "漆柚").AsTask); + } + + [Fact] + public async Task DownloadAsync_Index_Exception_Test() + { + var lyric = await _lyricsProvider.DownloadAsync("40'z", "ZOOLY"); + lyric.ToString().ShouldNotBeNullOrEmpty(); + } } } \ No newline at end of file