新接口请看:百度 mp3 接口(新)
1、通过关键词,获取列表。
http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=<word>&format=<format>
参数:
1 word: "歌曲名", //歌曲名 encodeURI
2 format: "json", //返回数据格式,xml | json,默认xml
3 callback: "Pub.music.searchResult", //固定值,返回jsonp格式
如 xml 格式:
http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=%E6%B5%81%E6%B5%AA%E8%AE%B0&ie=utf-8&format=xml
返回:
1<res>
2 <song><![CDATA[流浪记]]></song>
3 <song_id><![CDATA[38233821]]></song_id>
4 <singer><![CDATA[杨宗纬]]></singer>
5 <album><![CDATA[我是歌手 第十一期]]></album>
6 <singerPicLarge><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218335/36218335.jpg]]></singerPicLarge>
7 <singerPicSmall><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218344/36218344.jpg]]></singerPicSmall>
8 <albumPicLarge><![CDATA[]]></albumPicLarge>
9 <albumPicSmall><![CDATA[]]></albumPicSmall>
10</res>
json 格式:
http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=%E6%B5%81%E6%B5%AA%E8%AE%B0&ie=utf-8&format=json
返回:
1{
2 "song": "\u6d41\u6d6a\u8bb0",
3 "song_id": "38233821",
4 "singer": "\u6768\u5b97\u7eac",
5 "album": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",
6 "singerPicSmall": "http://qukufile2.qianqian.com/data2/pic/36218344/36218344.jpg",
7 "singerPicLarge": "http://qukufile2.qianqian.com/data2/pic/36218335/36218335.jpg",
8 "albumPicLarge": "",
9 "albumPicSmall": ""
10}
2、通过歌曲 id (song_id) 获取歌曲下载地址:
http://ting.baidu.com/data/music/links?songIds=<songIds>
GET 方式获取: 参数:
1 songIds: "38233821" //歌曲id,从第1个列表中得到的歌曲id
2 callback: "callback" //不为空时,返回jsonp格式数据
如:http://ting.baidu.com/data/music/links?songIds=38233821
返回:
1{
2 "errorCode": 22000,
3 "data": {
4 "xcode": "808f67065a7ea25b17e77954bed13215",
5 "songList": [
6 {
7 "queryId": "38233821",
8 "songId": 38233821,
9 "songName": "\u6d41\u6d6a\u8bb0",
10 "artistId": "8477",
11 "artistName": "\u6768\u5b97\u7eac",
12 "albumId": 38233662,
13 "albumName": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",
14 "songPicSmall": "http://c.hiphotos.baidu.com/ting/pic/item/29381f30e924b899d068ee4b6f061d950a7bf669.jpg",
15 "songPicBig": "http://c.hiphotos.baidu.com/ting/pic/item/2f738bd4b31c8701d1e22595267f9e2f0708ff69.jpg",
16 "songPicRadio": "http://c.hiphotos.baidu.com/ting/pic/item/b21bb051f81986185f1378f74bed2e738bd4e669.jpg",
17 "lrcLink": "/data2/lrc/38238568/38238568.lrc",
18 "version": "\u73b0\u573a",
19 "copyType": 1,
20 "time": 309,
21 "linkCode": 22000,
22 "songLink": "http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3",
23 "showLink": "http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215",
24 "format": "mp3",
25 "rate": 128,
26 "size": 4984113,
27 "relateStatus": "0",
28 "resourceType": "0"
29 }
30 ]
31 }
32}
注意:mp3 下载地址为 songLink,后面加 xcode 参数,xcode 每秒自动更新一次。
如:
1http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215