feat: 增强哔哩哔哩视频信息显示选项

- 在 guoba.support.js 中添加了哔哩哔哩封面、信息、简介和在线人数显示选项
- 在 config/version.yaml 中更新版本至 1.8.1 并添加自定义识别功能,修正油管分辨率问题,新增小飞机解析 Beta 功能
- 在 config/tools.yaml 中添加哔哩哔哩显示选项配置
- 在 apps/tools.js 中实现哔哩哔哩信息动态构建,优化视频信息获取逻辑
- 优化 yt-dlp-util.js 中的命令行参数构建,添加视频质量限制选项
This commit is contained in:
zhiyu1998 2024-09-13 23:42:56 +08:00
parent 22274d805c
commit eeb859845c
5 changed files with 102 additions and 28 deletions

View File

@ -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

View File

@ -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下载

View File

@ -1,10 +1,11 @@
- {
version: 1.8.0-beta,
version: 1.8.1,
data:
[
新增<span class="cmd">自定义识别</span>功能,
修正<span class="cmd">油管分辨率降低到720P</span>功能,
新增<span class="cmd">小飞机解析 Beta</span>功能,
新增<span class="cmd">BBDown更换CDN</span>功能,
新增<span class="cmd">Aria2下载选项</span>功能,
支持<span class="cmd">锅巴</span>插件,方便查看和修改配置,
输入<span class="cmd">#R帮助</span>获取插件帮助,
输入<span class="cmd">#R更新</span>更新插件,

View File

@ -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下载",

View File

@ -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) {