feat: 支持切换 BBDown 下载

This commit is contained in:
zhiyu1998 2024-08-04 22:49:32 +08:00
parent 30d7693b14
commit ebca7c93a5
5 changed files with 112 additions and 15 deletions

View File

@ -277,6 +277,10 @@ aiApiKey: '' # 用于识图的api keykimi接口申请https://platform.moon
![](./img/xhs-ck-export.webp) ![](./img/xhs-ck-export.webp)
### 📺 关于使用 BBDown 下载
- Linux教程https://pwa.sspai.com/post/83345
- Windows教程https://github.com/nilaoda/BBDown/issues/305
## 🤺 R插件交流群 ## 🤺 R插件交流群

View File

@ -81,6 +81,7 @@ import {LagrangeAdapter} from "../utils/lagrange-adapter.js";
import path from "path"; import path from "path";
import {OpenaiBuilder} from "../utils/openai-builder.js"; import {OpenaiBuilder} from "../utils/openai-builder.js";
import {contentEstimator} from "../utils/link-share-summary-util.js"; import {contentEstimator} from "../utils/link-share-summary-util.js";
import {checkBBDown, startBBDown} from "../utils/bbdown-util.js";
export class tools extends plugin { export class tools extends plugin {
/** /**
@ -206,6 +207,8 @@ export class tools extends plugin {
this.biliSessData = this.toolsConfig.biliSessData; this.biliSessData = this.toolsConfig.biliSessData;
// 加载哔哩哔哩的限制时长 // 加载哔哩哔哩的限制时长
this.biliDuration = this.toolsConfig.biliDuration; this.biliDuration = this.toolsConfig.biliDuration;
// 加载哔哩哔哩是否使用BBDown
this.biliUseBBDown = this.toolsConfig.biliUseBBDown;
// 加载抖音Cookie // 加载抖音Cookie
this.douyinCookie = this.toolsConfig.douyinCookie; this.douyinCookie = this.toolsConfig.douyinCookie;
// 加载抖音是否压缩 // 加载抖音是否压缩
@ -593,25 +596,53 @@ export class tools extends plugin {
// 加入队列 // 加入队列
this.queue.add(async () => { this.queue.add(async () => {
// 下载文件 // 下载文件
getDownloadUrl(url) await this.biliDownloadStrategy(e, url, path);
.then(data => {
this.downBili(`${path}temp`, data.videoUrl, data.audioUrl)
.then(_ => {
this.sendVideoToUpload(e, `${path}temp.mp4`)
})
.catch(err => {
logger.error(err);
e.reply("解析失败,请重试一下");
});
})
.catch(err => {
logger.error(err);
e.reply("解析失败,请重试一下");
});
}) })
return true; return true;
} }
/**
* 哔哩哔哩下载策略
* @param e 事件
* @param url 链接
* @param path 保存路径
* @returns {Promise<void>}
*/
async biliDownloadStrategy(e, url, path) {
// =================以下是调用BBDown的逻辑=====================
// 下载视频和音频
const tempPath = `${path}temp`;
// 检测是否开启BBDown
if (this.biliUseBBDown) {
// 检测环境的 BBDown
const isExistBBDown = await checkBBDown();
// 存在 BBDown
if (isExistBBDown) {
// 删除之前的文件
await checkAndRemoveFile(`${tempPath}.mp4`);
// 下载视频
await startBBDown(url, path, this.biliSessData);
// 发送视频
return this.sendVideoToUpload(e, `${tempPath}.mp4`);
}
e.reply("🚧 R插件提醒你开启但未检测到当前环境有【BBDown】即将使用默认下载方式 ( ◡̀_◡́)ᕤ");
}
// =================默认下载方式=====================
try {
// 获取下载链接
const data = await getDownloadUrl(url);
await this.downBili(tempPath, data.videoUrl, data.audioUrl);
// 上传视频
return this.sendVideoToUpload(e, `${tempPath}.mp4`);
} catch (err) {
// 错误处理
logger.error('[R插件][哔哩哔哩视频发送]下载错误,具体原因为:', err);
e.reply("解析失败,请重试一下");
}
}
/** /**
* 下载哔哩哔哩最高画质视频 * 下载哔哩哔哩最高画质视频
* @param e 交互事件 * @param e 交互事件

View File

@ -8,6 +8,7 @@ translateSecret: '' # 百度翻译密匙
biliSessData: '' # 哔哩哔哩的SESSDATA biliSessData: '' # 哔哩哔哩的SESSDATA
biliIntroLenLimit: 50 # 哔哩哔哩简介长度限制,填 0 或者 -1 可以不做任何限制,显示完整简介 biliIntroLenLimit: 50 # 哔哩哔哩简介长度限制,填 0 或者 -1 可以不做任何限制,显示完整简介
biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟单位 biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟单位
biliUseBBDown: false # 是否使用BBDown默认不开启开启后使用强劲的BBDown下载最高画质
douyinCookie: '' # douyin's cookie, 格式odin_tt=xxx;passport_fe_beating_status=xxx;sid_guard=xxx;uid_tt=xxx;uid_tt_ss=xxx;sid_tt=xxx;sessionid=xxx;sessionid_ss=xxx;sid_ucp_v1=xxx;ssid_ucp_v1=xxx;passport_assist_user=xxx;ttwid=xxx; douyinCookie: '' # douyin's cookie, 格式odin_tt=xxx;passport_fe_beating_status=xxx;sid_guard=xxx;uid_tt=xxx;uid_tt_ss=xxx;sid_tt=xxx;sessionid=xxx;sessionid_ss=xxx;sid_ucp_v1=xxx;ssid_ucp_v1=xxx;passport_assist_user=xxx;ttwid=xxx;
douyinCompression: true # true-压缩false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送 douyinCompression: true # true-压缩false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送

View File

@ -110,6 +110,14 @@ export function supportGuoba() {
placeholder: "请输入哔哩哔哩的简介长度限制默认50个字符填 0 或者 -1 可以不做任何限制,显示完整简介", placeholder: "请输入哔哩哔哩的简介长度限制默认50个字符填 0 或者 -1 可以不做任何限制,显示完整简介",
}, },
}, },
{
field: "tools.biliUseBBDown",
label: "使用BBDown下载",
bottomHelpMessage:
"【默认不开启,涉及范围只有哔哩哔哩,开启后默认最高画质发送】如果不爱折腾就使用默认下载方式,如果喜欢折腾就开启,开启后下载更强劲,并且一劳永逸!",
component: "Switch",
required: false,
},
{ {
field: "tools.douyinCookie", field: "tools.douyinCookie",
label: "抖音的Cookie", label: "抖音的Cookie",

53
utils/bbdown-util.js Normal file
View File

@ -0,0 +1,53 @@
import { exec } from 'child_process';
import os from 'os';
/**
* 检测 BBDown 是否存在
* @param callback
*/
export function checkBBDown(callback) {
// 根据操作系统选择命令
return new Promise((resolve, reject) => {
const command = os.platform() === 'win32' ? 'where BBDown' : 'which BBDown';
exec(command, (error, stdout, stderr) => {
if (error) {
logger.error(`[R插件][BBDown]未找到: ${stderr || error.message}`);
resolve(false);
}
logger.info(`[R插件][BBDown]找到: ${stdout.trim()}`);
resolve(true);
});
});
}
/**
* 使用BBDown下载
* @param videoUrl 视频链接
* @param downloadDir 下载目录
* @param biliSessData cookie
*/
export function startBBDown(videoUrl, downloadDir, biliSessData) {
return new Promise((resolve, reject) => {
// logger.info(videoUrl);
// 解析URL并提取参数p页数
const urlObj = new URL(videoUrl);
const pageParam = urlObj.searchParams.get('p');
// 说明:-F 自定义名称,-c 自定义Cookie --work-dir 设置下载目录,-M 多p下载的时候命名
const command = `BBDown ${videoUrl} --work-dir ${downloadDir} ${biliSessData ? '-c ' + biliSessData : ''} ${pageParam ? '-p ' + pageParam + ' -M \"temp\"' : '-p 1' + ' -M \"temp\"'} -F temp`;
// logger.info(command);
// 直接调用BBDown因为它已经在系统路径中
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`[R插件][BBDown]执行出错: ${error.message}`);
return;
}
if (stderr) {
reject(`[R插件][BBDown]错误信息: ${stderr}`);
return;
}
logger.info(`[R插件][BBDown]输出结果: ${stdout}`);
resolve(stdout);
});
});
}