mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🐞 fix: 修复哔哩哔哩总结不能总结一些没有弹幕视频的问题
This commit is contained in:
parent
28b106fa93
commit
d8401b3a90
@ -10,7 +10,7 @@ import HttpProxyAgent from "https-proxy-agent";
|
||||
import { mkdirsSync } from "../utils/file.js";
|
||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
||||
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
||||
import { transMap, douyinTypeMap, XHS_CK } from "../utils/constant.js";
|
||||
import { transMap, douyinTypeMap, XHS_CK, TEN_THOUSAND } from "../utils/constant.js";
|
||||
import { getIdVideo, generateRandomStr } from "../utils/common.js";
|
||||
import config from "../model/index.js";
|
||||
import Translate from "../utils/trans-strategy.js";
|
||||
@ -332,7 +332,21 @@ export class tools extends plugin {
|
||||
}
|
||||
// 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB
|
||||
// 请求视频信息
|
||||
const { title, combineContent, aid, cid } = await getVideoInfo(url);
|
||||
const videoInfo = await getVideoInfo(url);
|
||||
const { title, desc, dynamic, stat, aid, cid } = videoInfo
|
||||
// 视频信息
|
||||
let { view, danmaku, reply, favorite, coin, share, like } = stat;
|
||||
// 数据处理
|
||||
const dataProcessing = data => {
|
||||
return Number(data) >= TEN_THOUSAND ? (data / TEN_THOUSAND).toFixed(1) + "万" : data;
|
||||
};
|
||||
const combineContent = `总播放量:${dataProcessing(view)}, 弹幕数量:${dataProcessing(
|
||||
danmaku,
|
||||
)}, 回复量:${dataProcessing(reply)}, 收藏数:${dataProcessing(
|
||||
favorite,
|
||||
)}, 投币:${dataProcessing(coin)}, 分享:${dataProcessing(share)}, 点赞:${dataProcessing(
|
||||
like,
|
||||
)}\n`;
|
||||
e.reply([title, combineContent]);
|
||||
|
||||
await getDownloadUrl(url)
|
||||
@ -355,9 +369,9 @@ export class tools extends plugin {
|
||||
if (this.biliSessData && this.openaiApiKey) {
|
||||
let prompt;
|
||||
try {
|
||||
prompt = await getBiliGptInputText(title, aid, cid, this.biliSessData);
|
||||
prompt = await getBiliGptInputText({title, desc, dynamic, aid, cid}, this.biliSessData);
|
||||
} catch (err) {
|
||||
logger.error("总结失败,可能是没有弹幕或者网络问题!");
|
||||
logger.error("总结失败,可能是没有弹幕或者网络问题!\n", err);
|
||||
return true;
|
||||
}
|
||||
const response = await this.chatGptClient.sendMessage(prompt);
|
||||
|
@ -12,27 +12,11 @@ async function getVideoInfo(url) {
|
||||
).then(async resp => {
|
||||
const respJson = await resp.json();
|
||||
const respData = respJson.data;
|
||||
// 视频标题
|
||||
const title = "识别:哔哩哔哩," + respData.title + "\n";
|
||||
// 视频图片(暂时不加入,影响性能)
|
||||
// const videoCover = respData.pic;
|
||||
// 视频信息
|
||||
let { view, danmaku, reply, favorite, coin, share, like } = respData.stat;
|
||||
// 数据处理
|
||||
const dataProcessing = data => {
|
||||
return Number(data) >= TEN_THOUSAND ? (data / TEN_THOUSAND).toFixed(1) + "万" : data;
|
||||
};
|
||||
// 组合内容
|
||||
const combineContent = `总播放量:${dataProcessing(view)}, 弹幕数量:${dataProcessing(
|
||||
danmaku,
|
||||
)}, 回复量:${dataProcessing(reply)}, 收藏数:${dataProcessing(
|
||||
favorite,
|
||||
)}, 投币:${dataProcessing(coin)}, 分享:${dataProcessing(share)}, 点赞:${dataProcessing(
|
||||
like,
|
||||
)}\n`;
|
||||
return {
|
||||
title,
|
||||
combineContent,
|
||||
title: respData.title,
|
||||
desc: respData.desc,
|
||||
dynamic: respJson.data.dynamic,
|
||||
stat: respData.stat,
|
||||
aid: respData.aid,
|
||||
cid: respData.pages?.[0].cid,
|
||||
};
|
||||
|
@ -1,13 +1,12 @@
|
||||
import _ from 'lodash'
|
||||
/**
|
||||
* 获取gpt提取视频信息的文字
|
||||
* @param title 视频标题
|
||||
* @param aid
|
||||
* @param cid
|
||||
* @param videoInfo
|
||||
* @param biliSessData
|
||||
* @param shouldShowTimestamp 是否在每段字幕前面加入时间标识
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export async function getBiliGptInputText(title, aid, cid, biliSessData, shouldShowTimestamp = false) {
|
||||
export async function getBiliGptInputText(videoInfo, biliSessData, shouldShowTimestamp = false) {
|
||||
const headers = {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
@ -22,26 +21,32 @@ export async function getBiliGptInputText(title, aid, cid, biliSessData, shouldS
|
||||
headers,
|
||||
referrerPolicy: "no-referrer",
|
||||
};
|
||||
const {title, desc, dynamic, aid, cid} = videoInfo
|
||||
// https://api.bilibili.com/x/player/v2?aid=438937138&cid=1066979272
|
||||
const resp = await fetch(
|
||||
`https://api.bilibili.com/x/player/v2?aid=${aid}&cid=${cid}`,
|
||||
commonConfig,
|
||||
);
|
||||
const subtitles = (await resp.json()).data.subtitle.subtitles;
|
||||
const res = await fetch(`http:${subtitles[0]?.subtitle_url}`);
|
||||
if (_.isUndefined(res)) {
|
||||
throw new Error("");
|
||||
const subtitlesUrl = subtitles?.subtitle_url?.startsWith('//')
|
||||
? `https:${subtitles?.subtitle_url}`
|
||||
: subtitles?.subtitle_url
|
||||
let inputText = "";
|
||||
logger.mark(subtitlesUrl);
|
||||
if (subtitlesUrl !== undefined) {
|
||||
const res = await fetch(subtitlesUrl);
|
||||
const subtitlesData = (await res.json()).body;
|
||||
const subtitleTimestamp = reduceBilibiliSubtitleTimestamp(subtitlesData, shouldShowTimestamp);
|
||||
inputText = getSmallSizeTranscripts(subtitleTimestamp, subtitleTimestamp);
|
||||
} else {
|
||||
inputText = `${desc} ${dynamic}`;
|
||||
}
|
||||
const subtitlesData = (await res.json()).body;
|
||||
const subtitleTimestamp = reduceBilibiliSubtitleTimestamp(subtitlesData, shouldShowTimestamp);
|
||||
const inputText = getSmallSizeTranscripts(subtitleTimestamp, subtitleTimestamp);
|
||||
const videoConfig = {
|
||||
showEmoji: false,
|
||||
};
|
||||
const userPrompt = shouldShowTimestamp
|
||||
return shouldShowTimestamp
|
||||
? getUserSubtitleWithTimestampPrompt(title, inputText, videoConfig)
|
||||
: getUserSubtitlePrompt(title, inputText, videoConfig);
|
||||
return userPrompt;
|
||||
}
|
||||
|
||||
// 以下拼接算法来自:https://github.com/JimmyLv/BibiGPT
|
||||
|
Loading…
x
Reference in New Issue
Block a user