mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-02 05:10:42 +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,
|
true,
|
||||||
_defaultOption);
|
_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);
|
throw new ErrorCodeException(ErrorCodes.NoMatchingSong);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ public class LyricsDownloader : ILyricsDownloader, ISingletonDependency
|
|||||||
{
|
{
|
||||||
_logger.LogWarningInfo(ex);
|
_logger.LogWarningInfo(ex);
|
||||||
info.IsSuccessful = false;
|
info.IsSuccessful = false;
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -4,12 +4,17 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
|
|||||||
{
|
{
|
||||||
public class SongSearchResponse
|
public class SongSearchResponse
|
||||||
{
|
{
|
||||||
[JsonProperty("result")] public InnerListItemModel Items { get; set; }
|
[JsonProperty("result")] public InnerListItemModel? Items { get; set; }
|
||||||
|
|
||||||
[JsonProperty("code")] public int StatusCode { get; set; }
|
[JsonProperty("code")] public int StatusCode { get; set; }
|
||||||
|
|
||||||
public int GetFirstMatchSongId(string songName, long? duration)
|
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);
|
var perfectMatch = Items.SongItems.FirstOrDefault(x => x.Name == songName);
|
||||||
if (perfectMatch != null)
|
if (perfectMatch != null)
|
||||||
{
|
{
|
||||||
@ -27,7 +32,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase.JsonModel
|
|||||||
|
|
||||||
public class InnerListItemModel
|
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; }
|
[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 NetEaseGetLyricUrl = @"https://music.163.com/weapi/song/lyric?csrf_token=";
|
||||||
|
|
||||||
private const string NetEaseRequestReferer = @"https://music.163.com";
|
private const string NetEaseRequestReferer = @"https://music.163.com";
|
||||||
private const string NetEaseRequestContentType = @"application/x-www-form-urlencoded";
|
|
||||||
|
|
||||||
public NetEaseLyricsProvider(IWarpHttpClient warpHttpClient,
|
public NetEaseLyricsProvider(IWarpHttpClient warpHttpClient,
|
||||||
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
|
ILyricsItemCollectionFactory lyricsItemCollectionFactory,
|
||||||
@ -87,7 +86,7 @@ namespace ZonyLrcTools.Common.Lyrics.Providers.NetEase
|
|||||||
throw new ErrorCodeException(ErrorCodes.TheReturnValueIsIllegal, attachObj: args);
|
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);
|
throw new ErrorCodeException(ErrorCodes.NoMatchingSong, attachObj: args);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using Microsoft.Extensions.Options;
|
|||||||
using Shouldly;
|
using Shouldly;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using ZonyLrcTools.Common.Configuration;
|
using ZonyLrcTools.Common.Configuration;
|
||||||
|
using ZonyLrcTools.Common.Infrastructure.Exceptions;
|
||||||
using ZonyLrcTools.Common.Lyrics;
|
using ZonyLrcTools.Common.Lyrics;
|
||||||
|
|
||||||
namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
|
namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
|
||||||
@ -112,5 +113,12 @@ namespace ZonyLrcTools.Tests.Infrastructure.Lyrics
|
|||||||
var lyric = await _lyricsProvider.DownloadAsync("Everything", "Yinyues");
|
var lyric = await _lyricsProvider.DownloadAsync("Everything", "Yinyues");
|
||||||
lyric.ToString().ShouldNotBeNullOrEmpty();
|
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