From 49711921c5c4686428bc3a8e6d72130dd53252a8 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Mon, 5 Aug 2024 19:02:53 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D=20`xhs?= =?UTF-8?q?`=20=E4=B8=8B=E8=BD=BD=E6=98=AF=E6=9C=89=E6=B0=B4=E5=8D=B0=20&?= =?UTF-8?q?=20=E7=AE=80=E5=8C=96=E5=87=BD=E6=95=B0`saveJsonToFile`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 13 ++++++++----- utils/common.js | 10 ++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index e74cb92..e203b82 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -43,7 +43,7 @@ import { downloadImg, estimateReadingTime, formatBiliInfo, - retryAxiosReq, + retryAxiosReq, saveJsonToFile, secondsToTime, testProxy, truncateString @@ -962,6 +962,8 @@ export class tools extends plugin { || /(http:|https:)\/\/www\.xiaohongshu\.com\/explore\/(\w+)/.exec( e.msg, )?.[0] + // 注入ck + XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie; // 解析短号 let id; if (msgUrl.includes("xhslink")) { @@ -984,8 +986,6 @@ export class tools extends plugin { e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck\n文档:${HELP_DOC}`); return; } - // 注入ck - XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie; // 获取信息 fetch(`${XHS_REQ_LINK}${id}`, { headers: XHS_NO_WATERMARK_HEADER, @@ -1001,8 +1001,11 @@ export class tools extends plugin { // 封面 const cover = noteData.imageList?.[0].urlDefault; e.reply([segment.image(cover), `识别:小红书, ${title}\n${desc}`]); - // 构造xhs视频链接 - const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl; + // ⚠️ (暂时废弃)构造xhs视频链接(有水印) + // const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl; + + // 构造无水印 + const xhsVideoUrl = `http://sns-video-bd.xhscdn.com/${noteData.video.consumer.originVideoKey}` // 下载视频 this.downloadVideo(xhsVideoUrl).then(path => { if (path === undefined) { diff --git a/utils/common.js b/utils/common.js index cadf7af..6abf56d 100644 --- a/utils/common.js +++ b/utils/common.js @@ -435,18 +435,16 @@ export function checkCommandExists(command) { * @param {string} filename - 目标文件名 * @param {function} callback - 可选的回调函数,处理写入完成后的操作 */ -export function saveJsonToFile(jsonData, filename, callback) { +export function saveJsonToFile(jsonData, filename = "data.json") { // 转换 JSON 数据为字符串 const jsonString = JSON.stringify(jsonData, null, 2); // 第二个参数是 replacer,第三个参数是缩进 // 保存到文件 - fs.writeFile(filename, jsonString, 'utf8', (err) => { + return fs.writeFile(filename, jsonString, 'utf8', (err) => { if (err) { - console.error('Error writing file', err); - if (callback) callback(err); + logger.error('Error writing file', err); } else { - console.log('File successfully written'); - if (callback) callback(null); + logger.info('File successfully written'); } }); }