fix: 优化网易云歌词匹配机制,增强准确度。

Closes #75
This commit is contained in:
real-zony
2021-06-05 11:52:34 +08:00
parent 2ea5754e3e
commit 5520162a4c
6 changed files with 42 additions and 20 deletions

View File

@@ -51,7 +51,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Album.NetEase
var songDetailJsonStr = await _warpHttpClient.GetAsync(
GetMusicInfoApi,
new GetSongDetailsRequest(searchResult.GetFirstSongId()),
new GetSongDetailsRequest(searchResult.GetFirstMatchSongId(songName)),
_defaultOption);
var url = JObject.Parse(songDetailJsonStr).SelectToken("$.songs[0].album.picUrl")?.Value<string>();

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel
@@ -9,9 +10,10 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase.JsonModel
[JsonProperty("code")] public int StatusCode { get; set; }
public int GetFirstSongId()
public int GetFirstMatchSongId(string songName)
{
return Items.SongItems[0].Id;
var item = Items.SongItems.FirstOrDefault(x => x.Name == songName);
return item?.Id ?? Items.SongItems[0].Id;
}
}

View File

@@ -48,7 +48,7 @@ namespace ZonyLrcTools.Cli.Infrastructure.Lyric.NetEase
var lyricResponse = await _warpHttpClient.GetAsync(
NetEaseGetLyricUrl,
new GetLyricRequest(searchResult.GetFirstSongId()),
new GetLyricRequest(searchResult.GetFirstMatchSongId(args.SongName)),
msg => msg.Headers.Referrer = new Uri(NetEaseRequestReferer));
return Encoding.UTF8.GetBytes(lyricResponse);