mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 12:11:13 +00:00
fix: Fixed the issue where Netease Cloud Music did not throw the correct exception when a song could not be found.
This commit is contained in:
parent
f935f07609
commit
ab5f79bd50
@ -41,7 +41,7 @@ namespace ZonyLrcTools.Common.Album.NetEase
|
||||
true,
|
||||
_defaultOption);
|
||||
|
||||
if (searchResult is not { StatusCode: 200 } || searchResult.Items?.SongCount <= 0)
|
||||
if (searchResult is not { StatusCode: 200 } || searchResult.Items is not { SongCount: > 0 })
|
||||
{
|
||||
throw new ErrorCodeException(ErrorCodes.NoMatchingSong);
|
||||
}
|
||||
|
@ -107,7 +107,6 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
|
||||
{
|
||||
_logger.LogWarningInfo(ex);
|
||||
info.IsSuccessful = false;
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -4,12 +4,17 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
|
||||
{
|
||||
public class SongSearchResponse
|
||||
{
|
||||
[JsonProperty("result")] public InnerListItemModel Items { get; set; }
|
||||
[JsonProperty("result")] public InnerListItemModel? Items { get; set; }
|
||||
|
||||
[JsonProperty("code")] public int StatusCode { get; set; }
|
||||
|
||||
public int GetFirstMatchSongId(string songName, long? duration)
|
||||
{
|
||||
if (Items == null || Items.SongItems == null)
|
||||
{
|
||||
Console.Write("xx");
|
||||
}
|
||||
|
||||
var perfectMatch = Items.SongItems.FirstOrDefault(x => x.Name == songName);
|
||||
if (perfectMatch != null)
|
||||
{
|
||||
@ -27,7 +32,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
|
||||
|
||||
public class InnerListItemModel
|
||||
{
|
||||
[JsonProperty("songs")] public IList<SongModel> SongItems { get; set; }
|
||||
[JsonProperty("songs")] public IList<SongModel>? SongItems { get; set; }
|
||||
|
||||
[JsonProperty("songCount")] public int SongCount { get; set; }
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
|
||||
private const string NetEaseGetLyricUrl = @"https://music.163.com/weapi/song/lyric?csrf_token=";
|
||||
|
||||
private const string NetEaseRequestReferer = @"https://music.163.com";
|
||||
private const string NetEaseRequestContentType = @"application/x-www-form-urlencoded";
|
||||
|
||||
public NetEaseLyricsProvider(IWarpHttpClient warpHttpClient,
|
||||
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
|
||||
@ -49,7 +48,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
|
||||
|
||||
ValidateSongSearchResponse(searchResult, args);
|
||||
|
||||
return await _warpHttpClient.PostAsync(NetEaseGetLyricUrl,
|
||||
return await _warpHttpClient.PostAsync(NetEaseGetLyricUrl,
|
||||
requestOption: request =>
|
||||
{
|
||||
request.Headers.Referrer = new Uri(NetEaseRequestReferer);
|
||||
@ -87,7 +86,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
|
||||
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
|
||||
}
|
||||
|
||||
if (response.Items?.SongCount <= 0)
|
||||
if (response.Items is not { SongCount: > 0 })
|
||||
{
|
||||
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZonyLrcTools.Common.Configuration;
|
||||
using ZonyLrcTools.Common.Infrastructure.Exceptions;
|
||||
using ZonyLrcTools.Common.Lyrics;
|
||||
|
||||
namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
|
||||
@ -105,12 +106,19 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
|
||||
var lyric = await _lyricsProvider.DownloadAsync("橄榄树", "苏曼");
|
||||
lyric.ToString().ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task DownloadAsync_Issue133_Test()
|
||||
{
|
||||
var lyric = await _lyricsProvider.DownloadAsync("Everything", "Yinyues");
|
||||
lyric.ToString().ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DownloadAsync_NullException_Test()
|
||||
{
|
||||
var result = await Should.ThrowAsync<ErrorCodeException>(_lyricsProvider.DownloadAsync("創世記", "りりィ").AsTask);
|
||||
result.ErrorCode.ShouldBe(ErrorCodes.NoMatchingSong);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user