🐞 fix: 更换 dy 评论为官方接口

This commit is contained in:
zhiyu1998 2024-07-22 23:04:09 +08:00
parent 679c8deaca
commit 3d2a2f3676
3 changed files with 17 additions and 11 deletions

View File

@ -41,6 +41,7 @@ import {
estimateReadingTime,
formatBiliInfo,
retryAxiosReq,
saveJsonToFile,
secondsToTime,
testProxy,
truncateString
@ -306,7 +307,7 @@ export class tools extends plugin {
e.reply([segment.image(dyCover) ,`识别:抖音, ${ item.desc }\n
${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约${ Math.trunc(dyDuration / 60) }分钟\n大于管理员设置的最大时长 ${ durationThreshold / 60 } 分钟`])
// 如果开启评论的就调用
await this.douyinComment(e, douId);
await this.douyinComment(e, douId, headers);
return;
} else {
// 正常发送
@ -356,7 +357,7 @@ export class tools extends plugin {
await this.reply(await Bot.makeForwardMsg(no_watermark_image_list));
}
// 如果开启评论的就调用
await this.douyinComment(e, douId);
await this.douyinComment(e, douId, headers);
} catch (err) {
logger.error(err);
e.reply(`Cookie 过期或者 Cookie 没有填写,请参考\n${HELP_DOC}\n尝试无效后可以到官方QQ群[575663150]提出 bug 等待解决`)
@ -368,18 +369,23 @@ export class tools extends plugin {
* 获取 DY 评论暂时由群友 @慢热 提供
* @param e
* @param douId
* @param headers
*/
async douyinComment(e, douId) {
async douyinComment(e, douId, headers) {
if (!this.douyinComments) {
return;
}
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 dyCommentUrl = DY_COMMENT.replace("{}", douId);
const abParam = aBogus.generate_a_bogus(
new URLSearchParams(new URL(dyCommentUrl).search).toString(),
headers["User-Agent"],
);
const commentsResp = await axios.get(`${dyCommentUrl}&a_bogus=${ abParam }`, {
headers
})
const comments = commentsResp.data.data.comments;
// logger.info(headers)
// saveJsonToFile(commentsResp.data, "data.json", _);
const comments = commentsResp.data.comments;
const replyComments = comments.map(item => {
return {
message: item.text,

View File

@ -84,7 +84,7 @@ export const DY_INFO = "https://www.douyin.com/aweme/v1/web/aweme/detail/?device
* DY COMMENT API
* @type {string}
*/
export const DY_COMMENT = "https://bzapi.bzweb.xyz/api/public/dy/video/comment?id={}"
export const DY_COMMENT = "https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={}&cursor=0&count=20&item_type=0&insert_ids=&whale_cut_token=&cut_version=1&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=124.0.0.0&browser_online=true&engine_name=Blink&engine_version=124.0.0.0&os_name=Windows&os_version=10&cpu_core_num=20&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7361743797237679616"
/**
* 今日头条 DY API

View File

@ -435,7 +435,7 @@ export function checkCommandExists(command) {
* @param {string} filename - 目标文件名
* @param {function} callback - 可选的回调函数处理写入完成后的操作
*/
function saveJsonToFile(jsonData, filename, callback) {
export function saveJsonToFile(jsonData, filename, callback) {
// 转换 JSON 数据为字符串
const jsonString = JSON.stringify(jsonData, null, 2); // 第二个参数是 replacer第三个参数是缩进