From 5bbef5ef8a0f592b577e62b9000304a197c3ff4b Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Sun, 9 Apr 2023 14:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9F=AD=E9=93=BE=E6=8E=A5=E8=A7=A3=E6=9E=90=E6=95=88=E7=8E=87?= =?UTF-8?q?=20&=20=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E5=AF=BC=E8=87=B4=E8=A7=86=E9=A2=91=E6=97=B6=E9=95=BF?= =?UTF-8?q?=E4=BC=B0=E8=AE=A1=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 16 +++++++++++----- utils/biliInfo.js | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 6e02d9d..64176aa 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -19,6 +19,7 @@ import { getBiliGptInputText } from "../utils/biliSummary.js"; import { getBodianAudio, getBodianMv, getBodianMusicInfo } from "../utils/bodian.js"; import { ChatGPTBrowserClient } from "@waylaidwanderer/chatgpt-api"; import { av2BV } from "../utils/bilibili-bv-av-convert.js"; +import querystring from "querystring"; export class tools extends plugin { constructor() { @@ -285,7 +286,9 @@ export class tools extends plugin { // 短号处理 if (url.includes("b23.tv")) { const bShortUrl = bShortRex.exec(url)[0]; - await fetch(bShortUrl).then(resp => { + await fetch(bShortUrl, { + method: "HEAD" + }).then(resp => { url = resp.url; }); } else if (url.includes("www.bilibili.com")) { @@ -327,10 +330,13 @@ export class tools extends plugin { // 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB // 请求视频信息 const videoInfo = await getVideoInfo(url); - const { title, desc, duration, dynamic, stat, aid, cid } = videoInfo; - // 限制时长 - if (duration > this.biliDuration) { - e.reply(`当前视频时长约:${(duration / 60).toFixed(0)}分钟,\n大于管理员设置的最大时长 ${this.biliDuration / 60} 分钟!`); + const { title, desc, duration, dynamic, stat, aid, cid, pages } = videoInfo; + // 限制时长 & 考虑分页视频情况 + const query = querystring.parse(url); + const curPage = query?.p || 0; + const curDuration = pages?.[curPage].duration || duration; + if (curDuration > this.biliDuration) { + e.reply(`当前视频时长约:${(pages?.[curPage].duration / 60).toFixed(0)}分钟,\n大于管理员设置的最大时长 ${this.biliDuration / 60} 分钟!`); return true; } // 视频信息 diff --git a/utils/biliInfo.js b/utils/biliInfo.js index b898f3a..00e0e80 100644 --- a/utils/biliInfo.js +++ b/utils/biliInfo.js @@ -17,6 +17,7 @@ async function getVideoInfo(url) { stat: respData.stat, aid: respData.aid, cid: respData.pages?.[0].cid, + pages: respData?.pages, }; }); }