From eeb859845c80f4de9b2fc7fca7b358808e9aee1e Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Fri, 13 Sep 2024 23:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=BC=BA=E5=93=94?= =?UTF-8?q?=E5=93=A9=E5=93=94=E5=93=A9=E8=A7=86=E9=A2=91=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 guoba.support.js 中添加了哔哩哔哩封面、信息、简介和在线人数显示选项 - 在 config/version.yaml 中更新版本至 1.8.1 并添加自定义识别功能,修正油管分辨率问题,新增小飞机解析 Beta 功能 - 在 config/tools.yaml 中添加哔哩哔哩显示选项配置 - 在 apps/tools.js 中实现哔哩哔哩信息动态构建,优化视频信息获取逻辑 - 优化 yt-dlp-util.js 中的命令行参数构建,添加视频质量限制选项 --- apps/tools.js | 79 ++++++++++++++++++++++++++++++++------------ config/tools.yaml | 6 +++- config/version.yaml | 5 +-- guoba.support.js | 32 ++++++++++++++++++ utils/yt-dlp-util.js | 8 +++-- 5 files changed, 102 insertions(+), 28 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index c3ddd35..7a9e4c5 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -234,6 +234,14 @@ export class tools extends plugin { this.biliSessData = this.toolsConfig.biliSessData; // 加载哔哩哔哩的限制时长 this.biliDuration = this.toolsConfig.biliDuration; + // 加载是否显示哔哩哔哩的封面 + this.biliDisplayCover = this.toolsConfig.biliDisplayCover; + // 加载是否显示哔哩哔哩的视频信息 + this.biliDisplayInfo = this.toolsConfig.biliDisplayInfo; + // 加载是否显示哔哩哔哩的简介 + this.biliDisplayIntro = this.toolsConfig.biliDisplayIntro; + // 加载是否显示哔哩哔哩的在线人数 + this.biliDisplayOnline = this.toolsConfig.biliDisplayOnline; // 加载哔哩哔哩是否使用BBDown this.biliUseBBDown = this.toolsConfig.biliUseBBDown; // 加载 BBDown 的CDN配置 @@ -574,33 +582,14 @@ export class tools extends plugin { // 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB // 请求视频信息 const videoInfo = await getVideoInfo(url); - const { title, pic, desc, duration, dynamic, stat, bvid, aid, cid, owner, pages } = videoInfo; - // 视频信息 - let { view, danmaku, reply, favorite, coin, share, like } = stat; + const { duration, bvid, cid, owner, pages } = videoInfo; // 限制时长 & 考虑分页视频情况 const query = querystring.parse(url); const curPage = query?.p || 0; const curDuration = pages?.[curPage]?.duration || duration; const isLimitDuration = curDuration > this.biliDuration - // 构造一个可扩展的Map - const dataProcessMap = { - "点赞": like, - "硬币": coin, - "收藏": favorite, - "分享": share, - "总播放量": view, - "弹幕数量": danmaku, - "评论": reply - }; - // 过滤简介中的一些链接 - 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) }\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`; - let biliInfo = [`${ this.identifyPrefix } 识别:哔哩哔哩:${ title }`, combineContent] - // 加入图片 - biliInfo.unshift(segment.image(pic)); + // 动态构造哔哩哔哩信息 + let biliInfo = await this.constructBiliInfo(videoInfo); // 总结 const summary = await this.getBiliSummary(bvid, cid, owner.mid); // 封装总结 @@ -631,6 +620,52 @@ export class tools extends plugin { return true; } + /** + * 构造哔哩哔哩信息 + * @param videoInfo + * @returns {Promise<(string|string)[]>} + */ + async constructBiliInfo(videoInfo) { + const { title, desc, bvid, cid, pic } = videoInfo; + // 视频信息 + const { view, danmaku, reply, favorite, coin, share, like } = videoInfo.stat; + // 构造一个可扩展的Map + const dataProcessMap = { + "点赞": like, + "硬币": coin, + "收藏": favorite, + "分享": share, + "总播放量": view, + "弹幕数量": danmaku, + "评论": reply + }; + // 过滤简介中的一些链接 + const filteredDesc = await filterBiliDescLink(desc); + // 拼接在线人数 + const onlineTotal = await this.biliOnlineTotal(bvid, cid); + // 格式化数据 + let combineContent = ""; + // 是否显示信息 + if (this.biliDisplayInfo) { + combineContent += `\n${ formatBiliInfo(dataProcessMap) }`; + } + // 是否显示简介 + if (this.biliDisplayIntro) { + combineContent += `\n📝 简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`; + } + // 是否显示在线人数 + if (this.biliDisplayOnline) { + combineContent += `\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`; + } + let biliInfo = [`${ this.identifyPrefix } 识别:哔哩哔哩:${ title }`, combineContent] + // 是否显示封面 + if (this.biliDisplayCover) { + // 加入图片 + biliInfo.unshift(segment.image(pic)); + } + return biliInfo; + } + /** * 获取哔哩哔哩番剧信息 * @param url diff --git a/config/tools.yaml b/config/tools.yaml index a33de57..14159e7 100644 --- a/config/tools.yaml +++ b/config/tools.yaml @@ -2,13 +2,17 @@ defaultPath: './data/rcmp4/' # 保存视频的位置 videoSizeLimit: 70 # 视频大小限制(单位MB),超过大小则转换成群文件上传 proxyAddr: '127.0.0.1' # 魔法地址 proxyPort: '7890' # 魔法端口 -identifyPrefix: '✅' # 识别前缀,比如你识别哔哩哔哩,那么就有:✅ 识别:哔哩哔哩 +identifyPrefix: '' # 识别前缀,比如你识别哔哩哔哩,那么就有:✅ 识别:哔哩哔哩 deeplApiUrls: 'https://deeplx.papercar.top/translate,https://deeplx.llleman.com/translate,https://dlx.bitjss.com/translate,https://free-deepl.speedcow.top/translate,https://deeplx.keyrotate.com/translate' biliSessData: '' # 哔哩哔哩的SESSDATA biliIntroLenLimit: 50 # 哔哩哔哩简介长度限制,填 0 或者 -1 可以不做任何限制,显示完整简介 biliDuration: 480 # 哔哩哔哩限制的最大视频时长(默认8分钟),单位:秒 +biliDisplayCover: true # 是否显示哔哩哔哩的封面 +biliDisplayInfo: true # 是否显示哔哩哔哩的视频信息 +biliDisplayIntro: true # 是否显示哔哩哔哩的简介 +biliDisplayOnline: true # 是否显示哔哩哔哩的在线人数 biliUseBBDown: false # 是否使用BBDown,默认不开启,开启后使用强劲的BBDown下载最高画质 biliCDN: 0 # 哔哩哔哩 CDN,默认为0表示不使用 biliDownloadMethod: 0 # 哔哩哔哩的下载方式:0默认使用原生稳定的下载方式,如果你在乎内存可以使用轻量的wget和axel下载方式,如果在乎性能可以使用Aria2下载 diff --git a/config/version.yaml b/config/version.yaml index c585ea0..7baf2bc 100644 --- a/config/version.yaml +++ b/config/version.yaml @@ -1,10 +1,11 @@ - { - version: 1.8.0-beta, + version: 1.8.1, data: [ + 新增自定义识别功能, + 修正油管分辨率降低到720P功能, 新增小飞机解析 Beta功能, 新增BBDown更换CDN功能, - 新增Aria2下载选项功能, 支持锅巴插件,方便查看和修改配置, 输入#R帮助获取插件帮助, 输入#R更新更新插件, diff --git a/guoba.support.js b/guoba.support.js index a96a9ef..6d63ba7 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -124,6 +124,38 @@ export function supportGuoba() { placeholder: "请输入哔哩哔哩的简介长度限制(默认50个字符),填 0 或者 -1 可以不做任何限制,显示完整简介", }, }, + { + field: "tools.biliDisplayCover", + label: "是否显示封面", + bottomHelpMessage: + "默认显示,哔哩哔哩是否显示封面", + component: "Switch", + required: true, + }, + { + field: "tools.biliDisplayInfo", + label: "是否显示相关信息", + bottomHelpMessage: + "默认显示,哔哩哔哩是否显示相关信息(点赞、硬币、收藏、分享、播放数、弹幕数、评论数)", + component: "Switch", + required: true, + }, + { + field: "tools.biliDisplayIntro", + label: "是否显示简介", + bottomHelpMessage: + "默认显示,哔哩哔哩是否显示简介", + component: "Switch", + required: true, + }, + { + field: "tools.biliDisplayOnline", + label: "是否显示在线人数", + bottomHelpMessage: + "默认显示,哔哩哔哩是否显示在线人数", + component: "Switch", + required: true, + }, { field: "tools.biliUseBBDown", label: "使用BBDown下载", diff --git a/utils/yt-dlp-util.js b/utils/yt-dlp-util.js index ba31fc0..a479cc7 100644 --- a/utils/yt-dlp-util.js +++ b/utils/yt-dlp-util.js @@ -7,7 +7,7 @@ import { exec, execSync } from "child_process"; * @returns {string|string} */ function constructProxyParam(isOversea, proxy) { - return isOversea ? "" : `--proxy ${ proxy }`; + return isOversea ? "" : `--proxy ${proxy}`; } /** @@ -18,7 +18,7 @@ function constructProxyParam(isOversea, proxy) { * @returns string */ export function ytDlpGetTilt(url, isOversea, proxy) { - return execSync(`yt-dlp --get-title ${ constructProxyParam(isOversea, proxy) } ${ url }`); + return execSync(`yt-dlp --get-title ${constructProxyParam(isOversea, proxy)} ${url}`); } /** @@ -33,7 +33,9 @@ export function ytDlpGetTilt(url, isOversea, proxy) { export async function ytDlpHelper(path, url, isOversea, proxy, merge = false) { return new Promise((resolve, reject) => { const mergeOption = merge ? '--merge-output-format "mp4"' : ''; - const command = `yt-dlp ${ constructProxyParam(isOversea, proxy) } -P ${ path } -o "temp.%(ext)s" ${ mergeOption } ${ url }`; + // 添加 -f 参数来限制视频质量 + const qualityOption = '-f "bestvideo[height<=720]+bestaudio/best[height<=720]"'; + const command = `yt-dlp ${constructProxyParam(isOversea, proxy)} -P ${path} -o "temp.%(ext)s" ${mergeOption} ${qualityOption} ${url}`; exec(command, (error, stdout) => { if (error) {