mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: 修复 xhs
下载是有水印 & 简化函数saveJsonToFile
This commit is contained in:
parent
90f64e796d
commit
49711921c5
@ -43,7 +43,7 @@ import {
|
|||||||
downloadImg,
|
downloadImg,
|
||||||
estimateReadingTime,
|
estimateReadingTime,
|
||||||
formatBiliInfo,
|
formatBiliInfo,
|
||||||
retryAxiosReq,
|
retryAxiosReq, saveJsonToFile,
|
||||||
secondsToTime,
|
secondsToTime,
|
||||||
testProxy,
|
testProxy,
|
||||||
truncateString
|
truncateString
|
||||||
@ -962,6 +962,8 @@ export class tools extends plugin {
|
|||||||
|| /(http:|https:)\/\/www\.xiaohongshu\.com\/explore\/(\w+)/.exec(
|
|| /(http:|https:)\/\/www\.xiaohongshu\.com\/explore\/(\w+)/.exec(
|
||||||
e.msg,
|
e.msg,
|
||||||
)?.[0]
|
)?.[0]
|
||||||
|
// 注入ck
|
||||||
|
XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie;
|
||||||
// 解析短号
|
// 解析短号
|
||||||
let id;
|
let id;
|
||||||
if (msgUrl.includes("xhslink")) {
|
if (msgUrl.includes("xhslink")) {
|
||||||
@ -984,8 +986,6 @@ export class tools extends plugin {
|
|||||||
e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck\n文档:${HELP_DOC}`);
|
e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck\n文档:${HELP_DOC}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 注入ck
|
|
||||||
XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie;
|
|
||||||
// 获取信息
|
// 获取信息
|
||||||
fetch(`${XHS_REQ_LINK}${id}`, {
|
fetch(`${XHS_REQ_LINK}${id}`, {
|
||||||
headers: XHS_NO_WATERMARK_HEADER,
|
headers: XHS_NO_WATERMARK_HEADER,
|
||||||
@ -1001,8 +1001,11 @@ export class tools extends plugin {
|
|||||||
// 封面
|
// 封面
|
||||||
const cover = noteData.imageList?.[0].urlDefault;
|
const cover = noteData.imageList?.[0].urlDefault;
|
||||||
e.reply([segment.image(cover), `识别:小红书, ${title}\n${desc}`]);
|
e.reply([segment.image(cover), `识别:小红书, ${title}\n${desc}`]);
|
||||||
// 构造xhs视频链接
|
// ⚠️ (暂时废弃)构造xhs视频链接(有水印)
|
||||||
const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl;
|
// 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 => {
|
this.downloadVideo(xhsVideoUrl).then(path => {
|
||||||
if (path === undefined) {
|
if (path === undefined) {
|
||||||
|
@ -435,18 +435,16 @@ export function checkCommandExists(command) {
|
|||||||
* @param {string} filename - 目标文件名
|
* @param {string} filename - 目标文件名
|
||||||
* @param {function} callback - 可选的回调函数,处理写入完成后的操作
|
* @param {function} callback - 可选的回调函数,处理写入完成后的操作
|
||||||
*/
|
*/
|
||||||
export function saveJsonToFile(jsonData, filename, callback) {
|
export function saveJsonToFile(jsonData, filename = "data.json") {
|
||||||
// 转换 JSON 数据为字符串
|
// 转换 JSON 数据为字符串
|
||||||
const jsonString = JSON.stringify(jsonData, null, 2); // 第二个参数是 replacer,第三个参数是缩进
|
const jsonString = JSON.stringify(jsonData, null, 2); // 第二个参数是 replacer,第三个参数是缩进
|
||||||
|
|
||||||
// 保存到文件
|
// 保存到文件
|
||||||
fs.writeFile(filename, jsonString, 'utf8', (err) => {
|
return fs.writeFile(filename, jsonString, 'utf8', (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error writing file', err);
|
logger.error('Error writing file', err);
|
||||||
if (callback) callback(err);
|
|
||||||
} else {
|
} else {
|
||||||
console.log('File successfully written');
|
logger.info('File successfully written');
|
||||||
if (callback) callback(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user