1 Star 0 Fork 153

yzli/MusicFreePlugins_1

forked from 猫头猫/MusicFreePlugins 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
qmkg.js 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
猫头猫 提交于 2022-10-03 10:42 . feat: 缓存控制
function qmkg(packages) {
const { axios, cheerio } = packages;
async function parseMusicItemFromUrl(shareUrl) {
const html = (await axios.get(shareUrl)).data;
const $ = cheerio.load(html);
const script = $("script:contains('window.__DATA__')").text();
const jsonStr = script.match(/window\.__DATA__ \=(.+);\s*$/);
if (jsonStr) {
const result = JSON.parse(jsonStr[1]);
const musicItem = {
id: result.detail.ksong_mid,
shareid: result.shareid,
lrc: result.lyric,
artwork: result.detail.cover,
title: result.detail.song_name,
artist: `${result.detail.nick} (原唱: ${result.detail.singer_name})`,
album: result.detail.content,
url: result.detail.playurl,
detail: result.detail
}
return musicItem;
}
}
return {
platform: '全民K歌',
version: '0.0.0',
srcUrl: 'https://gitee.com/maotoumao/MusicFreePlugins/raw/master/qmkg.js',
cacheControl: 'no-store',
async getMediaSource(musicItem) {
if (musicItem.shareid) {
const newItem = await parseMusicItemFromUrl(`https://kg.qq.com/node/play?s=${musicItem.shareid}`);
return {
url: newItem.url,
}
}
return {
url: musicItem.url,
}
},
async importMusicItem(shareUrl) {
return parseMusicItemFromUrl(shareUrl);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/whihi/MusicFreePlugins_1.git
git@gitee.com:whihi/MusicFreePlugins_1.git
whihi
MusicFreePlugins_1
MusicFreePlugins_1
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385