From 0577915843e4c7100ac161b4af7181d123cad140 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Thu, 5 Sep 2024 13:37:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20fix:=20=E7=B4=A7=E6=80=A5?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=93=94=E5=93=A9=E5=93=94=E5=93=A9=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E8=A7=A3=E6=9E=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除旧的下载逻辑,采用新的API获取视频和音频下载链接 - 增加SESSDATA参数以支持会话数据传递 BREAKING CHANGE: 下载方法的参数和逻辑有重大更改 --- apps/tools.js | 56 +---------------------------------------------- utils/bilibili.js | 36 ++++++++++-------------------- 2 files changed, 13 insertions(+), 79 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 29a0f23..31a6b9b 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -615,16 +615,6 @@ export class tools extends plugin { Msg && (await e.reply(Msg)); e.reply(biliInfo); } - // 处理下载逻辑 - if (e.msg !== undefined && e.msg.startsWith("下载")) { - // 检测是否扫码了,如果没有扫码数据终止下载 - if (_.isEmpty(this.biliSessData)) { - e.reply("检测到没有填写biliSessData,下载终止!"); - return true; - } - await this.downloadBiliVideo(e, url, this.biliSessData); - return true; - } // 只提取音乐处理 if (e.msg !== undefined && e.msg.startsWith("音乐")) { return await this.biliMusic(e, url); @@ -716,7 +706,7 @@ export class tools extends plugin { // =================默认下载方式===================== try { // 获取下载链接 - const data = await getDownloadUrl(url); + const data = await getDownloadUrl(url, this.biliSessData); await this.downBili(tempPath, data.videoUrl, data.audioUrl); @@ -744,50 +734,6 @@ export class tools extends plugin { } } - /** - * 下载哔哩哔哩最高画质视频 - * @param e 交互事件 - * @param url 下载链接 - * @param SESSDATA ck - * @returns {Promise} - */ - async downloadBiliVideo(e, url, SESSDATA) { - const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1]; - const dash = await getBiliVideoWithSession(videoId, "", SESSDATA); - // 限制时长,防止下载大视频卡死。暂时这样设计 - const curDuration = dash.duration; - const isLimitDuration = curDuration > this.biliDuration; - if (isLimitDuration) { - const durationInMinutes = (curDuration / 60).toFixed(0); - e.reply(`当前视频(${ videoId })时长为 ${ durationInMinutes } 分钟,大于管理员设置的时长 ${ this.biliDuration / 60 } 分钟`); - return true; - } - // 获取关键信息 - const { video, audio } = dash; - const videoData = video?.[0]; - const audioData = audio?.[0]; - // 提取信息 - const { height, frameRate, baseUrl: videoBaseUrl } = videoData; - const { baseUrl: audioBaseUrl } = audioData; - e.reply(`正在下载${ height }p ${ Math.trunc(frameRate) }帧数 视频,请稍候...`); - const path = `${ this.getCurDownloadPath(e) }/`; - const that = this; - // 添加下载任务到并发队列 - this.queue.add(() => - that.downBili(`${ path }temp`, videoBaseUrl, audioBaseUrl) - .then(_ => { - that.sendVideoToUpload(e, `${ path }temp.mp4`); - }) - .catch(err => { - logger.error(`[R插件][B站下载引擎] ${ err }`); - e.reply("解析失败,请重试一下"); - }) - ); - logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${ this.queue.size }`); - - return true; - } - // 下载哔哩哔哩音乐 async biliMusic(e, url) { const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1]; diff --git a/utils/bilibili.js b/utils/bilibili.js index 4b7bbcf..d1e7a1a 100644 --- a/utils/bilibili.js +++ b/utils/bilibili.js @@ -199,32 +199,20 @@ async function axelDownloadBFile(url, fullFileName, progressCallback, videoDownl /** * 获取下载链接 * @param url + * @param SESSDATA * @returns {Promise} */ -export async function getDownloadUrl(url) { - return axios - .get(url, { - headers: { - ...BILI_HEADER - }, - }) - .then(({ data }) => { - const info = JSON.parse( - data.match(/