From d25c9883ff31a4eb2dfda9eb5bc0564afde98538 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Mon, 12 Aug 2024 22:38:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=20`bil?= =?UTF-8?q?i`=20=E9=9F=B3=E4=B9=90=E8=AF=86=E5=88=AB=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E6=83=85=E5=86=B5=20&=20=E5=8A=A0=E5=85=A5`=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E4=BA=BA=E6=95=B0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复音乐下载的特殊情况 2. 加入在线人数 --- apps/tools.js | 22 ++++++++++++++++++++-- constants/tools.js | 7 +++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 1e850b8..5c8c114 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -23,6 +23,7 @@ import { XHS_NO_WATERMARK_HEADER, } from "../constants/constant.js"; import { + BILI_ONLINE, BILI_STREAM_INFO, BILI_SUMMARY, DY_COMMENT, @@ -537,7 +538,7 @@ export class tools extends plugin { return true; } // 只提取音乐处理 - if (e.msg !== undefined && e.msg.includes("音乐")) { + if (e.msg !== undefined && e.msg.startsWith("音乐")) { e.reply("识别:哔哩哔哩音乐,正在提取请稍候...") return await this.biliMusic(e, url); } @@ -573,8 +574,10 @@ export class tools extends plugin { }; // 过滤简介中的一些链接 const filteredDesc = await filterBiliDescLink(desc); + // 拼接在线人数 + const onlineTotal = await this.biliOnlineTotal(bvid, cid); // 格式化数据 - const combineContent = `\n${ formatBiliInfo(dataProcessMap) }\n简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`; + const combineContent = `\n${ formatBiliInfo(dataProcessMap) }\n📝 简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }\n🏄‍♂️️ 当前视频有 ${onlineTotal.total} 人在观看,其中 ${onlineTotal.count} 人在网页端观看`; let biliInfo = [`识别:哔哩哔哩:${ title }`, combineContent] // 总结 const summary = await this.getBiliSummary(bvid, cid, owner.mid); @@ -655,6 +658,21 @@ export class tools extends plugin { } } + /** + * 获取在线人数 + * @param bvid + * @param cid + * @returns {Promise<{total: *, count: *}>} + */ + async biliOnlineTotal(bvid, cid) { + const onlineResp = await axios.get(BILI_ONLINE.replace("{0}", bvid).replace("{1}", cid)); + const online = onlineResp.data.data; + return { + total: online.total, + count: online.count + } + } + /** * 下载哔哩哔哩最高画质视频 * @param e 交互事件 diff --git a/constants/tools.js b/constants/tools.js index 95f6164..0fe2487 100644 --- a/constants/tools.js +++ b/constants/tools.js @@ -61,6 +61,13 @@ export const BILI_SCAN_CODE_DETECT = "https://passport.bilibili.com/x/passport-l */ export const BILI_STREAM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info" +/** + * 获取视频在线人数_web端 + * https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/online.md + * @type {string} + */ +export const BILI_ONLINE = "https://api.bilibili.com/x/player/online/total?bvid={0}&cid={1}" + /** * 米游社网页端获取文章 * https://github.com/UIGF-org/mihoyo-api-collect/blob/main/hoyolab/article/article.md#%E8%8E%B7%E5%8F%96%E5%AE%8C%E6%95%B4%E6%96%87%E7%AB%A0%E4%BF%A1%E6%81%AF