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