From a3687141c0dcf4697999560a5ce4208bd1a66355 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Thu, 16 Mar 2023 10:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B8=B8=E5=AE=A2=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90netease?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/neteasepro.js | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/apps/neteasepro.js b/apps/neteasepro.js index a982939..9231336 100644 --- a/apps/neteasepro.js +++ b/apps/neteasepro.js @@ -154,28 +154,36 @@ export class neteasepro extends plugin { musicUrlReg2.exec(message)[3] || musicUrlReg.exec(message)[2] || /id=(\d+)/.exec(message)[1]; - const isMessageJson = await this.isJSON(message); - // 如果是小程序 & 是游客 - if (isMessageJson && !(await redis.get(await this.getRedisKey(e.user_id)))) { - const musicJson = JSON.parse(message); - const { preview, title, desc } = musicJson.meta.music || musicJson.meta.news; - // console.log(musicUrl, preview, title, desc); - // 如果没有登陆,就使用官方接口 - e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]); - if (!(await redis.exists(await this.getRedisKey(e.user_id)))) { - this.downloadMp3(`music.163.com/song/media/outer/url?id=${id}`, "follow") - .then(path => { - Bot.acquireGfs(e.group_id).upload( - fs.readFileSync(path), - "/", - `${title.replace(/[\/\?<>\\:\*\|".… ]/g, "")}.mp3`, - ); - }) - .catch(err => { - console.error(`下载音乐失败,错误信息为: ${err.message}`); - }); - return true; + // 是游客 + if (!(await redis.get(await this.getRedisKey(e.user_id)))) { + // 是小程序 + if (await this.isJSON(message)) { + const musicJson = JSON.parse(message); + const { preview, title, desc } = musicJson.meta.music || musicJson.meta.news; + // console.log(musicUrl, preview, title, desc); + // 如果没有登陆,就使用官方接口 + e.reply([`识别:网易云音乐,${title}--${desc}`, segment.image(preview)]); + } else { + // 非小程序 + const title = await getSongDetail(id).then(res => { + const song = res.songs[0]; + return `${song?.name}-${song?.ar?.[0].name}`.replace(/[\/\?<>\\:\*\|".… ]/g, ""); + }); + e.reply(`识别:网易云音乐,${title}`); } + // 下载游客歌曲 + this.downloadMp3(`https://music.163.com/song/media/outer/url?id=${id}`, "follow") + .then(path => { + Bot.acquireGfs(e.group_id).upload( + fs.readFileSync(path), + "/", + `${id}.mp3`, + ); + }) + .catch(err => { + console.error(`下载音乐失败,错误信息为: ${err.message}`); + }); + return true; } // 检查当前歌曲是否可用 const checkOne = await checkMusic(id);