QQ音乐API-借他人之力实现我的音乐盒
好久没有写博客了,最近升级做爸爸了,很开心的事情。内心又很忧郁,怎么能给媳妇和儿子一个相对好的物质经济条件。现在什么都没有的我,至少还有你们。
话不多说了,这篇博客还是和自己用vue做web app相关。
因为自己没有这些音乐 MV相关的资源,借人家的当然是捷径。也希望能帮助那些和我有同样需求的人。
qq音乐网址: https://y.qq.com
所有先关的API已经简单封装到 https://github.com/xiangwenhu/vbox/blob/master/src/api
大约20多个,呵呵哒.
基础的地址信息配置
const COMMON_PARAMS = 'g_tk=5381&loginUin=0&hostUin=0&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0' // const C_Y_QQ_COM = 'https://c.y.qq.com' const C_Y_QQ_COM = '/cyqq' /* 歌手 */ // 搜索歌手 const URL_SEARCH_SINGER = `${C_Y_QQ_COM}/v8/fcg-bin/v8.fcg?channel=singer&page=list&format=json&${COMMON_PARAMS}` // 相似歌手 const URL_SINGER_SIM = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_simsinger.fcg?utf8=1&format=jsonp&${COMMON_PARAMS}` // 歌手的歌曲 const URL_SINGER_SONGS = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_singer_track_cp.fcg?format=json&order=listen&songstatus=1&${COMMON_PARAMS}` // 歌手的专辑 const URL_SINGER_ALBUM = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_singer_album.fcg?format=json&order=time&${COMMON_PARAMS}` // 歌手描述 const URL_SINGER_DESC = `${C_Y_QQ_COM}/splcloud/fcgi-bin/fcg_get_singer_desc.fcg?utf8=1&outCharset=utf-8&format=xml` /* 专辑 */ // 专辑的分类信息和默认首页 const URL_ALBUM_LIBRARY = `${C_Y_QQ_COM}/v8/fcg-bin/album_library?${COMMON_PARAMS}&format=json` // 专辑信息 const URL_ALBUM_INFO = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_album_info_cp.fcg?${COMMON_PARAMS}` /* 搜索 */ // 热门搜索关键字 const URL_HOT_KEY = `${C_Y_QQ_COM}/splcloud/fcgi-bin/gethotkey.fcg?${COMMON_PARAMS}` // 搜索结果-单曲 const URL_SEARCH_CLIENT_SONG = `${C_Y_QQ_COM}/soso/fcgi-bin/client_search_cp?format=json&ct=24&qqmusic_ver=1298&new_json=1&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&${COMMON_PARAMS}` // 搜索结果-mv const URL_SEARCH_CLIENT_MV = `${C_Y_QQ_COM}/soso/fcgi-bin/client_search_cp?ct=24&format=json&qqmusic_ver=1298&remoteplace=txt.yqq.mv&aggr=0&catZhida=1&lossless=0&sem=1&t=12&${COMMON_PARAMS}` // 搜素专辑 const URL_SEARCH_CLIENT_ALBUM = `${C_Y_QQ_COM}/soso/fcgi-bin/client_search_cp?ct=24&format=json&qqmusic_ver=1298&remoteplace=txt.yqq.album&aggr=0&catZhida=1&lossless=0&sem=10&t=8&${COMMON_PARAMS}` // 搜索后的智能搜索 const URL_SEARCH_SMARTBOX = `${C_Y_QQ_COM}/splcloud/fcgi-bin/smartbox_new.fcg?is_xml=0&format=json&${COMMON_PARAMS}` /* 排行 */ // 排行榜分类 const URL_TOPLIST_OPT = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_toplist_opt.fcg?page=index&format=html&tpl=macv4&v8debug=1` // 某个排行的列表 const URL_TOPLIST_LIST = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_v8_toplist_cp.fcg?tpl=3&page=detail&type=top&${COMMON_PARAMS}` // 节目的vkey const URL_VKEY = `${C_Y_QQ_COM}/base/fcgi-bin/fcg_music_express_mobile3.fcg?cid=205361747&uin=0&guid=488797456&${COMMON_PARAMS}` /* 歌单 */ // 歌单的分类 const URL_DISS_TAG_CONF = `${C_Y_QQ_COM}/splcloud/fcgi-bin/fcg_get_diss_tag_conf.fcg?format=json&${COMMON_PARAMS}` // 按照分类查询歌单 const URL_DISS_BYTAG = `${C_Y_QQ_COM}/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg?format=json&sin=0&ein=29&${COMMON_PARAMS}` // 获取某个歌单的内容 const URL_DISS_INFO = `${C_Y_QQ_COM}/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg?type=1&json=1&utf8=1&onlysong=0&format=json&${COMMON_PARAMS}` // 相似歌单 const URL_DISS_SIMILAR = `${C_Y_QQ_COM}/musichall/fcgi-bin/fcg_similar_recomm.fcg?recomtype=2&format=json` /* MV */ // MV查询 taglist=1 有标签 const URL_MV_BYTAG = `${C_Y_QQ_COM}/v8/fcg-bin/getmv_by_tag?utf8=1&otype=json&format=json&${COMMON_PARAMS}` // MV信息 const URL_MV_INFO = `${C_Y_QQ_COM}/mv/fcgi-bin/fcg_getmvinfo.fcg?format=json&${COMMON_PARAMS}` // 相似MV const URL_MV_SIMILAR = `${C_Y_QQ_COM}/mv/fcgi-bin/fcg_getmvlist.fcg?reqtype=1&cid=205360328&format=json&${COMMON_PARAMS}` // 首页推荐 const URL_RRCOM = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_first_yqq.fcg?format=json&tpl=v12&page=other&${COMMON_PARAMS}` /* 歌曲 */ // 歌曲歌词 const URL_SONG_LYR = `${C_Y_QQ_COM}/lyric/fcgi-bin/fcg_query_lyric_new.fcg?${COMMON_PARAMS}&format=json` // 歌曲信息TO:: const URL_SONG_INFO = `${C_Y_QQ_COM}/v8/fcg-bin/fcg_play_single_song.fcg?songmid=0016IcYd27ZJWw&tpl=yqq_song_detail&format=json&g_tk=1885845528&${COMMON_PARAMS}` // 歌曲所在的专辑 const URL_SONG_ALBUM = `${C_Y_QQ_COM}/rcmusic/fcgi-bin/fcg_iphone_music_rec_songlist?cid=338&ct=20&uin=10000&&g_tk=1885845528&${COMMON_PARAMS}` const MusicJsonCallback = function (data) { return data } global.MusicJsonCallback = MusicJsonCallback export default { URL_SEARCH_SINGER, URL_SINGER_SIM, URL_SINGER_SONGS, URL_SINGER_ALBUM, URL_SINGER_DESC, URL_ALBUM_LIBRARY, URL_ALBUM_INFO, URL_HOT_KEY, URL_SEARCH_CLIENT_SONG, URL_SEARCH_CLIENT_MV, URL_SEARCH_CLIENT_ALBUM, URL_SEARCH_SMARTBOX, URL_TOPLIST_OPT, URL_TOPLIST_LIST, URL_VKEY, URL_DISS_TAG_CONF, URL_DISS_BYTAG, URL_DISS_INFO, URL_DISS_SIMILAR, URL_MV_BYTAG, URL_MV_INFO, URL_MV_SIMILAR, URL_RRCOM, URL_SONG_LYR, URL_SONG_INFO, URL_SONG_ALBUM }
具体请求Other
import URLConsts from './URLConsts' export default { // 热搜关键字 hotkey: function () { let url = `${URLConsts.URL_HOT_KEY}` return fetch(url) }, /** * 排行分类 */ topList() { let url = URLConsts.URL_TOPLIST_OPT return fetch(url).then(res => { return res.text() }).then(content => { function jsonCallback(data) { return JSON.stringify(data) } return eval(content) }) }, /** * 排行榜详细数据 * @param {*} topid id * @param {*} song_begin 开始 * @param {*} song_num 结束 */ topListList(topid = 4, song_begin = 0, song_num = 30) { let today = new Date(), yes = new Date(today.getTime() - 1000 * 60 * 60 * 24), date = yes.getFullYear() + '-' + ((yes.getMonth() + 1) + '').padStart(2, '0') + '-' + (yes.getDate() + '').padStart(2, '0'), url = `${URLConsts.URL_TOPLIST_LIST}&topid=${topid}&date=${date}&song_begin=${song_begin}&song_num=${song_num}` return fetch(url) }, /** * 歌曲的vkey * @param {*} songmid 歌曲id */ vkey(songmid) { let url = `${URLConsts.URL_VKEY}&songmid=${songmid}&filename=C400${songmid}.m4a` return fetch(url) }, /** * 歌单的分类 */ dissTagConf() { return fetch(URLConsts.URL_DISS_TAG_CONF) }, /** * 按照分类查询歌单 * @param {*} categoryId * @param {*} sortId 排序 5 推荐 / 2 最新 * 返回结果 dissid 为歌单编号 */ dissByTag(categoryId = 10000000, sortId = 5) { let url = `${URLConsts.URL_DISS_BYTAG}&categoryId=${categoryId}&sortId=${sortId}&rnd=${Math.random().toFixed(16)}` return fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ headers: { referer: 'https://y.qq.com/portal/playlist.html', 'Accept': 'application/json', 'Content-Type': 'application/json' } }) }) }, /** * 按照id获取歌单信息 * @param {*} disstid 歌单id */ dissInfo(disstid) { let url = `${URLConsts.URL_DISS_INFO}&disstid=${disstid}` return fetch(url) }, /** * 相似歌单 * @param {*} dissid 歌单id * @param {*} maxnum 最大返回条数 */ dissSimilar(dissid, maxnum = 6) { let url = `${URLConsts.URL_DISS_SIMILAR}&dissid=${dissid}&maxnum=${maxnum}&_=${new Date().getTime()}` return fetch(url) }, // 首页推荐 RecomList() { let url = `${URLConsts.URL_RRCOM}&rnd=${(Math.random() * Math.pow(10, 16)).toFixed(0)}` return fetch(url) } }
搜索Search
import URLConsts from './URLConsts' export default { // 歌手搜索 singers: function (type = 'all_all', hot = 'all', pagenum = 1, pagesize = 100) { let url = `${URLConsts.URL_SEARCH_SINGER}&key=${type}_${hot}&pagenum=${pagenum}&pagesize=${pagesize}` return fetch(url) }, // 专辑信息 albumInfo: function (albummid) { let url = `${URLConsts.URL_ALBUM_INFO}&albummid=${albummid}` return fetch(url) }, /** * @param {*w} 关键字 * @param {*remoteplace}类型 txt.yqq.mv/txt.yqq.album/txt.yqq.center * @param {*p} 页码 * @param {*n} 页大小 * 返回结果:zhida.type 2:专辑 0:歌曲 1: 歌手 */ searchSongs(w, p = 1, n = 30) { let url = `${URLConsts.URL_SEARCH_CLIENT_SONG}&remoteplace=txt.yqq.center&w=${encodeURIComponent(w)}&p=${p}&n=${n}` return fetch(url) }, /** * 执行搜索后搜索mv * @param {*} w 关键字 * @param {*} p 页面 * @param {*} n 特大小 */ searchMVs(w, p = 1, n = 30) { let url = `${URLConsts.URL_SEARCH_CLIENT_MV}&w=${encodeURIComponent(w)}&p=${p}&n=${n}` return fetch(url) }, // 执行搜索后搜索专辑 searchAlbums(w, p = 1, n = 30) { let url = `${URLConsts.URL_SEARCH_CLIENT_ALBUM}&w=${encodeURIComponent(w)}&p=${p}&n=${n}` return fetch(url) }, /** * 执行搜索后的智能搜索 * @param {*} key 关键字 */ smartBox(key) { let url = `${URLConsts.URL_SEARCH_SMARTBOX}&key=${encodeURIComponent(key)}` return fetch(url) }, /** * * @param {*} cmd firstpage 返回分类信息 /get_album_info 不返回分类信息 * @param {*} page 页码 * @param {*} pagesize 页大小 * @param {*} sort 1 最新 / 2 最热 * @param {*} language 语种 * @param {*} genre 流派 * @param {*} year 年代 * @param {*} pay 价格 1 免费 / 2 免费 * @param {*} type 类别 专辑/演唱会等 * @param {*} company 唱片公司 华纳唱片/环球唱片等 */ albumLib(cmd = 'firstpage', page = 0, pagesize = 20, sort = 1, language = -1, genre = 0, year = 1, pay = 0, type = -1, company = -1) { let url = `${URLConsts.URL_ALBUM_LIBRARY}&cmd=${cmd}&page=${page}&pagesize=${pagesize}&sort=${sort}&language=${language}&genre=${genre}&year=${year}&pay=${pay}&type=${type}&company=${company}` return fetch(url) }, /** * 通过标签搜索MV * @param {*} area 区域 * @param {*} tag 类型 官方版/舞蹈等 * @param {*} year 年份 * @param {*} type 排序 2最热/1最新 * @param {*} taglist 是否带标签, 1带/0不带 * @param {*} pageno 页码 * @param {*} pagecount 也大小 */ mvByTag(area = 0, tag = 0, year = 0, type = 2, taglist = 1, pageno = 0, pagecount = 20) { let url = `${URLConsts.URL_MV_BYTAG}&area=${area}&tag=${tag}&year=${year}&type=${type}&taglist=${taglist}&pageno=${pageno}&pagecount=${pagecount}&_=${Math.random().toFixed(16)}` return fetch(url) }, /** * 获得MV的信息 * @param {*} vid mv id */ mvInfo(vid) { let url = `${URLConsts.URL_MV_INFO}&vid=${vid}` return fetch(url).then(res => res.text()).then(content => { return eval(content) }) }, /** * 相似MV *@param {*} vid mv id */ mvSimilar(vid) { let url = `${URLConsts.URL_MV_SIMILAR}&vid=${vid}` return fetch(url) }, /** * 获取歌词信息 decodeURIComponent(escape(window.atob('sds==' ))) * @param {*} songmid 歌曲id */ lyric(songmid) { let url = `${URLConsts.URL_SONG_LYR}&songmid=${songmid}&pcachetime=${new Date().getTime()}` return fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ headers: { referer: 'https://y.qq.com/portal/player.html' } }) }).then(res => res.text()).then(content => eval(content)) }, // 歌曲信息 songInfo(songmid) { let url = `${URLConsts.URL_SONG_INFO}&songmid=${songmid}` return fetch(url) }, // 歌曲所在的专辑 songAlbums(songid) { let url = `${URLConsts.URL_SONG_ALBUM}&songid=${songid}` return fetch(url) } }
歌手相关Singer
import URLConsts from './URLConsts' export default class Singer { constructor(singermid) { // 歌手id this.singermid = singermid } // 相似歌手 simsinger(start = 0, num = 5) { let url = `${URLConsts.URL_SINGER_SIM}&singer_mid=${this.singermid}&start=${start}&num=${num}` return fetch(url) } // 歌曲 songs(begin = 0, num = 30) { let url = `${URLConsts.URL_SINGER_SONGS}&singermid=${this.singermid}&begin=${begin}&num=${num}` return fetch(url) } // 专辑 albums(begin = 0, num = 30) { let url = `${URLConsts.URL_SINGER_ALBUM}&singermid=${this.singermid}&begin=${begin}&num=${num}` return fetch(url) } // 歌手描述 desc() { let r = new Date().getTime() let url = `${URLConsts.URL_SINGER_DESC}&singermid=${this.singermid}&r=${r}` return fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ headers: { referer: 'https://c.y.qq.com/xhr_proxy_utf8.html', 'Host': 'y.qq.com', 'Origin': 'https://y.qq.com' } }) }) } }