优化多p标题的识别 单p不在识别分p标题 多p显示总标题和分p

This commit is contained in:
CSSZYF 2025-06-15 13:08:20 +08:00 committed by GitHub
parent e398a4cb99
commit 6e8c225686
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -840,35 +840,40 @@ export class tools extends plugin {
const { duration, bvid, cid, owner, pages } = videoInfo; const { duration, bvid, cid, owner, pages } = videoInfo;
let durationForCheck; let durationForCheck;
let displayTitle = videoInfo.title; // 默认使用总标题 let displayTitle = videoInfo.title; // 始终使用总标题
let partTitle = null; // 用于存储分P标题
let targetPageInfo = null; // 用于后续下载决策 let targetPageInfo = null; // 用于后续下载决策
const urlParts = url.split('?'); const urlParts = url.split('?');
const queryParams = urlParts.length > 1 ? querystring.parse(urlParts[1]) : {}; const queryParams = urlParts.length > 1 ? querystring.parse(urlParts[1]) : {};
const pParam = queryParams.p ? parseInt(queryParams.p, 10) : null; const pParam = queryParams.p ? parseInt(queryParams.p, 10) : null;
if (pParam && pages && pages.length >= pParam && pParam > 0) { // 只有当分P数量大于1时才认为是多P并处理分P标题
// 如果URL指定了有效的p参数 (p从1开始计数) if (pages && pages.length > 1) {
if (pParam && pages.length >= pParam && pParam > 0) {
// 如果URL指定了有效的p参数
targetPageInfo = pages[pParam - 1]; targetPageInfo = pages[pParam - 1];
durationForCheck = targetPageInfo.duration; durationForCheck = targetPageInfo.duration;
displayTitle = targetPageInfo.part; partTitle = targetPageInfo.part; // 存储分P标题
logger.info(`[R插件][Bili Duration] 分析到合集 P${pParam} (标题: ${displayTitle}), 时长: ${durationForCheck}s`); logger.info(`[R插件][Bili Duration] 分析到合集 P${pParam} (分P标题: ${partTitle}), 时长: ${durationForCheck}s`);
} else if (pages && pages.length > 0) { } else {
// 否则如果存在分P默认检查第一个分P // 否则默认检查第一个分P
targetPageInfo = pages[0]; targetPageInfo = pages[0];
durationForCheck = targetPageInfo.duration; durationForCheck = targetPageInfo.duration;
displayTitle = targetPageInfo.part; // 在多P情况下即使用户没有指定p也显示第一个分p的标题
logger.info(`[R插件][Bili Duration] 分析到合集 P1 (标题: ${displayTitle}), 时长: ${durationForCheck}s`); partTitle = targetPageInfo.part;
logger.info(`[R插件][Bili Duration] 分析到合集 P1 (分P标题: ${partTitle}), 时长: ${durationForCheck}s`);
}
} else { } else {
// 如果没有分P信息或pages为空使用总时长 // 单P或无分P信息
durationForCheck = duration; durationForCheck = duration;
// displayTitle 保持为 videoInfo.title // 对于单P视频我们不设置 partTitle以避免混淆
logger.info(`[R插件][Bili Duration] Using total duration (Title: ${displayTitle}): ${durationForCheck}s`); logger.info(`[R插件][Bili Duration] Using total duration (Title: ${displayTitle}): ${durationForCheck}s`);
} }
const isLimitDuration = durationForCheck > this.biliDuration; const isLimitDuration = durationForCheck > this.biliDuration;
// 动态构造哔哩哔哩信息 // 动态构造哔哩哔哩信息
let biliInfo = await this.constructBiliInfo(videoInfo, displayTitle); let biliInfo = await this.constructBiliInfo(videoInfo, displayTitle, partTitle, pParam || (pages && pages.length > 1 ? 1 : null));
// 总结 // 总结
if (this.biliDisplaySummary) { if (this.biliDisplaySummary) {
const summary = await this.getBiliSummary(bvid, cid, owner.mid); const summary = await this.getBiliSummary(bvid, cid, owner.mid);
@ -927,10 +932,13 @@ export class tools extends plugin {
/** /**
* 构造哔哩哔哩信息 * 构造哔哩哔哩信息
* @param videoInfo * @param videoInfo
* @returns {Promise<(string|string)[]>} * @param displayTitle
* @param partTitle
* @param pParam
* @returns {Promise<(string|string|*)[]>}
*/ */
async constructBiliInfo(videoInfo, displayTitle) { // displayTitle 参数 async constructBiliInfo(videoInfo, displayTitle, partTitle, pParam) { // 增加 partTitle 和 pParam 参数
const { desc, bvid, cid, pic } = videoInfo; // 移除了 title const { desc, bvid, cid, pic } = videoInfo;
// 视频信息 // 视频信息
const { view, danmaku, reply, favorite, coin, share, like } = videoInfo.stat; const { view, danmaku, reply, favorite, coin, share, like } = videoInfo.stat;
// 格式化数据 // 格式化数据
@ -961,7 +969,14 @@ export class tools extends plugin {
const onlineTotal = await this.biliOnlineTotal(bvid, cid); const onlineTotal = await this.biliOnlineTotal(bvid, cid);
combineContent += `\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`; combineContent += `\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`;
} }
let biliInfo = [`${ this.identifyPrefix }识别:哔哩哔哩,${ displayTitle }`, combineContent]; // 使用 displayTitle
let finalTitle = `${ this.identifyPrefix }识别:哔哩哔哩,${ displayTitle }`;
// 如果有多P标题并且它和主标题不一样则添加
if (partTitle && partTitle !== displayTitle) {
finalTitle += `|${pParam}P: ${ partTitle }`;
}
let biliInfo = [finalTitle, combineContent];
// 是否显示封面 // 是否显示封面
if (this.biliDisplayCover) { if (this.biliDisplayCover) {
// 加入图片 // 加入图片
@ -2169,7 +2184,6 @@ export class tools extends plugin {
await checkAndRemoveFile(`${path}/${videoFilename}`); await checkAndRemoveFile(`${path}/${videoFilename}`);
await checkAndRemoveFile(`${path}/${audioFilename}`); await checkAndRemoveFile(`${path}/${audioFilename}`);
await checkAndRemoveFile(`${path}/${thumbnailFilenamePrefix}.png`); await checkAndRemoveFile(`${path}/${thumbnailFilenamePrefix}.png`);
// 下载缩略图并获取实际文件名 // 下载缩略图并获取实际文件名
const actualThumbnailFilename = await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, thumbnailFilenamePrefix); const actualThumbnailFilename = await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, thumbnailFilenamePrefix);
const fullThumbnailPath = `${path}/${actualThumbnailFilename}`; const fullThumbnailPath = `${path}/${actualThumbnailFilename}`;
@ -3290,6 +3304,5 @@ export class tools extends plugin {
} else { } else {
await e.group.sendFile(path); await e.group.sendFile(path);
} }
await checkAndRemoveFile(path); // 上传成功后删除
} }
} }