feat: 新增携带 dy 评论 [#IACU74]

1. 新增评论,默认不开启,可以自己配置后开启
This commit is contained in:
zhiyu1998 2024-07-15 20:31:16 +08:00
parent d26fd51eee
commit 4ed06a0eee
5 changed files with 145 additions and 96 deletions

View File

@ -48,7 +48,7 @@ body:
label: 版本 label: 版本
description: 你当前正在使用我们软件的哪个版本/分支? description: 你当前正在使用我们软件的哪个版本/分支?
options: options:
- 1.7.1 (默认) - 1.7.2 (默认)
- 1.7.1 (最新) - 1.7.2 (最新)
validations: validations:
required: true required: true

View File

@ -56,6 +56,7 @@ import PQueue from 'p-queue';
import { getWbi } from "../utils/biliWbi.js"; import { getWbi } from "../utils/biliWbi.js";
import { import {
BILI_SUMMARY, BILI_SUMMARY,
DY_COMMENT,
DY_INFO, DY_INFO,
DY_TOUTIAO_INFO, DY_TOUTIAO_INFO,
GENERAL_REQ_LINK, GENERAL_REQ_LINK,
@ -203,6 +204,8 @@ export class tools extends plugin {
this.douyinCookie = this.toolsConfig.douyinCookie; this.douyinCookie = this.toolsConfig.douyinCookie;
// 加载抖音是否压缩 // 加载抖音是否压缩
this.douyinCompression = this.toolsConfig.douyinCompression; this.douyinCompression = this.toolsConfig.douyinCompression;
// 加载抖音是否开启评论
this.douyinComments = this.toolsConfig.douyinComments;
// 翻译引擎 // 翻译引擎
this.translateEngine = new Translate({ this.translateEngine = new Translate({
translateAppId: this.toolsConfig.translateAppId, translateAppId: this.toolsConfig.translateAppId,
@ -244,7 +247,7 @@ export class tools extends plugin {
const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const douUrl = urlRex.exec(e.msg.trim())[0]; const douUrl = urlRex.exec(e.msg.trim())[0];
await this.douyinRequest(douUrl).then(async res => { const res = await this.douyinRequest(douUrl);
// 当前版本需要填入cookie // 当前版本需要填入cookie
if (_.isEmpty(this.douyinCookie)) { if (_.isEmpty(this.douyinCookie)) {
e.reply(`检测到没有Cookie无法解析抖音${HELP_DOC}`); e.reply(`检测到没有Cookie无法解析抖音${HELP_DOC}`);
@ -286,12 +289,12 @@ export class tools extends plugin {
// logger.info(item.video); // logger.info(item.video);
// 多位面选择play_addr、play_addr_265、play_addr_h264 // 多位面选择play_addr、play_addr_265、play_addr_h264
const { play_addr: { uri: videoAddrURI } } = item.video; const { play_addr: { uri: videoAddrURI } } = item.video;
const resolution = this.douyinCompression === 1 ? "720p" : "1080p"; const resolution = this.douyinCompression ? "720p" : "1080p";
// 使用今日头条 CDN 进一步加快解析速度 // 使用今日头条 CDN 进一步加快解析速度
const resUrl = DY_TOUTIAO_INFO.replace("1080p", resolution).replace("{}", videoAddrURI); const resUrl = DY_TOUTIAO_INFO.replace("1080p", resolution).replace("{}", videoAddrURI);
// ⚠️ 暂时废弃代码 // ⚠️ 暂时废弃代码
/*if (this.douyinCompression === 1) { /*if (this.douyinCompression) {
// H.265压缩率更高、流量省一半. 相对于H.264 // H.265压缩率更高、流量省一半. 相对于H.264
// 265 和 264 随机均衡负载 // 265 和 264 随机均衡负载
const videoAddrList = Math.random() > 0.5 ? play_addr_265.url_list : play_addr_h264.url_list; const videoAddrList = Math.random() > 0.5 ? play_addr_265.url_list : play_addr_h264.url_list;
@ -326,10 +329,40 @@ export class tools extends plugin {
// console.log(no_watermark_image_list) // console.log(no_watermark_image_list)
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list)); await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
} }
// 如果开启评论的就调用
if (this.douyinComments) {
const comments = (await this.douyinComment(douId)).unshift({
message: "前20条热门评论",
nickname: this.e.sender.card || this.e.user_id,
user_id: this.e.user_id,
}); });
e.reply(await Bot.makeForwardMsg(comments));
}
return true; return true;
} }
/**
* 获取 DY 评论暂时由群友 @慢热 提供
* @param douId
* @returns {Promise<*>}
*/
async douyinComment(douId) {
const commentsResp = await axios.get(DY_COMMENT.replace("{}", douId), {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
}
})
const comments = commentsResp.data.data.comments;
return comments.map(item => {
return {
message: item.text,
nickname: this.e.sender.card || this.e.user_id,
user_id: this.e.user_id,
}
})
}
// tiktok解析 // tiktok解析
async tiktok(e) { async tiktok(e) {
// 判断海外 // 判断海外
@ -1632,7 +1665,13 @@ export class tools extends plugin {
try { try {
const resp = await axios.head(url, params); const resp = await axios.head(url, params);
const location = resp.request.res.responseUrl; const location = resp.request.res.responseUrl;
return location; return new Promise((resolve, reject) => {
if (location != null) {
return resolve(location);
} else {
return reject("获取失败");
}
});
} catch (error) { } catch (error) {
console.error(error); console.error(error);
throw error; throw error;

View File

@ -10,7 +10,8 @@ biliIntroLenLimit: 50 # 哔哩哔哩简介长度限制,填 0 或者 -1 可以
biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟单位 biliDuration: 480 # 哔哩哔哩限制的最大视频时长默认8分钟单位
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: 1 # 1-压缩0-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送 douyinCompression: true # true-压缩false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送
douyinComments: false # true-开启评论false-关闭评论
queueConcurrency: 1 # 【目前只涉及哔哩哔哩的下载】根据服务器性能设置可以并发下载的个数如果你的服务器比较强劲就选择4~12较弱就一个一个下载选择1 queueConcurrency: 1 # 【目前只涉及哔哩哔哩的下载】根据服务器性能设置可以并发下载的个数如果你的服务器比较强劲就选择4~12较弱就一个一个下载选择1
@ -22,4 +23,4 @@ autoclearTrashtime: '0 0 8 * * ?' #每天早上8点自动清理视频缓存cr
aiBaseURL: '' # 用于识图的接口kimi默认接口为https://api.moonshot.cn其他服务商自己填写 aiBaseURL: '' # 用于识图的接口kimi默认接口为https://api.moonshot.cn其他服务商自己填写
aiApiKey: '' # 用于识图的api keykimi接口申请https://platform.moonshot.cn/console/api-keys aiApiKey: '' # 用于识图的api keykimi接口申请https://platform.moonshot.cn/console/api-keys
aiModel: 'claude-3-haiku-20240307' # 模型使用kimi不用填写其他要填写 aiModel: 'moonshot-v1-8k' # 模型使用kimi不用填写其他要填写

View File

@ -73,6 +73,12 @@ export const XHS_VIDEO = "http://sns-video-bd.xhscdn.com/"
*/ */
export const DY_INFO = "https://www.douyin.com/aweme/v1/web/aweme/detail/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={}&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=1344&screen_height=756&browser_language=zh-CN&browser_platform=Win32&browser_name=Firefox&browser_version=118.0&browser_online=true&engine_name=Gecko&engine_version=109.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=&platform=PC" export const DY_INFO = "https://www.douyin.com/aweme/v1/web/aweme/detail/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={}&pc_client_type=1&version_code=190500&version_name=19.5.0&cookie_enabled=true&screen_width=1344&screen_height=756&browser_language=zh-CN&browser_platform=Win32&browser_name=Firefox&browser_version=118.0&browser_online=true&engine_name=Gecko&engine_version=109.0&os_name=Windows&os_version=10&cpu_core_num=16&device_memory=&platform=PC"
/**
* DY COMMENT API
* @type {string}
*/
export const DY_COMMENT = "https://bzapi.bzweb.xyz/api/public/dy/video/comment?id={}"
/** /**
* 今日头条 DY API * 今日头条 DY API
* @type {string} * @type {string}

View File

@ -14,12 +14,14 @@ export function supportGuoba() {
isV3: true, isV3: true,
isV2: false, isV2: false,
description: "专门为朋友们写的Yunzai-Bot插件专注图片分享和生活的插件", description: "专门为朋友们写的Yunzai-Bot插件专注图片分享和生活的插件",
// 是否显示在左侧菜单可选值auto、true、false
// 当为 auto 时,如果配置项大于等于 3 个,则显示在左侧菜单
showInMenu: 'auto',
// 显示图标,此为个性化配置 // 显示图标,此为个性化配置
// 图标可在 https://icon-sets.iconify.design 这里进行搜索 // 图标可在 https://icon-sets.iconify.design 这里进行搜索
// icon: "mdi:share-reviews-sharp", icon: 'mdi:stove',
// 图标颜色,例:#FF0000 或 rgb(255, 0, 0) // 图标颜色,例:#FF0000 或 rgb(255, 0, 0)
// iconColor: "#3498db", iconColor: '#d19f56',
// 如果想要显示成图片,也可以填写图标路径(绝对路径)
iconPath: path.join(_path, "resources/img/rank/top.png"), iconPath: path.join(_path, "resources/img/rank/top.png"),
}, },
configInfo: { configInfo: {
@ -121,14 +123,15 @@ export function supportGuoba() {
}, },
{ {
field: "tools.douyinCompression", field: "tools.douyinCompression",
label: "抖音是否使用压缩格式1-压缩0-不压缩)", label: "抖音是否使用压缩格式",
bottomHelpMessage: component: "Switch",
"1-压缩0-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送",
component: "Input",
required: false, required: false,
componentProps: {
placeholder: "请输入1或者0默认1",
}, },
{
field: "tools.douyinComments",
label: "抖音是否开启评论",
component: "Switch",
required: false,
}, },
{ {
field: "tools.queueConcurrency", field: "tools.queueConcurrency",
@ -154,7 +157,7 @@ export function supportGuoba() {
}, },
{ {
field: "tools.lagrangeForwardWebSocket", field: "tools.lagrangeForwardWebSocket",
label: "拉格朗日正向WebSocket连接地址", label: "Lagrange.Core-WebSocket连接地址",
bottomHelpMessage: bottomHelpMessage:
"格式ws://地址:端口/,拉格朗日正向连接地址,用于适配拉格朗日上传群文件,解决部分用户无法查看视频问题", "格式ws://地址:端口/,拉格朗日正向连接地址,用于适配拉格朗日上传群文件,解决部分用户无法查看视频问题",
component: "Input", component: "Input",