/// <summary> /// 搜索音乐 /// </summary> /// <param name="keyWord">关键词</param> /// <returns></returns> public static List <Dictionary <string, string> > SearchMusic(string keyWord) { JObject jsonResult = NeteaseCloudAPI.Search(keyWord); List <Dictionary <string, string> > result = new List <Dictionary <string, string> >(); foreach (JObject song in jsonResult["result"]["songs"]) { Dictionary <string, string> tempSong = new Dictionary <string, string> { ["name"] = song["name"].ToString(), ["id"] = song["id"].ToString(), ["artist"] = song["artists"].ToList()[0]["name"].ToString() }; result.Add(tempSong); } return(result); }
/// <summary> /// 根据ID下载歌词 /// </summary> /// <param name="id"></param> /// <returns></returns> public static string DownloadLyricByID(string id, bool isMergeTranslation = true) { string lyric = null; JObject lyricJson = NeteaseCloudAPI.Lyric(id); try { lyric = lyricJson["lrc"]["lyric"].ToString(); string tlyric = lyricJson["tlyric"]["lyric"].ToString(); if (tlyric != "" && isMergeTranslation) { lyric = string.Join("\n", MergeTranslation(lyric, tlyric)); } string p = @"(\[\d*:\d*.)(\d{2})\d\]"; lyric = Regex.Replace(lyric, p, @"$1$2]"); } catch (System.NullReferenceException) { } return(lyric == null ? "[00:00.00]轻音乐,请欣赏" : lyric); }