Skip to content

Commit

Permalink
更新API
Browse files Browse the repository at this point in the history
  • Loading branch information
wwh1004 committed Aug 22, 2019
1 parent 44c6150 commit f1d7a59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions NLyric.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.28822.285
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLyric", "NLyric\NLyric.csproj", "{5423689E-6713-4F96-82E3-48B11E2A6412}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeteaseCloudMusicApi", "..\NeteaseCloudMusicApi\NeteaseCloudMusicApi\NeteaseCloudMusicApi.csproj", "{C1E0A5F6-19C4-45DA-9CC0-7966AB01DAF6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{5423689E-6713-4F96-82E3-48B11E2A6412}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5423689E-6713-4F96-82E3-48B11E2A6412}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5423689E-6713-4F96-82E3-48B11E2A6412}.Release|Any CPU.Build.0 = Release|Any CPU
{C1E0A5F6-19C4-45DA-9CC0-7966AB01DAF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1E0A5F6-19C4-45DA-9CC0-7966AB01DAF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1E0A5F6-19C4-45DA-9CC0-7966AB01DAF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1E0A5F6-19C4-45DA-9CC0-7966AB01DAF6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
8 changes: 4 additions & 4 deletions NLyric/Ncm/CloudMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static async Task<NcmTrack[]> SearchTrackAsync(Track track, int limit, bo
json = await NcmApi.SearchAsync(keywords, NcmApi.SearchType.Track, limit);
if ((int)json["songCount"] == 0)
return Array.Empty<NcmTrack>();
return ((JArray)json["songs"]).Select(t => ParseTrack(t, false)).ToArray();
return ((JArray)json["songs"]).Select(ParseTrack).ToArray();
}

public static async Task<NcmAlbum[]> SearchAlbumAsync(Album album, int limit, bool withArtists) {
Expand All @@ -50,7 +50,7 @@ public static async Task<NcmTrack[]> GetTracksAsync(int albumId) {
JToken json;

json = await NcmApi.GetAlbumAsync(albumId);
return ((JArray)json["songs"]).Select(t => ParseTrack(t, true)).ToArray();
return ((JArray)json["album"]["songs"]).Select(ParseTrack).ToArray();
}

public static async Task<NcmLyric> GetLyricAsync(int trackId) {
Expand Down Expand Up @@ -81,11 +81,11 @@ private static NcmAlbum ParseAlbum(JToken json) {
return ncmAlbum;
}

private static NcmTrack ParseTrack(JToken json, bool fromAlbumDetail) {
private static NcmTrack ParseTrack(JToken json) {
Track track;
NcmTrack ncmTrack;

track = new Track((string)json["name"], ParseNames((JArray)json[fromAlbumDetail ? "ar" : "artists"]));
track = new Track((string)json["name"], ParseNames((JArray)json["artists"]));
ncmTrack = new NcmTrack(track, (int)json["id"]);
return ncmTrack;
}
Expand Down
9 changes: 2 additions & 7 deletions NLyric/Ncm/NcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NLyric.Ncm {
/// </summary>
public static class NcmApi {
private const string SEARCH_URL = "http://music.163.com/api/search/pc";
private const string ALBUM_URL = "http://musicapi.leanapp.cn/album";
private const string ALBUM_URL = "http://music.163.com/api/album";
private const string LYRIC_URL = "http://music.163.com/api/song/lyric";

/// <summary>
Expand Down Expand Up @@ -45,13 +45,8 @@ public static async Task<JToken> SearchAsync(IEnumerable<string> keywords, Searc
}

public static async Task<JToken> GetAlbumAsync(int id) {
QueryCollection queries;

queries = new QueryCollection {
{ "id", id.ToString() }
};
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, ALBUM_URL, queries, null)) {
using (HttpResponseMessage response = await client.SendAsync(HttpMethod.Get, ALBUM_URL + "/" + id.ToString())) {
JObject json;

if (!response.IsSuccessStatusCode)
Expand Down

0 comments on commit f1d7a59

Please sign in to comment.