mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🚑 fix: 紧急修复哔哩哔哩视频解析功能
- 移除旧的下载逻辑,采用新的API获取视频和音频下载链接 - 增加SESSDATA参数以支持会话数据传递 BREAKING CHANGE: 下载方法的参数和逻辑有重大更改
This commit is contained in:
parent
c61b520222
commit
0577915843
@ -615,16 +615,6 @@ export class tools extends plugin {
|
||||
Msg && (await e.reply(Msg));
|
||||
e.reply(biliInfo);
|
||||
}
|
||||
// 处理下载逻辑
|
||||
if (e.msg !== undefined && e.msg.startsWith("下载")) {
|
||||
// 检测是否扫码了,如果没有扫码数据终止下载
|
||||
if (_.isEmpty(this.biliSessData)) {
|
||||
e.reply("检测到没有填写biliSessData,下载终止!");
|
||||
return true;
|
||||
}
|
||||
await this.downloadBiliVideo(e, url, this.biliSessData);
|
||||
return true;
|
||||
}
|
||||
// 只提取音乐处理
|
||||
if (e.msg !== undefined && e.msg.startsWith("音乐")) {
|
||||
return await this.biliMusic(e, url);
|
||||
@ -716,7 +706,7 @@ export class tools extends plugin {
|
||||
// =================默认下载方式=====================
|
||||
try {
|
||||
// 获取下载链接
|
||||
const data = await getDownloadUrl(url);
|
||||
const data = await getDownloadUrl(url, this.biliSessData);
|
||||
|
||||
await this.downBili(tempPath, data.videoUrl, data.audioUrl);
|
||||
|
||||
@ -744,50 +734,6 @@ export class tools extends plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载哔哩哔哩最高画质视频
|
||||
* @param e 交互事件
|
||||
* @param url 下载链接
|
||||
* @param SESSDATA ck
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async downloadBiliVideo(e, url, SESSDATA) {
|
||||
const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1];
|
||||
const dash = await getBiliVideoWithSession(videoId, "", SESSDATA);
|
||||
// 限制时长,防止下载大视频卡死。暂时这样设计
|
||||
const curDuration = dash.duration;
|
||||
const isLimitDuration = curDuration > this.biliDuration;
|
||||
if (isLimitDuration) {
|
||||
const durationInMinutes = (curDuration / 60).toFixed(0);
|
||||
e.reply(`当前视频(${ videoId })时长为 ${ durationInMinutes } 分钟,大于管理员设置的时长 ${ this.biliDuration / 60 } 分钟`);
|
||||
return true;
|
||||
}
|
||||
// 获取关键信息
|
||||
const { video, audio } = dash;
|
||||
const videoData = video?.[0];
|
||||
const audioData = audio?.[0];
|
||||
// 提取信息
|
||||
const { height, frameRate, baseUrl: videoBaseUrl } = videoData;
|
||||
const { baseUrl: audioBaseUrl } = audioData;
|
||||
e.reply(`正在下载${ height }p ${ Math.trunc(frameRate) }帧数 视频,请稍候...`);
|
||||
const path = `${ this.getCurDownloadPath(e) }/`;
|
||||
const that = this;
|
||||
// 添加下载任务到并发队列
|
||||
this.queue.add(() =>
|
||||
that.downBili(`${ path }temp`, videoBaseUrl, audioBaseUrl)
|
||||
.then(_ => {
|
||||
that.sendVideoToUpload(e, `${ path }temp.mp4`);
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error(`[R插件][B站下载引擎] ${ err }`);
|
||||
e.reply("解析失败,请重试一下");
|
||||
})
|
||||
);
|
||||
logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${ this.queue.size }`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 下载哔哩哔哩音乐
|
||||
async biliMusic(e, url) {
|
||||
const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1];
|
||||
|
@ -199,32 +199,20 @@ async function axelDownloadBFile(url, fullFileName, progressCallback, videoDownl
|
||||
/**
|
||||
* 获取下载链接
|
||||
* @param url
|
||||
* @param SESSDATA
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function getDownloadUrl(url) {
|
||||
return axios
|
||||
.get(url, {
|
||||
headers: {
|
||||
...BILI_HEADER
|
||||
},
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const info = JSON.parse(
|
||||
data.match(/<script>window\.__playinfo__=({.*})<\/script><script>/)?.[1],
|
||||
);
|
||||
// 自动绕过解析不了的mcdn视频链接
|
||||
const videoUrl = selectAndAvoidMCdnUrl(info?.data?.dash?.video?.[0]?.baseUrl, info?.data?.dash?.video?.[0]?.backupUrl);
|
||||
// 自动绕过解析不了的mcdn音频链接
|
||||
const audioUrl = selectAndAvoidMCdnUrl(info?.data?.dash?.audio?.[0]?.baseUrl, info?.data?.dash?.audio?.[0]?.backupUrl);
|
||||
|
||||
const title = data.match(/title="(.*?)"/)?.[1]?.replaceAll?.(/\\|\/|:|\*|\?|"|<|>|\|/g, '');
|
||||
|
||||
if (videoUrl && audioUrl) {
|
||||
return { videoUrl, audioUrl, title };
|
||||
}
|
||||
|
||||
return Promise.reject('获取下载地址失败');
|
||||
});
|
||||
export async function getDownloadUrl(url, SESSDATA) {
|
||||
const videoId = /video\/[^\?\/ ]+/.exec(url)[0].split("/")[1];
|
||||
const dash = await getBiliVideoWithSession(videoId, "", SESSDATA);
|
||||
// 获取关键信息
|
||||
const { video, audio } = dash;
|
||||
const videoData = video?.[0];
|
||||
const audioData = audio?.[0];
|
||||
// 提取信息
|
||||
const { height, frameRate, baseUrl: videoBaseUrl } = videoData;
|
||||
const { baseUrl: audioBaseUrl } = audioData;
|
||||
return { videoUrl: videoBaseUrl, audioUrl: audioBaseUrl };
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user