public static Song[] GetSongListSong(string id) { string postJson = JsonMapper.ToJson(new GetModules.SinglePostModule { id = id }); var response = GetTools.PostApi("/v1/GetAlbumsData", postJson); if (response.IsSuccessful) { GetModules.SongListGetModule jsonData = JsonMapper.ToObject <GetModules.SongListGetModule>(response.Content); if (jsonData.Success) { for (int i = 0; i != jsonData.Data.Data.Length; i++) { string[] assestUri = JointAssetsUrl.GetAssestUri(jsonData.Data.Data[i].CDN, GetTools.CDNList, jsonData.Data.Data[i].CoverImg, jsonData.Data.Data[i].Music, jsonData.Data.Data[i].Lyric); jsonData.Data.Data[i].assestLink = new Song.AssestLink { CoverImg = assestUri[0], Music = assestUri[1], Lyric = assestUri[2] }; } Log.WriteLine("获取歌单 " + id + " 成功", Level.Info); return(jsonData.Data.Data); } else { Log.WriteLine("请求失败:\r\n" + response.Content, Level.Error); throw new Exception(jsonData.Msg.ToString()); } } else { throw new Exception(response.StatusCode.ToString()); } }
/// <summary> /// 获取热门歌曲 /// </summary> /// <param name="PageIndex"></param> /// <param name="PageRows"></param> /// <returns></returns> public static Song[] GetHotMusic(int PageIndex, int PageRows) { string postJson = JsonMapper.ToJson(new GetModules.ListPostModule { pageIndex = PageIndex, pageRows = PageRows }); var response = GetTools.PostApi("/v1/GetHotMusicList", postJson); if (response.IsSuccessful) { GetModules.MusicListGetModule jsonData = JsonMapper.ToObject <GetModules.MusicListGetModule>(response.Content); if (jsonData.Success) { Song[] songs = jsonData.Data; for (int i = 0; i != songs.Length; i++) { string[] assestUri = JointAssetsUrl.GetAssestUri(songs[i].CDN, GetTools.CDNList, songs[i].CoverImg, songs[i].Music, songs[i].Lyric); songs[i].assestLink = new AssestLink { CoverImg = assestUri[0], Music = assestUri[1], Lyric = assestUri[2] }; } return(songs); } else { Log.WriteLine("请求失败:\r\n" + response.Content, Level.Error); throw new Exception(jsonData.Msg.ToString()); } } else { throw new Exception("错误代码:" + response.StatusCode.ToString()); } }
/// <summary> /// 获取 / 搜索歌曲 /// </summary> /// <param name="SearchCondition">搜索依据</param> /// <param name="keyword">搜索关键词</param> /// <param name="PageIndex">页码</param> /// <param name="PageRows">一页输出数量</param> /// <returns></returns> public static Song[] GetMusicList(string SearchCondition, string keyword, int PageIndex, int PageRows, string sortField, string sortType) { string postJson = JsonMapper.ToJson(new GetModules.ListPostModule { search = new GetModules.Search { condition = SearchCondition, keyword = keyword }, pageIndex = PageIndex, pageRows = PageRows, sortField = sortField, sortType = sortType }); var response = GetTools.PostApi("/v1/GetMusicList", postJson); if (response.IsSuccessful) { GetModules.MusicListGetModule jsonData = JsonMapper.ToObject <GetModules.MusicListGetModule>(response.Content); if (jsonData.Success) { for (int i = 0; i != jsonData.Data.Length; i++) { string[] assestUri = JointAssetsUrl.GetAssestUri(jsonData.Data[i].CDN, GetTools.CDNList, jsonData.Data[i].CoverImg, jsonData.Data[i].Music, jsonData.Data[i].Lyric); jsonData.Data[i].assestLink = new AssestLink { CoverImg = assestUri[0], Music = assestUri[1], Lyric = assestUri[2] }; } return(jsonData.Data); } else { Log.WriteLine("请求失败:\r\n" + response.Content, Level.Error); throw new Exception(jsonData.Msg.ToString()); } } else { throw new Exception(response.StatusCode.ToString()); } }
/// <summary> /// 获取多个歌曲对象 /// </summary> /// <param name="SongId">歌曲 Id</param> public static Song GetSongObjects(string[] SongId) { string postJson = JsonMapper.ToJson(new GetModules.ArrayPostModule { ids = SongId }); var response = GetTools.PostApi("/v1/GetMusicData", postJson); // 请求 Api if (response.IsSuccessful) { GetModules.MusicListGetModule jsonData = JsonMapper.ToObject <GetModules.MusicListGetModule>(response.Content); // 转 Json 为对象 if (jsonData.Success) { string[] assestUri = JointAssetsUrl.GetAssestUri(jsonData.Data[0].CDN, GetTools.CDNList, jsonData.Data[0].CoverImg, jsonData.Data[0].Music, jsonData.Data[0].Lyric); jsonData.Data[0].assestLink = new AssestLink { CoverImg = assestUri[0], Music = assestUri[1], Lyric = assestUri[2] }; return(jsonData.Data[0]); } else { Log.WriteLine("请求失败:\r\n" + response.Content, Level.Error); throw new Exception(jsonData.Msg.ToString()); } } else { throw new Exception(response.StatusCode.ToString()); } }