前端meting-api修改
TheStoneFishmeting-api修改
meting-js可以用于播放音乐, 但是由于很多歌曲都需要vip, 所以很多歌曲都无法播放。
修改后的源代码(只修改了qq音乐)
一、获取meting-api
meting-js可以添加自己的api, 所以可以通过修改meting-api来添加获取歌曲的其他方式。
1
| git clone https://github.com/xizeyoupan/Meting-API
|
二、metting-api添加获取歌曲的方法
在src\providers\tencent\song.js
是获取QQ音乐 歌曲信息、下载链接的方法。
添加下面的方法, 我这里使用的是gequbao.com
来获取歌曲的url。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| const find_download_url = async (id) => { const url = 'https://www.gequbao.com/api/play-url'; let result = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: `id=${encodeURIComponent(id)}` }); result = await result.json(); return result; }
const find_song_id = async (param) => { const url = `https://www.gequbao.com${param}`; let result = await fetch(url); result = await result.text(); const match = result.match(/window\.play_id\s*=\s*'([^']+)';/); return match[1]; }
const search_other = async (keyword) => { const url = `https://www.gequbao.com/s/${keyword}`; let result = await fetch(url); result = await result.text(); if(result.indexOf('热门资讯') != -1){ return ''; } const match = result.match(/\/music\/\d+/); const song_id = await find_song_id(match[0]); return await find_download_url(song_id); }
|
在get_song_url方法中添加判断, 如果获取不到url就去gequbao网站获取
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| export const get_song_url = async (song_id, cookie = '') => { let id = song_id.split(',') let uin = '' let qqmusic_key = '' const typeObj = { s: 'M500', e: '.mp3', }
const file = id.map(e => `${typeObj.s}${e}${e}${typeObj.e}`) const guid = (Math.random() * 10000000).toFixed(0);
let purl = '';
let data = { req_0: { module: 'vkey.GetVkeyServer', method: 'CgiGetVkey', param: { guid: guid, songmid: id, songtype: [0], uin: uin, loginflag: 1, platform: '20', }, }, comm: { uin: uin, format: 'json', ct: 19, cv: 0, authst: qqmusic_key, }, }
let params = { '-': 'getplaysongvkey', g_tk: 5381, loginUin: uin, hostUin: 0, format: 'json', inCharset: 'utf8', outCharset: 'utf-8¬ice=0', platform: 'yqq.json', needNewCode: 0, data: JSON.stringify(data), }
if (config.OVERSEAS || id.length > 1) { params.format = 'jsonp' const callback_function_name = 'callback' const callback_name = "callback" const parse_function = "qq_get_url_from_json" const url = changeUrlQuery(params, 'https://u.y.qq.com/cgi-bin/musicu.fcg') return "@" + parse_function + '@' + callback_name + '@' + callback_function_name + '@' + url }
const url = changeUrlQuery(params, 'https://u.y.qq.com/cgi-bin/musicu.fcg')
let result = await fetch(url);
result = await result.json() if (purl === '') { const song_info = (await get_song_info(song_id))[0]; let keyword = `${song_info['title']} ${song_info['author']}`; keyword = keyword.replace('/', '&') result = await search_other(keyword); return result.data.url; }
if (result.req_0 && result.req_0.data && result.req_0.data.midurlinfo) { purl = result.req_0.data.midurlinfo[0].purl; }
const domain = result.req_0.data.sip.find(i => !i.startsWith('http://ws')) || result.req_0.data.sip[0];
const res = `${domain}${purl}`.replace('http://', 'https://') return res;
}
|
三、运行meting-api
1、用nodejs运行
2、使用docker运行
构建镜像
1
| docker build -t meting-api .
|
运行
1
| docker run -d --name meting -p 127.0.0.1:3000:3000 meting-api:latest
|
四、使用meting-api
meting-api是可以配置接口的默认是使用官方接口
1
| this.api = this.meta.api || window.meting_api || 'https://api.i-meto.com/meting/api?server=:server&type=:type&id=:id&r=:r'
|
可以通过添加变量meting_api或者添加参数api来自定义接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <!DOCTYPE html> <html>
<head> <meta charset="utf-8" /> <title></title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"> <script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/meting/dist/Meting.min.js"></script> </head>
<body> <meting-js server="tencent" api="http://自己的接口地址/api?server=:server&type=:type&id=:id&auth=:auth&r=:r" type="playlist" id="8010915597"></meting-js> </body>
</html>
|