1、通过关键词,获取列表。
http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=<word>&format=<format>
参数:
word: "歌曲名", //歌曲名 encodeURI
format: "json", //返回数据格式,xml | json,默认xml
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
返回:
<res>
<song><![CDATA[流浪记]]></song>
<song_id><![CDATA[38233821]]></song_id>
<singer><![CDATA[杨宗纬]]></singer>
<album><![CDATA[我是歌手 第十一期]]></album>
<singerPicLarge><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218335/36218335.jpg]]></singerPicLarge>
<singerPicSmall><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218344/36218344.jpg]]></singerPicSmall>
<albumPicLarge><![CDATA[]]></albumPicLarge>
<albumPicSmall><![CDATA[]]></albumPicSmall>
</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
返回:
{
"song": "u6d41u6d6au8bb0",
"song_id": "38233821",
"singer": "u6768u5b97u7eac",
"album": "u6211u662fu6b4cu624b u7b2cu5341u4e00u671f",
"singerPicSmall": "http://qukufile2.qianqian.com/data2/pic/36218344/36218344.jpg",
"singerPicLarge": "http://qukufile2.qianqian.com/data2/pic/36218335/36218335.jpg",
"albumPicLarge": "",
"albumPicSmall": ""
}
2、通过歌曲id (song_id) 获取歌曲下载地址:
http://ting.baidu.com/data/music/links?songIds=<songIds>
GET 方式获取:
参数:
songIds: "38233821" //歌曲id,从第1个列表中得到的歌曲id
callback: "callback" //不为空时,返回jsonp格式数据
如:http://ting.baidu.com/data/music/links?songIds=38233821
返回:
{
"errorCode": 22000,
"data": {
"xcode": "808f67065a7ea25b17e77954bed13215",
"songList": [{
"queryId": "38233821",
"songId": 38233821,
"songName": "u6d41u6d6au8bb0",
"artistId": "8477",
"artistName": "u6768u5b97u7eac",
"albumId": 38233662,
"albumName": "u6211u662fu6b4cu624b u7b2cu5341u4e00u671f",
"songPicSmall": "http://c.hiphotos.baidu.com/ting/pic/item/29381f30e924b899d068ee4b6f061d950a7bf669.jpg",
"songPicBig": "http://c.hiphotos.baidu.com/ting/pic/item/2f738bd4b31c8701d1e22595267f9e2f0708ff69.jpg",
"songPicRadio": "http://c.hiphotos.baidu.com/ting/pic/item/b21bb051f81986185f1378f74bed2e738bd4e669.jpg",
"lrcLink": "/data2/lrc/38238568/38238568.lrc",
"version": "u73b0u573a",
"copyType": 1,
"time": 309,
"linkCode": 22000,
"songLink": "http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3",
"showLink": "http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215",
"format": "mp3",
"rate": 128,
"size": 4984113,
"relateStatus": "0",
"resourceType": "0"
}]
}
}
注意:mp3下载地址为 songLink,后面加xcode参数,xcode每秒自动更新一次。
如:
http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215