/// <summary> /// 获取音乐列表 /// </summary> /// <param name="SongName">歌曲名</param> /// <returns></returns> public List <clsMusic> GetMusicList(string SongName) { //string url = m_strGetMusicList + SongName; string url = ""; string strJson = ""; bool bolCanDownload; clsMusic msc; List <clsMusic> lmsc = new List <clsMusic>(); JObject jo; int i = 0; string KwCSRF = ""; string strWyyFirst = ""; clsAESEncrypt aes = new clsAESEncrypt(); //----------酷我音乐----------- url = m_strGetKwMusicList1.Replace("<<SongName>>", SongName); strJson = m_htpClient.GetWeb(url); KwCSRF = m_htpClient.GetHeaders("Set-Cookie"); KwCSRF = KwCSRF.Substring(KwCSRF.IndexOf("kw_token=") + 9, KwCSRF.IndexOf(";") - 9); m_htpClient.AddHeaders("csrf", KwCSRF); m_htpClient.AddHeaders("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"); m_htpClient.AddHeaders("Referer", url); url = m_strGetKwMusicList2.Replace("<<SongName>>", SongName); strJson = m_htpClient.GetWeb(url); try { jo = (JObject)JsonConvert.DeserializeObject(strJson); for (i = 0; i < jo["data"]["list"].Count(); i++) { bolCanDownload = true; //重置 //旧接口下载,高品质而且vip可下 //if (jo["data"]["lists"][i]["pay"].ToString() == "16711935") //该字段为16711935,则为收费,不可下载 // bolCanDownload = false; msc = new clsMusic(i, jo["data"]["list"][i]["name"].ToString(), "", jo["data"]["list"][i]["artist"].ToString(), jo["data"]["list"][i]["album"].ToString(), enmMusicSource.Kw, jo["data"]["list"][i]["musicrid"].ToString(), bolCanDownload); lmsc.Add(msc); } } catch { } //----------酷我音乐end------------ //----------网易云音乐--------- strWyyFirst = m_strWyyMusicGetList.Replace("<<SongName>>", SongName); strWyyFirst = aes.AESEncrypt(strWyyFirst, m_strWyyMusicFourth, m_strWyyMusicIV); strWyyFirst = aes.AESEncrypt(strWyyFirst, m_strWyyMusicFourth, m_strWyyMusicIV);//两次AES加密,得到 params 参数 url = m_strGetWyyMusicList; strJson = m_htpClient.PostWeb(url, "params=" + strWyyFirst + "&encSecKey=" + m_strWyyMusicRSA); try { jo = (JObject)JsonConvert.DeserializeObject(strJson); for (i = 0; i < jo["result"]["songs"].Count(); i++) { bolCanDownload = true; //重置 if (jo["result"]["songs"][i]["privilege"]["fl"].ToString() == "0") //该字段为0,则为不可下载(歌名灰色) { bolCanDownload = false; } //副标题 jo["result"]["songs"][i]["alia"].ToString() 多为[],需要清洗,干脆不要了 msc = new clsMusic(i, jo["result"]["songs"][i]["name"].ToString(), "", jo["result"]["songs"][i]["ar"][0]["name"].ToString(), jo["result"]["songs"][i]["al"]["name"].ToString(), enmMusicSource.Wyy, jo["result"]["songs"][i]["id"].ToString(), bolCanDownload); lmsc.Add(msc); } } catch { } //---------网易云音乐end--------- //-----酷狗音乐------------- url = m_strGetKgMusicList.Replace("<<SongName>>", SongName); strJson = m_htpClient.GetWeb(url); try { jo = (JObject)JsonConvert.DeserializeObject(strJson); for (i = 0; i < jo["data"]["lists"].Count(); i++) { bolCanDownload = true; //重置 if (jo["data"]["lists"][i]["trans_param"]["musicpack_advance"].ToString() == "1") //该字段为1,则为收费,不可下载 { bolCanDownload = false; } msc = new clsMusic(i, jo["data"]["lists"][i]["SongName"].ToString(), "", jo["data"]["lists"][i]["SingerName"].ToString(), jo["data"]["lists"][i]["AlbumName"].ToString(), enmMusicSource.Kg, jo["data"]["lists"][i]["FileHash"].ToString(), bolCanDownload); lmsc.Add(msc); } } catch { } //-----酷狗音乐end------------- //------QQ音乐-------- url = m_strGetQQMusicList.Replace("<<SongName>>", SongName); strJson = m_htpClient.GetWeb(url); try { jo = (JObject)JsonConvert.DeserializeObject(strJson); for (i = 0; i < jo["data"]["song"]["list"].Count(); i++) { bolCanDownload = true; //重置 if (jo["data"]["song"]["list"][i]["pay"]["pay_play"].ToString() == "1") //该字段为1,则为收费,不可下载 { bolCanDownload = false; } msc = new clsMusic(i, jo["data"]["song"]["list"][i]["name"].ToString(), jo["data"]["song"]["list"][i]["lyric"].ToString(), jo["data"]["song"]["list"][i]["singer"][0]["name"].ToString(), jo["data"]["song"]["list"][i]["album"]["name"].ToString(), enmMusicSource.QQ, jo["data"]["song"]["list"][i]["mid"].ToString(), bolCanDownload); lmsc.Add(msc); } } catch { } //------QQ音乐End-------- return(lmsc); }
/// <summary> /// 获取音乐下载URL /// </summary> /// <param name="date">必要的数据,如QQ音乐为mid</param> /// <param name="intSource">来源,默认为1-QQ音乐</param> /// <returns></returns> public string GetMusicDownloadURL(string date, enmMusicSource emsSource = enmMusicSource.QQ) { string ResultURL = ""; string url = ""; JObject jo; string strWyyFirst = ""; clsAESEncrypt aes = new clsAESEncrypt(); switch (emsSource) { case enmMusicSource.QQ: url = m_strGetQQMusicVkey.Replace("<<mid>>", date); ResultURL = m_htpClient.GetWeb(url); if (ResultURL.Substring(1, 8) == "\"code\":0") { jo = (JObject)JsonConvert.DeserializeObject(ResultURL); ResultURL = jo["req_0"]["data"]["midurlinfo"][0]["flowurl"].ToString(); ResultURL = m_strGetQQMusicDownloadURL + ResultURL; m_strFileFormat = jo["req_0"]["data"]["midurlinfo"][0]["filename"].ToString(); m_strFileFormat = m_strFileFormat.Substring(m_strFileFormat.IndexOf(".")); } break; case enmMusicSource.Kg: url = m_strGetKgMusicDownloadURL.Replace("<<FileHash>>", date);//.Replace("<<KgMid>>", "c596eb268a2705383a10d0af021664c0");//.Replace("<<KgDFID>>","07u9ob41Vu350chwOw4ejU7b"); ResultURL = m_htpClient.GetWeb(url); if (ResultURL.Substring(1, 10) == "\"status\":1") { jo = (JObject)JsonConvert.DeserializeObject(ResultURL); ResultURL = jo["data"]["play_url"].ToString(); m_strFileFormat = ResultURL.Substring(ResultURL.Length - 4); //可能会出错,如果后缀不是3个字节的话 } break; case enmMusicSource.Kw: ResultURL = m_strGetKwMusicDownloadURL.Replace("<<MUSICID>>", date); m_strFileFormat = ".mp3"; //旧接口目前只想到mp3格式 break; case enmMusicSource.Wyy: strWyyFirst = m_strWyyMusicGetDownloadURL.Replace("<<ID>>", date); strWyyFirst = aes.AESEncrypt(strWyyFirst, m_strWyyMusicFourth, m_strWyyMusicIV); strWyyFirst = aes.AESEncrypt(strWyyFirst, m_strWyyMusicFourth, m_strWyyMusicIV); //两次AES加密,得到 params 参数 url = m_strGetWyyMusicDownloadURL; ResultURL = m_htpClient.PostWeb(url, "params=" + strWyyFirst + "&encSecKey=" + m_strWyyMusicRSA); if (ResultURL.Substring(1, 6) == "\"data\"") { jo = (JObject)JsonConvert.DeserializeObject(ResultURL); ResultURL = jo["data"][0]["url"].ToString(); m_strFileFormat = "." + jo["data"][0]["type"].ToString(); } break; default: break; } return(ResultURL); }