今天听了一天的歌曲,打算搞一个在线播放器,可惜要为歌曲烦恼,本来是打算想把歌曲下载下来放入到空间里面,可这样就会消费空间流量,于是就百度了一下百度音乐的MP3接口,有些是json返回获取,但我要介绍不是这款啦,这个感觉挺麻烦的,最简单的就是获取id咯,先给下链接
http://ting.baidu.com/data/music/links?songIds=35509935
访问以上链接会返回出现{ "errorCode": 22000, "data": { "xcode": "2dd12fdc443fbc21b033f115eaff28df", "songList": [{ "queryId": "35509935", "songId": 35509935, "songName": "\u671f\u5f85 (\uae30\ub300\ud574)", "artistId": "85849406", "artistName": "Girl\u0027s Day", "albumId": 35509930, "albumName": "\u671f\u5f85 (\uae30\ub300)", "songPicSmall": "http:\/\/b.hiphotos.baidu.com\/ting\/pic\/item\/d4628535e5dde7115f93c18fa4efce1b9d166102.jpg", "songPicBig": "http:\/\/a.hiphotos.baidu.com\/ting\/pic\/item\/caef76094b36acaf92a114857fd98d1001e99c02.jpg", "songPicRadio": "http:\/\/b.hiphotos.baidu.com\/ting\/pic\/item\/adaf2edda3cc7cd9328fb6a03a01213fb80e912d.jpg", "lrcLink": "\/data2\/lrc\/70442867\/70442867.lrc", "version": "", "copyType": 1, "time": 195, "linkCode": 22000, "songLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/124011321\/355099351413612061.mp3?xcode=2dd12fdc443fbc214e3750572fbff757787251487e4e2c6c", "showLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/124011321\/355099351413612061.mp3?xcode=2dd12fdc443fbc214e3750572fbff757787251487e4e2c6c", "format": "mp3", "rate": 128, "size": 3122475, "relateStatus": "0", "resourceType": "2" }] } }
那么songIds后面的35509935是怎么获取的呢,打开你搜索的歌曲页面,如我搜索《想你 (????)》这首歌曲,他的链接是http://music.baidu.com/song/124002223那么请直接复制124002223这个,这就是songIds后面要输入的,然后访问就会返回一下信息:
{ "errorCode": 22000, "data": { "xcode": "548293ff72ac871a4bd29ebbbfef7ca5", "songList": [{ "queryId": "124002223", "songId": 124002223, "songName": "\u60f3\u4f60 (\ubcf4\uace0\uc2f6\uc5b4)", "artistId": "85849406", "artistName": "Girl\u0027s Day", "albumId": 124002228, "albumName": "\ubcf4\uace0\uc2f6\uc5b4", "songPicSmall": "http:\/\/a.hiphotos.baidu.com\/ting\/pic\/item\/342ac65c103853433f6d29589013b07eca80882d.jpg", "songPicBig": "http:\/\/a.hiphotos.baidu.com\/ting\/pic\/item\/c8ea15ce36d3d5390a9fa1ba3987e950352ab02d.jpg", "songPicRadio": "http:\/\/b.hiphotos.baidu.com\/ting\/pic\/item\/d8f9d72a6059252d67b5b37d379b033b5bb5b92d.jpg", "lrcLink": "\/data2\/lrc\/124002535\/124002535.lrc", "version": "", "copyType": 1, "time": 217, "linkCode": 22000, "songLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/124002264\/1240022231413496861.mp3?xcode=548293ff72ac871a9ca047e54ae3b85327adbfabbc2e2bea", "showLink": "http:\/\/zhangmenshiting.baidu.com\/data2\/music\/124002264\/1240022231413496861.mp3?xcode=548293ff72ac871a9ca047e54ae3b85327adbfabbc2e2bea", "format": "mp3", "rate": 128, "size": 3476064, "relateStatus": "0", "resourceType": "0" }] } }
xcode每秒自动更新一次,出现以上信息那就好办多了,访问songLink链接就OK了,这样歌曲就下载出来了,也不在将歌曲下载下来了,妈妈在也不用担心为歌曲下载而烦恼了
发表评论: