mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: 网易云链接解析
This commit is contained in:
parent
648ed593c7
commit
9958568d05
@ -11,6 +11,7 @@ import {
|
|||||||
getUserRecord,
|
getUserRecord,
|
||||||
checkMusic,
|
checkMusic,
|
||||||
getSong,
|
getSong,
|
||||||
|
getSongDetail,
|
||||||
} from "../utils/netease.js";
|
} from "../utils/netease.js";
|
||||||
import { ha12store, store2ha1 } from "../utils/encrypt.js";
|
import { ha12store, store2ha1 } from "../utils/encrypt.js";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
@ -153,24 +154,27 @@ export class neteasepro extends plugin {
|
|||||||
musicUrlReg2.exec(message)[3] ||
|
musicUrlReg2.exec(message)[3] ||
|
||||||
musicUrlReg.exec(message)[2] ||
|
musicUrlReg.exec(message)[2] ||
|
||||||
/id=(\d+)/.exec(message)[1];
|
/id=(\d+)/.exec(message)[1];
|
||||||
const musicJson = JSON.parse(message);
|
const isMessageJson = await this.isJSON(message);
|
||||||
const { musicUrl, preview, title, desc } = musicJson.meta.music || musicJson.meta.news;
|
if (isMessageJson) {
|
||||||
console.log(musicUrl, preview, title, desc);
|
const musicJson = JSON.parse(message);
|
||||||
// 如果没有登陆,就使用官方接口
|
const { preview, title, desc } = musicJson.meta.music || musicJson.meta.news;
|
||||||
e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]);
|
// console.log(musicUrl, preview, title, desc);
|
||||||
if (!(await redis.exists(await this.getRedisKey(e.user_id)))) {
|
// 如果没有登陆,就使用官方接口
|
||||||
this.downloadMp3(`music.163.com/song/media/outer/url?id=${id}`, "follow")
|
e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]);
|
||||||
.then(path => {
|
if (!(await redis.exists(await this.getRedisKey(e.user_id)))) {
|
||||||
Bot.acquireGfs(e.group_id).upload(
|
this.downloadMp3(`music.163.com/song/media/outer/url?id=${id}`, "follow")
|
||||||
fs.readFileSync(path),
|
.then(path => {
|
||||||
"/",
|
Bot.acquireGfs(e.group_id).upload(
|
||||||
`${title.replace(/[\/\?<>\\:\*\|".… ]/g, "")}.mp3`,
|
fs.readFileSync(path),
|
||||||
);
|
"/",
|
||||||
})
|
`${title.replace(/[\/\?<>\\:\*\|".… ]/g, "")}.mp3`,
|
||||||
.catch(err => {
|
);
|
||||||
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
})
|
||||||
});
|
.catch(err => {
|
||||||
return true;
|
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 检查当前歌曲是否可用
|
// 检查当前歌曲是否可用
|
||||||
const checkOne = await checkMusic(id);
|
const checkOne = await checkMusic(id);
|
||||||
@ -181,13 +185,13 @@ export class neteasepro extends plugin {
|
|||||||
const userInfo = await this.aopBefore(e);
|
const userInfo = await this.aopBefore(e);
|
||||||
// 可用,开始下载
|
// 可用,开始下载
|
||||||
const userDownloadUrl = (await getSong(id, await userInfo.cookie))[0].url;
|
const userDownloadUrl = (await getSong(id, await userInfo.cookie))[0].url;
|
||||||
|
const title = await getSongDetail(id).then(res => {
|
||||||
|
const song = res.songs[0];
|
||||||
|
return `${song?.name}-${song?.ar?.[0].name}`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
|
||||||
|
});
|
||||||
await this.downloadMp3(userDownloadUrl)
|
await this.downloadMp3(userDownloadUrl)
|
||||||
.then(path => {
|
.then(path => {
|
||||||
Bot.acquireGfs(e.group_id).upload(
|
Bot.acquireGfs(e.group_id).upload(fs.readFileSync(path), "/", `${title}.mp3`);
|
||||||
fs.readFileSync(path),
|
|
||||||
"/",
|
|
||||||
`${title.replace(/[\/\?<>\\:\*\|".… ]/g, "")}.mp3`,
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
console.error(`下载音乐失败,错误信息为: ${err.message}`);
|
||||||
@ -231,13 +235,25 @@ export class neteasepro extends plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async isJSON(str) {
|
||||||
|
if (typeof str !== "string") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 定时轮询
|
// 定时轮询
|
||||||
async poll(key) {
|
async poll(key) {
|
||||||
let timer;
|
let timer;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
timer = setInterval(async () => {
|
timer = setInterval(async () => {
|
||||||
const statusRes = await getCookies(key);
|
const statusRes = await getCookies(key);
|
||||||
console.log(statusRes);
|
// console.log(statusRes);
|
||||||
if (statusRes.code === 800) {
|
if (statusRes.code === 800) {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
reject("二维码已过期,请重新获取");
|
reject("二维码已过期,请重新获取");
|
||||||
|
@ -115,6 +115,15 @@ async function getSong(id, cookie) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getSongDetail(ids) {
|
||||||
|
return axios({
|
||||||
|
url: `${BASE_URL}/song/detail?ids=${ids}×tamp=${Date.now()}`,
|
||||||
|
method: "get",
|
||||||
|
}).then(resp => {
|
||||||
|
return resp.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getCookies,
|
getCookies,
|
||||||
getLoginStatus,
|
getLoginStatus,
|
||||||
@ -124,4 +133,5 @@ export {
|
|||||||
getUserRecord,
|
getUserRecord,
|
||||||
checkMusic,
|
checkMusic,
|
||||||
getSong,
|
getSong,
|
||||||
|
getSongDetail
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user