通過QQ音樂介面獲取數據
最近正在學習做一個web移動音樂播放器,因為不想做資料庫存放數據,所以就學著在QQ音樂的介面獲取一些數據
獲取歌單數據:
url: https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg
//songList.jsexport function getDiscList() { const url = /api/getDiscList const data = Object.assign({}, commonParams, { platform: yqq, hostUin: 0, sin: 0, ein: 29, sortId: 5, needNewCode: 0, categoryId: 10000000, rnd: Math.random(), format: json }) return axios.get(url, { params: data }).then((res) => { return Promise.resolve(res.data) })}webpack.dev.conf.js// 通過axios代理獲取/*** 通過axios,從真實的QQ音樂的地址發送一個http請求,同時修改一個headers,正確響應,* 並將內容返回到前端界面* @param {[type]} req [require]* @param {String} res [response]* @param {Function} params: req.query [參數]* @return {[type]} [description]*/apiRoutes.get(/api/getDiscList, function(req, res) { var url = https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg axios.get(url, { headers: { referer: https://c.y.qq.com/, host: c.y.qq.com }, params: req.query }).then((response) => { // 將數據返回給前端 res.json(response.data) }).catch((e) => { console.log(e) })})
獲取輪播圖數據:
url: https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg
export function getRecommend() { const url = https://c.y.qq.com/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg const data = Object.assign({}, commonParams, { platform: h5, uin: 0, needNewCode: 1 }) return jsonp(url, data, options)}
獲取歌詞數據:
url: https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg
export function getDiscList() { const url = /api/getDiscList const data = Object.assign({}, commonParams, { platform: yqq, hostUin: 0, sin: 0, ein: 29, sortId: 5, needNewCode: 0, categoryId: 10000000, rnd: Math.random(), format: jsonp }) return axios.get(url, { params: data }).then((res) => { return Promise.resolve(res.data) })}// webpack.dev.conf.jsapiRoutes.get(/api/lyric, function(req, res) { var url = https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg axios.get(url, { headers: { referer: https://c.y.qq.com, host: c.y.qq.com }, params: req.query }).then((response) => { var ret = response.data if (typeof ret === string) { var reg = /^w+(({[^()]+}))$/ var matches = ret.match(reg) if (matches) { ret = JSON.parse(matches[1]) } } res.json(ret) }).catch((e) => { console.log(e) })})
獲取歌手信息:
url: https://szc.y.qq.com/v8/fcg-bin/v8.fcg
export function getSingerList() { const url = https://c.y.qq.com/v8/fcg-bin/v8.fcg const data = Object.assign({}, commonParams, { channel: singer, page: list, key: all_all_all, pagesize: 100, pagenum: 1, hostUin: 0, needNewCode: 0, platform: yqq, g_tk: 2001751543 }) return jsonp(url, data, options)}
獲取歌曲詳情:
url: https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg
export function getSingerDetail(singerId) { const url = https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg const data = Object.assign({}, commonParams, { hostUin: 0, needNewCode: 0, order: listen, platform: h5page, begin: 0, num: 100, songstatus: 1, singermid: singerId, g_tk: 2001751543 }) return jsonp(url, data, options)}
獲取排行榜數據(抓取移動端):
url: https://c.y.qq.com/v8/fcg-bin/fcg_myqq_toplist.fcg
獲取歌單歌曲列表:
url: https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg
獲取榜單詳情(移動端):
url: https://c.y.qq.com/v8/fcg-bin/fcg_v8_toplist_cp.fcg
推薦閱讀: