利用百度API获取mp3及歌词lrc下载地址

1. [代码]1、通过关键词,获取列表。

[html] view plain copy print ?
  1. http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=<word>&format=<format>  
  2. 参数:  
  3.     word: "歌曲名", //歌曲名 encodeURI  
  4.   
  5.     format: "json", //返回数据格式,xml | json,默认xml  
  6.   
  7.     callback: "Pub.music.searchResult", //固定值,返回jsonp格式  
  8.   
  9. 如 xml格式:  
  10. 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  
  11.   
  12. 返回:  
  13. <res>  
  14. <song>song>  
  15. <song_id>song_id>  
  16. <singer>singer>  
  17. <album>album>  
  18. <singerPicLarge>singerPicLarge>  
  19. <singerPicSmall>singerPicSmall>  
  20. <albumPicLarge>albumPicLarge>  
  21. <albumPicSmall>albumPicSmall>  
  22. res>  
http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=&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

返回:










 


 

2. [代码]返回json格式 

[html] view plain copy print ?
  1. 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  
  2.   
  3. 返回:  
  4.   
  5. {  
  6. "song": "\u6d41\u6d6a\u8bb0",  
  7. "song_id": "38233821",  
  8. "singer": "\u6768\u5b97\u7eac",  
  9. "album": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",  
  10. "singerPicSmall": "http:\/\/qukufile2.qianqian.com\/data2\/pic\/36218344\/36218344.jpg",  
  11. "singerPicLarge": "http:\/\/qukufile2.qianqian.com\/data2\/pic\/36218335\/36218335.jpg",  
  12. "albumPicLarge": "",  
  13. "albumPicSmall": ""  
  14. }  
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": "\u6d41\u6d6a\u8bb0",
"song_id": "38233821",
"singer": "\u6768\u5b97\u7eac",
"album": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",
"singerPicSmall": "http:\/\/qukufile2.qianqian.com\/data2\/pic\/36218344\/36218344.jpg",
"singerPicLarge": "http:\/\/qukufile2.qianqian.com\/data2\/pic\/36218335\/36218335.jpg",
"albumPicLarge": "",
"albumPicSmall": ""
}


 


 

3. [代码]2、通过歌曲id (song_id) 获取歌曲下载地址:

[html] view plain copy print ?
  1. http://ting.baidu.com/data/music/links?songIds=<songIds>  
  2. GET 方式获取:  
  3. 参数:  
  4.   
  5.     songIds: "38233821" //歌曲id,从第1个列表中得到的歌曲id    
  6.   
  7.     callback: "callback" //不为空时,返回jsonp格式数据  
  8.   
  9.   
  10. 如:http://ting.baidu.com/data/music/links?songIds=38233821  
  11.   
  12. 返回:  
  13.   
  14. {  
  15. "errorCode": 22000,  
  16. "data": {  
  17. "xcode": "808f67065a7ea25b17e77954bed13215",  
  18. "songList": [{  
  19. "queryId": "38233821",  
  20. "songId": 38233821,  
  21. "songName": "\u6d41\u6d6a\u8bb0",  
  22. "artistId": "8477",  
  23. "artistName": "\u6768\u5b97\u7eac",  
  24. "albumId": 38233662,  
  25. "albumName": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",  
  26. "songPicSmall": "http:\/\/c.hiphotos.baidu.com\/ting\/pic\/item\/29381f30e924b899d068ee4b6f061d950a7bf669.jpg",  
  27. "songPicBig": "http:\/\/c.hiphotos.baidu.com\/ting\/pic\/item\/2f738bd4b31c8701d1e22595267f9e2f0708ff69.jpg",  
  28. "songPicRadio": "http:\/\/c.hiphotos.baidu.com\/ting\/pic\/item\/b21bb051f81986185f1378f74bed2e738bd4e669.jpg",  
  29. "lrcLink": "\/data2\/lrc\/38238568\/38238568.lrc",  
  30. "version": "\u73b0\u573a",  
  31. "copyType": 1,  
  32. "time": 309,  
  33. "linkCode": 22000,  
  34. "songLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/38542270\/382338211365422461.mp3",  
  35. "showLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/38542270\/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215",  
  36. "format": "mp3",  
  37. "rate": 128,  
  38. "size": 4984113,  
  39. "relateStatus": "0",  
  40. "resourceType": "0"  
  41. }]  
  42. }  
  43. }  
http://ting.baidu.com/data/music/links?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": "\u6d41\u6d6a\u8bb0",
"artistId": "8477",
"artistName": "\u6768\u5b97\u7eac",
"albumId": 38233662,
"albumName": "\u6211\u662f\u6b4c\u624b \u7b2c\u5341\u4e00\u671f",
"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": "\u73b0\u573a",
"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"
}]
}
}

 

4. [代码]注意:mp3下载地址为 songLink,后面加xcode参数,xcode每秒自动更新一次。

[html] view plain copy print ?
  1. http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215  
http://zhangmenshiting.baidu.com/data2/music/38542270/382338211365422461.mp3?xcode=808f67065a7ea25b17e77954bed13215

 

5. [代码]歌词lrc地址为lrcLink前加http://ting.baidu.com 如: 

[html] view plain copy print ?
  1. http://ting.baidu.com/data2/lrc/15265710/15265710.lrc  

 

你可能感兴趣的:(android开发)