From 94b30c66f1b27cc3757e4e57469a43f3ac469d0a Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Thu, 30 May 2024 22:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8Dnetease?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E6=AD=8C=E6=9B=B2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 9 ++++++--- utils/common.js | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 2cfe2c4..02bf86e 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -34,7 +34,7 @@ import { } from "../constants/constant.js"; import { downloadImg, - downloadMp3, estimateReadingTime, + downloadAudio, estimateReadingTime, formatBiliInfo, getIdVideo, retryAxiosReq, secondsToTime, @@ -1026,8 +1026,11 @@ export class tools extends plugin { // 不是VIP歌曲,直接识别完就下一步 e.reply(`识别:网易云音乐,${ title }`); } + // 动态判断后缀名 + const extensionPattern = /\.([a-zA-Z0-9]+)$/; + const musicExt = url.match(extensionPattern); // 下载音乐 - downloadMp3(url, this.getCurDownloadPath(e), title, 'follow').then(async path => { + downloadAudio(url, this.getCurDownloadPath(e), title, 'follow', musicExt).then(async path => { // 发送语音 // e.reply(segment.record(path)); // 判断是不是icqq @@ -1490,7 +1493,7 @@ export class tools extends plugin { }); const url = vipMusicData.data.mp3; // 下载音乐 - downloadMp3(url, this.getCurDownloadPath(e), title, 'follow').then(async path => { + downloadAudio(url, this.getCurDownloadPath(e), title, 'follow').then(async path => { // 发送语音 // e.reply(segment.record(path)); // 判断是不是icqq diff --git a/utils/common.js b/utils/common.js index dde259f..3c41213 100644 --- a/utils/common.js +++ b/utils/common.js @@ -128,14 +128,15 @@ export function generateRandomStr(randomlength = 16) { * @param path 下载目录 * @param title 音乐名 * @param redirect 是否要重定向 + * @param audioType 建议填写 mp3 / m4a / flac 类型 * @returns {Promise} */ -export async function downloadMp3(mp3Url, path, title = "temp", redirect = "manual") { +export async function downloadAudio(mp3Url, path, title = "temp", redirect = "manual", audioType = "mp3") { // 如果没有目录就创建一个 await mkdirIfNotExists(path) // 补充保存文件名 - path += `/${ title }.mp3`; + path += `/${ title }.${audioType}`; if (fs.existsSync(path)) { console.log(`音频已存在`); fs.unlinkSync(path);