From a4cf8df5da3b0f6c9a6db616e9f4f620f6fd6719 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Sun, 4 Aug 2024 14:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=20xhs?= =?UTF-8?q?=20=E6=B2=A1=E6=9C=89ck=E6=8F=90=E7=A4=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 351 +++++++++++++++++++++++++------------------------- 1 file changed, 178 insertions(+), 173 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 263b79d..9783ca9 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -1,14 +1,14 @@ // 主库 import fetch from "node-fetch"; import fs from "node:fs"; -import { Buffer } from 'node:buffer'; +import {Buffer} from 'node:buffer'; // 其他库 import axios from "axios"; import _ from "lodash"; import tunnel from "tunnel"; -import { HttpsProxyAgent } from 'https-proxy-agent'; -import { exec, execSync } from "child_process"; -import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists } from "../utils/file.js"; +import {HttpsProxyAgent} from 'https-proxy-agent'; +import {exec, execSync} from "child_process"; +import {checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists} from "../utils/file.js"; import { downloadBFile, filterBiliDescLink, @@ -21,7 +21,7 @@ import { m4sToMp3, mergeFileToMp4 } from "../utils/bilibili.js"; -import { downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl } from "../utils/acfun.js"; +import {downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl} from "../utils/acfun.js"; import { BILI_DEFAULT_INTRO_LEN_LIMIT, COMMON_USER_AGENT, @@ -51,11 +51,11 @@ import { import config from "../model/index.js"; import Translate from "../utils/trans-strategy.js"; import * as aBogus from "../utils/a-bogus.cjs"; -import { getBodianAudio, getBodianMusicInfo, getBodianMv } from "../utils/bodian.js"; -import { av2BV } from "../utils/bilibili-bv-av-convert.js"; +import {getBodianAudio, getBodianMusicInfo, getBodianMv} from "../utils/bodian.js"; +import {av2BV} from "../utils/bilibili-bv-av-convert.js"; import querystring from "querystring"; import PQueue from 'p-queue'; -import { getWbi } from "../utils/biliWbi.js"; +import {getWbi} from "../utils/biliWbi.js"; import { BILI_STREAM_INFO, BILI_SUMMARY, @@ -73,14 +73,14 @@ import { WEISHI_VIDEO_INFO, XHS_REQ_LINK } from "../constants/tools.js"; -import { processTikTokUrl } from "../utils/tiktok.js"; -import { getDS } from "../utils/mihoyo.js"; +import {processTikTokUrl} from "../utils/tiktok.js"; +import {getDS} from "../utils/mihoyo.js"; import GeneralLinkAdapter from "../utils/general-link-adapter.js"; -import { mid2id } from "../utils/weibo.js"; -import { LagrangeAdapter } from "../utils/lagrange-adapter.js"; +import {mid2id} from "../utils/weibo.js"; +import {LagrangeAdapter} from "../utils/lagrange-adapter.js"; import path from "path"; -import { OpenaiBuilder } from "../utils/openai-builder.js"; -import { contentEstimator } from "../utils/link-share-summary-util.js"; +import {OpenaiBuilder} from "../utils/openai-builder.js"; +import {contentEstimator} from "../utils/link-share-summary-util.js"; export class tools extends plugin { /** @@ -104,7 +104,7 @@ export class tools extends plugin { priority: 300, rule: [ { - reg: `^(翻|trans)[${ tools.Constants.existsTransKey }]`, + reg: `^(翻|trans)[${tools.Constants.existsTransKey}]`, fnc: "trans", }, { @@ -194,7 +194,7 @@ export class tools extends plugin { }, { reg: "(qishui.douyin.com)", - fnc: "qishuiMusic" + fnc: "qishuiMusic" } ], }); @@ -205,7 +205,7 @@ export class tools extends plugin { // 魔法接口 this.proxyAddr = this.toolsConfig.proxyAddr; this.proxyPort = this.toolsConfig.proxyPort; - this.myProxy = `http://${ this.proxyAddr }:${ this.proxyPort }`; + this.myProxy = `http://${this.proxyAddr}:${this.proxyPort}`; // 加载哔哩哔哩配置 this.biliSessData = this.toolsConfig.biliSessData; // 加载哔哩哔哩的限制时长 @@ -225,7 +225,7 @@ export class tools extends plugin { proxy: this.myProxy, }); // 并发队列 - this.queue = new PQueue({ concurrency: Number(this.toolsConfig.queueConcurrency) }); + this.queue = new PQueue({concurrency: Number(this.toolsConfig.queueConcurrency)}); // 视频下载的并发数量 this.videoDownloadConcurrency = this.toolsConfig.videoDownloadConcurrency; // ai接口 @@ -262,7 +262,7 @@ export class tools extends plugin { const res = await this.douyinRequest(douUrl); // 当前版本需要填入cookie if (_.isEmpty(this.douyinCookie)) { - e.reply(`检测到没有Cookie,无法解析抖音${ HELP_DOC }`); + e.reply(`检测到没有Cookie,无法解析抖音${HELP_DOC}`); return; } const douId = /note\/(\d+)/g.exec(res)?.[1] || /video\/(\d+)/g.exec(res)?.[1]; @@ -283,8 +283,8 @@ export class tools extends plugin { headers["User-Agent"], ); // const param = resp.data.result[0].paramsencode; - const resDyApi = `${ dyApi }&a_bogus=${ abParam }`; - headers['Referer'] = `https://www.douyin.com/video/${ douId }` + const resDyApi = `${dyApi}&a_bogus=${abParam}`; + headers['Referer'] = `https://www.douyin.com/video/${douId}` // 定义一个dy请求 const dyResponse = () => axios.get(resDyApi, { headers, @@ -301,7 +301,7 @@ export class tools extends plugin { if (urlType === "video") { // logger.info(item.video); // 多位面选择:play_addr、play_addr_265、play_addr_h264 - const { play_addr: { uri: videoAddrURI }, duration, cover } = item.video; + const {play_addr: {uri: videoAddrURI}, duration, cover} = item.video; // 进行时间判断,如果超过时间阈值就不发送 const dyDuration = Math.trunc(duration / 1000); const durationThreshold = this.biliDuration; @@ -309,14 +309,14 @@ export class tools extends plugin { // 超过阈值,不发送的情况 const dyCover = cover.url_list?.pop(); // logger.info(cover.url_list); - e.reply([segment.image(dyCover), `识别:抖音, ${ item.desc }\n - ${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ Math.trunc(dyDuration / 60) }分钟,\n大于管理员设置的最大时长 ${ durationThreshold / 60 } 分钟!`]) + e.reply([segment.image(dyCover), `识别:抖音, ${item.desc}\n + ${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${Math.trunc(dyDuration / 60)}分钟,\n大于管理员设置的最大时长 ${durationThreshold / 60} 分钟!`]) // 如果开启评论的就调用 await this.douyinComment(e, douId, headers); return; } else { // 正常发送 - e.reply(`识别:抖音, ${ item.desc }`); + e.reply(`识别:抖音, ${item.desc}`); } // 分辨率判断是否压缩 const resolution = this.douyinCompression ? "720p" : "1080p"; @@ -336,7 +336,7 @@ export class tools extends plugin { }*/ // logger.info(resUrl); - const path = `${ this.getCurDownloadPath(e) }/temp.mp4`; + const path = `${this.getCurDownloadPath(e)}/temp.mp4`; // 加入队列 this.queue.add(async () => { await this.downloadVideo(resUrl).then(() => { @@ -345,7 +345,7 @@ export class tools extends plugin { }) } else if (urlType === "image") { // 发送描述 - e.reply(`识别:抖音, ${ item.desc }`); + e.reply(`识别:抖音, ${item.desc}`); // 无水印图片列表 let no_watermark_image_list = []; // 有水印图片列表 @@ -368,7 +368,7 @@ export class tools extends plugin { await this.douyinComment(e, douId, headers); } catch (err) { logger.error(err); - logger.mark(`Cookie 过期或者 Cookie 没有填写,请参考\n${ HELP_DOC }\n尝试无效后可以到官方QQ群[575663150]提出 bug 等待解决`) + logger.mark(`Cookie 过期或者 Cookie 没有填写,请参考\n${HELP_DOC}\n尝试无效后可以到官方QQ群[575663150]提出 bug 等待解决`) } return true; } @@ -388,7 +388,7 @@ export class tools extends plugin { new URLSearchParams(new URL(dyCommentUrl).search).toString(), headers["User-Agent"], ); - const commentsResp = await axios.get(`${ dyCommentUrl }&a_bogus=${ abParam }`, { + const commentsResp = await axios.get(`${dyCommentUrl}&a_bogus=${abParam}`, { headers }) // logger.info(headers) @@ -422,10 +422,10 @@ export class tools extends plugin { // 下载逻辑 const path = this.getCurDownloadPath(e); await checkAndRemoveFile(path + "/temp.mp4"); - const title = execSync(`yt-dlp --get-title ${ cleanedTiktokUrl } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`) - e.reply(`识别:TikTok,视频下载中请耐心等待 \n${ title }`); + const title = execSync(`yt-dlp --get-title ${cleanedTiktokUrl} ${isOversea ? "" : `--proxy ${this.myProxy}`}`) + e.reply(`识别:TikTok,视频下载中请耐心等待 \n${title}`); await this.tiktokHelper(path, cleanedTiktokUrl, isOversea); - await this.sendVideoToUpload(e, `${ path }/temp.mp4`); + await this.sendVideoToUpload(e, `${path}/temp.mp4`); return true; } @@ -439,13 +439,13 @@ export class tools extends plugin { */ async tiktokHelper(path, url, isOversea) { return new Promise((resolve, reject) => { - const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ this.myProxy }` } -P ${ path } -o "temp.%(ext)s" ${ url }`; + const command = `yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} -o "temp.%(ext)s" ${url}`; exec(command, (error, stdout) => { if (error) { - console.error(`Error executing command: ${ error }`); + console.error(`Error executing command: ${error}`); reject(error); } else { - console.log(`Command output: ${ stdout }`); + console.log(`Command output: ${stdout}`); resolve(stdout); } }); @@ -454,17 +454,17 @@ export class tools extends plugin { // 哔哩哔哩扫码登录 async biliScan(e) { - e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 }); + e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', {recallMsg: 180}); // 图片发送钩子 const imgSendHook = function (e, path) { - e.reply([segment.image(path), segment.at(e.user_id), '请扫码以完成获取'], { recallMsg: 180 }) + e.reply([segment.image(path), segment.at(e.user_id), '请扫码以完成获取'], {recallMsg: 180}) }; // 检查路径是否存在文件夹 await mkdirIfNotExists(this.defaultPath); // 发送请求 - const saveCodePath = `${ this.defaultPath }qrcode.png`; + const saveCodePath = `${this.defaultPath}qrcode.png`; - const { SESSDATA, refresh_token } = await getScanCodeData(saveCodePath, 8, () => imgSendHook(e, saveCodePath)) + const {SESSDATA, refresh_token} = await getScanCodeData(saveCodePath, 8, () => imgSendHook(e, saveCodePath)) // 更新到配置文件 config.updateField("tools", "biliSessData", SESSDATA); @@ -479,7 +479,7 @@ export class tools extends plugin { let url = e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim().replaceAll("\\", ""); // 直接发送BV号的处理 if (/^BV[1-9a-zA-Z]{10}$/.exec(url)?.[0]) { - url = `https://www.bilibili.com/video/${ url }`; + url = `https://www.bilibili.com/video/${url}`; logger.info(url) } // 短号处理 @@ -511,11 +511,11 @@ export class tools extends plugin { // 提取相关信息 const liveData = await this.getBiliStream(streamId); // logger.info(liveData); - const { title, user_cover, keyframe, description, tags } = liveData.data.data; + const {title, user_cover, keyframe, description, tags} = liveData.data.data; e.reply([ segment.image(user_cover), segment.image(keyframe), - `识别:哔哩哔哩直播,${ title }${ description ? `\n\n简述:${ description }\n` : '' }${ tags ? `标签:${ tags }\n` : '' }` + `识别:哔哩哔哩直播,${title}${description ? `\n\n简述:${description}\n` : ''}${tags ? `标签:${tags}\n` : ''}` ]); return true; } @@ -551,9 +551,9 @@ export class tools extends plugin { // 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB // 请求视频信息 const videoInfo = await getVideoInfo(url); - const { title, pic, desc, duration, dynamic, stat, bvid, aid, cid, owner, pages } = videoInfo; + const {title, pic, desc, duration, dynamic, stat, bvid, aid, cid, owner, pages} = videoInfo; // 视频信息 - let { view, danmaku, reply, favorite, coin, share, like } = stat; + let {view, danmaku, reply, favorite, coin, share, like} = stat; // 限制时长 & 考虑分页视频情况 const query = querystring.parse(url); const curPage = query?.p || 0; @@ -572,8 +572,8 @@ export class tools extends plugin { // 过滤简介中的一些链接 const filteredDesc = await filterBiliDescLink(desc); // 格式化数据 - const combineContent = `\n${ formatBiliInfo(dataProcessMap) }\n简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`; - let biliInfo = [`识别:哔哩哔哩:${ title }`, combineContent] + const combineContent = `\n${formatBiliInfo(dataProcessMap)}\n简介:${truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT)}`; + let biliInfo = [`识别:哔哩哔哩:${title}`, combineContent] // 总结 const summary = await this.getBiliSummary(bvid, cid, owner.mid); // 不提取音乐,正常处理 @@ -582,26 +582,26 @@ export class tools extends plugin { biliInfo.unshift(segment.image(pic)) // 限制视频解析 const durationInMinutes = (curDuration / 60).toFixed(0); - biliInfo.push(`${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ durationInMinutes }分钟,\n大于管理员设置的最大时长 ${ this.biliDuration / 60 } 分钟!`) - summary && biliInfo.push(`\n${ summary }`); + biliInfo.push(`${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${durationInMinutes}分钟,\n大于管理员设置的最大时长 ${this.biliDuration / 60} 分钟!`) + summary && biliInfo.push(`\n${summary}`); e.reply(biliInfo); return true; } else { - summary && biliInfo.push(`\n${ summary }`); + summary && biliInfo.push(`\n${summary}`); e.reply(biliInfo); } // 创建文件,如果不存在 - const path = `${ this.getCurDownloadPath(e) }/`; + const path = `${this.getCurDownloadPath(e)}/`; await mkdirIfNotExists(path); // 加入队列 this.queue.add(async () => { // 下载文件 getDownloadUrl(url) .then(data => { - this.downBili(`${ path }temp`, data.videoUrl, data.audioUrl) + this.downBili(`${path}temp`, data.videoUrl, data.audioUrl) .then(_ => { - this.sendVideoToUpload(e, `${ path }temp.mp4`) + this.sendVideoToUpload(e, `${path}temp.mp4`) }) .catch(err => { logger.error(err); @@ -631,31 +631,31 @@ export class tools extends plugin { const isLimitDuration = curDuration > this.biliDuration; if (isLimitDuration) { const durationInMinutes = (curDuration / 60).toFixed(0); - e.reply(`当前视频(${ videoId })时长为 ${ durationInMinutes } 分钟,大于管理员设置的时长 ${ this.biliDuration / 60 } 分钟`); + e.reply(`当前视频(${videoId})时长为 ${durationInMinutes} 分钟,大于管理员设置的时长 ${this.biliDuration / 60} 分钟`); return true; } // 获取关键信息 - const { video, audio } = dash; + 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 {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) + that.downBili(`${path}temp`, videoBaseUrl, audioBaseUrl) .then(_ => { - that.sendVideoToUpload(e, `${ path }temp.mp4`); + that.sendVideoToUpload(e, `${path}temp.mp4`); }) .catch(err => { - logger.error(`[R插件][B站下载引擎] ${ err }`); + logger.error(`[R插件][B站下载引擎] ${err}`); e.reply("解析失败,请重试一下"); }) ); - logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${ this.queue.size }`); + logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${this.queue.size}`); return true; } @@ -685,7 +685,7 @@ export class tools extends plugin { const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0]; getDynamic(dynamicId, session).then(async resp => { if (resp.dynamicSrc.length > 0) { - e.reply(`识别:哔哩哔哩动态, ${ resp.dynamicDesc }`); + e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`); let dynamicSrcMsg = []; resp.dynamicSrc.forEach(item => { dynamicSrcMsg.push({ @@ -715,10 +715,10 @@ export class tools extends plugin { // 这个有点用,但不多 let wbi = "wts=1701546363&w_rid=1073871926b3ccd99bd790f0162af634" if (!_.isEmpty(this.biliSessData)) { - wbi = await getWbi({ bvid, cid, up_mid }, this.biliSessData); + wbi = await getWbi({bvid, cid, up_mid}, this.biliSessData); } // 构造API - const summaryUrl = `${ BILI_SUMMARY }?${ wbi }`; + const summaryUrl = `${BILI_SUMMARY}?${wbi}`; logger.info(summaryUrl) // 构造结果:https://api.bilibili.com/x/web-interface/view/conclusion/get?bvid=BV1L94y1H7CV&cid=1335073288&up_mid=297242063&wts=1701546363&w_rid=1073871926b3ccd99bd790f0162af634 return axios.get(summaryUrl) @@ -730,7 +730,7 @@ export class tools extends plugin { let resReply = ""; // 总体总结 if (summary) { - resReply = `\n摘要:${ summary }\n` + resReply = `\n摘要:${summary}\n` } // 分段总结 if (outline) { @@ -739,11 +739,11 @@ export class tools extends plugin { const keyPoint = item?.part_outline; // 时间点的总结 const specificContent = keyPoint.map(point => { - const { timestamp, content } = point + const {timestamp, content} = point const specificTime = secondsToTime(timestamp) - return `${ specificTime } ${ content }\n`; + return `${specificTime} ${content}\n`; }).join(""); - return `- ${ smallTitle }\n${ specificContent }\n`; + return `- ${smallTitle}\n${specificContent}\n`; }); resReply += specificTimeSummary.join(""); } @@ -757,7 +757,7 @@ export class tools extends plugin { * @returns {Promise<*>} */ async getBiliStream(liveId) { - return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, { + return axios.get(`${BILI_STREAM_INFO}?room_id=${liveId}`, { headers: { 'User-Agent': COMMON_USER_AGENT, } @@ -783,14 +783,14 @@ export class tools extends plugin { await fetch(TWITTER_TWEET_INFO.replace("{}", id), { headers: { "User-Agent": "v2TweetLookupJS", - "authorization": `Bearer ${ Buffer.from(TWITTER_BEARER_TOKEN, "base64").toString() }` + "authorization": `Bearer ${Buffer.from(TWITTER_BEARER_TOKEN, "base64").toString()}` }, ...params, agent: !isOversea ? '' : new HttpsProxyAgent(this.myProxy), }).then(async resp => { logger.info(resp) - e.reply(`识别:小蓝鸟学习版,${ resp.data.text }`); - const downloadPath = `${ this.getCurDownloadPath(e) }`; + e.reply(`识别:小蓝鸟学习版,${resp.data.text}`); + const downloadPath = `${this.getCurDownloadPath(e)}`; // 创建文件夹(如果没有过这个群) if (!fs.existsSync(downloadPath)) { mkdirsSync(downloadPath); @@ -805,7 +805,7 @@ export class tools extends plugin { // 视频 await this.downloadVideo(resp.includes.media[0].variants[0].url, true).then( _ => { - e.reply(segment.video(`${ downloadPath }/temp.mp4`)); + e.reply(segment.video(`${downloadPath}/temp.mp4`)); }, ); } @@ -898,21 +898,21 @@ export class tools extends plugin { // acfun解析 async acfun(e) { - const path = `${ this.getCurDownloadPath(e) }/temp/`; + const path = `${this.getCurDownloadPath(e)}/temp/`; await mkdirIfNotExists(path); let inputMsg = e.msg; // 适配手机分享:https://m.acfun.cn/v/?ac=32838812&sid=d2b0991bd6ad9c09 if (inputMsg.includes("m.acfun.cn")) { - inputMsg = `https://www.acfun.cn/v/ac${ /ac=([^&?]*)/.exec(inputMsg)[1] }`; + inputMsg = `https://www.acfun.cn/v/ac${/ac=([^&?]*)/.exec(inputMsg)[1]}`; } parseUrl(inputMsg).then(res => { - e.reply(`识别:猴山,${ res.videoName }`); + e.reply(`识别:猴山,${res.videoName}`); parseM3u8(res.urlM3u8s[res.urlM3u8s.length - 1]).then(res2 => { downloadM3u8Videos(res2.m3u8FullUrls, path).then(_ => { - mergeAcFileToMp4(res2.tsNames, path, `${ path }out.mp4`).then(_ => { - this.sendVideoToUpload(e, `${ path }out.mp4`) + mergeAcFileToMp4(res2.tsNames, path, `${path}out.mp4`).then(_ => { + this.sendVideoToUpload(e, `${path}out.mp4`) }); }); }); @@ -948,11 +948,16 @@ export class tools extends plugin { } else { id = /explore\/(\w+)/.exec(msgUrl)?.[1] || /discovery\/item\/(\w+)/.exec(msgUrl)?.[1]; } - const downloadPath = `${ this.getCurDownloadPath(e) }`; + const downloadPath = `${this.getCurDownloadPath(e)}`; + // 检测没有 cookie 则退出 + if (_.isEmpty(this.xiaohongshuCookie)) { + e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck,文档:${HELP_DOC}`); + return; + } // 注入ck XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie; // 获取信息 - fetch(`${ XHS_REQ_LINK }${ id }`, { + fetch(`${XHS_REQ_LINK}${id}`, { headers: XHS_NO_WATERMARK_HEADER, }).then(async resp => { const xhsHtml = await resp.text(); @@ -960,25 +965,25 @@ export class tools extends plugin { const res = xhsHtml.match(reg)[1].replace(/undefined/g, "null"); const resJson = JSON.parse(res); const noteData = resJson.note.noteDetailMap[id].note; - const { title, desc, type } = noteData; + const {title, desc, type} = noteData; let imgPromise = []; if (type === "video") { // 封面 const cover = noteData.imageList?.[0].urlDefault; - e.reply([segment.image(cover), `识别:小红书, ${ title }\n${ desc }`]); + e.reply([segment.image(cover), `识别:小红书, ${title}\n${desc}`]); // 构造xhs视频链接 const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl; // 下载视频 this.downloadVideo(xhsVideoUrl).then(path => { if (path === undefined) { // 创建文件,如果不存在 - path = `${ this.getCurDownloadPath(e) }/`; + path = `${this.getCurDownloadPath(e)}/`; } - this.sendVideoToUpload(e, `${ path }/temp.mp4`) + this.sendVideoToUpload(e, `${path}/temp.mp4`) }); return true; } else if (type === "normal") { - e.reply(`识别:小红书, ${ title }\n${ desc }`); + e.reply(`识别:小红书, ${title}\n${desc}`); noteData.imageList.map(async (item, index) => { imgPromise.push(downloadImg(item.urlDefault, downloadPath, index.toString())); }); @@ -1010,10 +1015,10 @@ export class tools extends plugin { if (suffix.startsWith("reel")) { suffix = suffix.replace("reel/", "p/"); } - const API = `https://imginn.com/${ suffix }`; + const API = `https://imginn.com/${suffix}`; // logger.info(API); let imgPromise = []; - const downloadPath = `${ this.getCurDownloadPath(e) }`; + const downloadPath = `${this.getCurDownloadPath(e)}`; // 判断是否是海外服务器 const isOversea = await this.isOverseasServer(); // 简单封装图片下载 @@ -1042,13 +1047,13 @@ export class tools extends plugin { const desc = html.match(/(?<=content=").*?(?=\")/g)?.[2]; const images = html.match(/