Simple test and analysis of using C # to call Netease Cloud Music API
![Simple test and analysis of using C # to call Netease Cloud Music API Simple test and analysis of using C # to call Netease Cloud Music API](http://up-free-imgs.azimiao.com/wp-content/uploads/2016/10/april0000.jpg)
Some of the materials referenced in this article are listed at the end. As of August 3, 2017, most interfaces had failed and the new version of interfaces had been encrypted. For the new version, please refer to: Netease Cloud Music New WebAPI Analysis
catalog:
-
Netease Cloud Music API -
Call with c # -
Simple test finished product
API related to Netease Cloud Music
1. Song information:
{"songs":[{ "starred":false, "popularity":5.0, "starredNum":0, "playedNum":0, "dayPlays":0, "hearTime":0, "mp3Url":" http://m2.music.126.net/oJe-1zZhVL4PcElir7W96A==/5649290743614436.mp3 ", "rtUrls":[], "artists":[{"img1v1Id":18686200114669622,"topicPerson":0,"picUrl":" http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg ","picId":0,"albumSize":0,"img1v1Url":" http://p4.music.126.net/VnZiScyynLG7atLIZ2YPkw==/18686200114669622.jpg "," briefDesc ":" "," trans ":" "," alias ": []," musicSize ": 0," name ":" Shigero Sakamoto "," id ": 14593," img1v1Id_str ":" 18686200114669622 "}], "hMusic":{"bitrate":192000,"playTime":178938,"dfsId":5649290743614437,"volumeDelta":0.289741,"sr":44100,"name":"Black One","id":35417247,"size":3825822,"extension":"mp3"},"mMusic":{"bitrate":160000,"playTime":178938,"dfsId":5649290743614435,"volumeDelta":0.688485,"sr":44100,"name":"Black One","id":35417245,"size":3627638,"extension":"mp3"},"lMusic" :{"bitrate":96000,"playTime":178938,"dfsId":5649290743614436,"volumeDelta":0.864432,"sr":44100,"name":"Black One","id":35417246,"size":2195710,"extension":"mp3"},"album":{"songs":[],"paid":false,"onSale":false,"picUrl":" http://p3.music.126.net/GmgDv08JNU1gn9wVUBzIVw==/931286348726508.jpg ","artists":[{"img1v1Id":18686200114669622,"topicPerson":0,"picUrl":" http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg ","picId":0,"albumSize":0,"img1v1Url":" http://p3.music.126.net/VnZiScyynLG7atLIZ2YPkw==/18686200114669622.jpg "," briefDesc ":" "," trans ":" "," alias ": []," musicSize ": 0," name ":" Shigero Sakamoto "," id ": 14593," img1v1Id_str ":" 18686200114669622 "}]," picId ": 931286348726508," artist ": {" img1v1Id ": 18686200114669622," topicPerson ": 0," picUrl ":" http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg ","picId":0,"albumSize":0,"img1v1Url":" http://p4.music.126.net/VnZiScyynLG7atLIZ2YPkw==/18686200114669622.jpg ","briefDesc":"","trans":"","alias":[],"musicSize":0,"name":"","id":0,"img1v1Id_str":"18686200114669622"},"publishTime":1261670400000,"commentThreadId":"R_AL_3_44451","briefDesc":"","copyrightId":0,"company":"5pb. Records "," status ": 1," tags ":" "," description ":" "," subType ": null," alias ": [" The original soundtrack of the girl's TV animation of crime and punishment and redemption "]," blurPicUrl ":" http://p3.music.126.net/GmgDv08JNU1gn9wVUBzIVw==/931286348726508.jpg "," companyId ": 0," pic ": 931286348726508," name ":" TV Animation 11eyes (O.S. T) "," id ": 44451," type ":" album "," size ": 55}," mvid ": 0," fee ": 0," ftype ": 0," rtype ": 0," rurl ": null," commentThreadId ":" R_SO_4_458964 "," copyrightId ": 0," score ": 5," copy "pyFrom": "", "status": 0, "disc": "", "no": 45, "audit": null, "ringtone": "", "position": 45, "duration": 178938, "alias": [], " crbt":null,"bMusic":{"bitrate":96000,"playTime":178938,"dfsId":5649290743614436,"volumeDelta":0.864432,"sr":44100,"name":"Black One","id":35417246,"size":2195710,"extension":"mp3"},"rtUrl":null,"name":"Black One","id":458964 }], "equalizers":{}, "code":200 }
Song search (requires specific header information):
-
s: Content searched -
Offset: offset (for paging) -
Limit: the quantity obtained -
Type: Type of search -
Song 1 -
Album 10 -
Singer 100 -
Singing list 1000 -
User 1002 -
mv 1004 -
Lyrics 1006 -
Anchor station 1009
-
Song download:
{"data":{ "id":28445467, "url":" http://m10.music.126.net/20161019192149/64bd58d3071e829f606afee85e63d501/ymusic/fe64/c17f/54cc/64c15c1430e55bf2c8093f0b47dc39f4.mp3 ", "br":320000, "size":6732382, "md5":"64c15c1430e55bf2c8093f0b47dc39f4", "code":200, "expi":1200, "type":"mp3", "gain":-1.34, "fee":0, "uf":null, "payed":0, "flag":0, "canExtend":false}, "code":200}
Header information
Album, song list, etc
Call with c #
Get song information
public static string getMusic(string id) { string url = " http://music.163.com/api/song/detail/?id= "+id+"&ids=["+id+"]&csrf_token="; HttpWebRequest req = (HttpWebRequest)HttpWebRequest. Create(url); req.Method = "get"; HttpWebResponse response = (HttpWebResponse)req. GetResponse(); Stream res = response.GetResponseStream(); StreamReader reader1 = new StreamReader(res); string a1 = reader1.ReadToEnd(); return a1; //string[] a2 = a1.Split(new string[]{"\"mp3Url\":\"","\",\"rtUrls"}, StringSplitOptions.RemoveEmptyEntries); //this.mp3url = a2[1]; }
Get download address
public static string getApiUrl(int kbps, string id) { return " http://music.163.com/api/song/enhance/download/url?br= " + kbps + "&id=" + id; } public static string getDownUrl(int kbps,string id) { if (id != "") { string apiurl = getApiUrl(kbps, id); HttpWebRequest req = (HttpWebRequest)HttpWebRequest. Create(apiurl); req.Method = "get"; HttpWebResponse response = (HttpWebResponse)req. GetResponse(); Stream res = response.GetResponseStream(); StreamReader reader1 = new StreamReader(res); string a1 = reader1.ReadToEnd(); return a1; } else { return("null"); } }
search
public string Param(string sname) { string postls; string ss = HttpUtility.UrlEncode(sname,Encoding.GetEncoding("utf-8")); StringBuilder bulider = new StringBuilder(); bulider.AppendFormat("s={0}&offset={1}&limit={2}&type={3}", ss, 0, 20, 1); postls = bulider.ToString(); return postls; } public static string searchMusic(string sname) { HttpWebRequest request = (HttpWebRequest)WebRequest. Create(searchurl); request.Method = "POST"; request.Referer = " http://music.163.com/search/ "; request.ContentType = "application/x-www-form-urlencoded"; string postinfo = Param(sname); request.ContentLength = Encoding.UTF8.GetByteCount(postinfo); CookieContainer cookies = new CookieContainer(); Cookie cook = new Cookie(); Cookie cook1 = new Cookie(); cook.Value = "1.5.2"; cook.Name = "appver"; cook.Domain = "music.163.com"; cook1.Value = " http://music.163.com/ "; cook1.Name = "Referer"; cook1.Domain = "music.163.com"; cookies.Add(cook); cookies.Add(cook1); request.CookieContainer = cookies; Stream myRequestStream = request.GetRequestStream(); byte[] postm = Encoding. ASCII.GetBytes(postinfo); using(Stream reqStream =request. GetRequestStream()){ reqStream.Write(postm,0,postm.Length); } HttpWebResponse resp = (HttpWebResponse)request. GetResponse(); Stream strem = resp.GetResponseStream(); StreamReader a1 = new StreamReader(strem); string a2 = a1.ReadToEnd(); return a2; }
Simple test finished product
References