feat: Added KuWo(酷我) Music lyrics source (incomplete).

This commit is contained in:
real-zony
2022-10-26 17:05:44 +08:00
parent 6b72f919b8
commit b7b1f36bf5
15 changed files with 219 additions and 13 deletions

View File

@@ -0,0 +1,13 @@
using Newtonsoft.Json;
namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class GetLyricsRequest
{
[JsonProperty("musicId")] public long MusicId { get; }
public GetLyricsRequest(long musicId)
{
MusicId = musicId;
}
}

View File

@@ -0,0 +1,21 @@
using Newtonsoft.Json;
namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class GetLyricsResponse
{
[JsonProperty("status")] public int Status { get; set; }
[JsonProperty("lrclist")] public ICollection<GetLyricsItem> Lyrics { get; set; }
[JsonProperty("msg")] public string? ErrorMessage { get; set; }
[JsonProperty("msgs")] public string? ErrorMessage2 { get; set; }
}
public class GetLyricsItem
{
[JsonProperty("lineLyric")] public string Text { get; set; }
[JsonProperty("time")] public string Position { get; set; }
}

View File

@@ -0,0 +1,19 @@
using Newtonsoft.Json;
namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class SongSearchRequest
{
[JsonProperty("key")] public string Keyword { get; set; }
[JsonProperty("pn")] public int PageNumber { get; }
[JsonProperty("rn")] public int PageSize { get; }
public SongSearchRequest(string name, string artist, int pageNumber = 1, int pageSize = 20)
{
Keyword = $"{name} {artist}";
PageNumber = pageNumber;
PageSize = pageSize;
}
}

View File

@@ -0,0 +1,46 @@
using Newtonsoft.Json;
namespace ZonyLrcTools.Common.Lyrics.Providers.KuWo.JsonModel;
public class SongSearchResponse
{
[JsonProperty("code")] public int Code { get; set; }
[JsonProperty("data")] public SongSearchResponseInnerData InnerData { get; set; }
[JsonProperty("msg")] public string? ErrorMessage { get; set; }
public long GetMatchedMusicId(string musicName, string artistName, long? duration)
{
var prefectMatch = InnerData.SongItems.FirstOrDefault(x => x.Name == musicName && x.Artist == artistName);
if (prefectMatch != null)
{
return prefectMatch.MusicId;
}
if (duration is null or 0)
{
return InnerData.SongItems.First().MusicId;
}
return InnerData.SongItems.OrderBy(t => Math.Abs(t.Duration - duration.Value)).First().MusicId;
}
}
public class SongSearchResponseInnerData
{
[JsonProperty("total")] public string Total { get; set; }
[JsonProperty("list")] public ICollection<SongSearchResponseDetail> SongItems { get; set; }
}
public class SongSearchResponseDetail
{
[JsonProperty("artist")] public string? Artist { get; set; }
[JsonProperty("name")] public string? Name { get; set; }
[JsonProperty("rid")] public long MusicId { get; set; }
[JsonProperty("duration")] public long Duration { get; set; }
}