mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🐞 fix: 修复 xhs
下载是有水印 & 简化函数saveJsonToFile
This commit is contained in:
parent
90f64e796d
commit
49711921c5
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user