mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: xhs解析视频 & xhs解析速度提升
This commit is contained in:
parent
251c382d2b
commit
3ae7c26a3b
@ -12,7 +12,7 @@ import HttpProxyAgent from "https-proxy-agent";
|
|||||||
import { mkdirsSync } from "../utils/file.js";
|
import { mkdirsSync } from "../utils/file.js";
|
||||||
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js";
|
||||||
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
|
||||||
import { transMap, douyinTypeMap, TEN_THOUSAND } from "../utils/constant.js";
|
import { transMap, douyinTypeMap, TEN_THOUSAND, XHS_CK } from "../utils/constant.js";
|
||||||
import { getIdVideo, generateRandomStr } from "../utils/common.js";
|
import { getIdVideo, generateRandomStr } from "../utils/common.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
|
|
||||||
@ -535,53 +535,50 @@ export class tools extends plugin {
|
|||||||
|
|
||||||
// 小红书解析
|
// 小红书解析
|
||||||
async redbook(e) {
|
async redbook(e) {
|
||||||
|
// 解析短号
|
||||||
const msgUrl = /(http:|https:)\/\/(xhslink|xiaohongshu).com\/[A-Za-z\d._?%&+\-=\/#@]*/.exec(
|
const msgUrl = /(http:|https:)\/\/(xhslink|xiaohongshu).com\/[A-Za-z\d._?%&+\-=\/#@]*/.exec(
|
||||||
e.msg,
|
e.msg,
|
||||||
)[0];
|
)[0];
|
||||||
const url = `https://dlpanda.com/zh-CN/xhs?url=${msgUrl}`;
|
let id;
|
||||||
|
if (msgUrl.includes('xhslink')) {
|
||||||
await axios
|
await fetch(msgUrl, {
|
||||||
.get(url, {
|
redirect: 'follow',
|
||||||
headers: {
|
}).then(resp => {
|
||||||
"User-Agent":
|
const uri = decodeURIComponent(resp.url)
|
||||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
id = /explore\/(\w+)/.exec(uri)[1];
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Accept-Encoding": "gzip,deflate,compress",
|
|
||||||
},
|
|
||||||
timeout: 10000,
|
|
||||||
proxy: false,
|
|
||||||
})
|
})
|
||||||
.then(async resp => {
|
} else {
|
||||||
const reg = /<img(.*)src="\/\/ci\.xiaohongshu\.com(.*?)"/g;
|
id = /explore\/(\w+)/.exec(msgUrl)[1];
|
||||||
|
|
||||||
const downloadPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
|
|
||||||
// 创建文件夹(如果没有过这个群)
|
|
||||||
if (!fs.existsSync(downloadPath)) {
|
|
||||||
mkdirsSync(downloadPath);
|
|
||||||
}
|
}
|
||||||
const res = resp.data.match(reg);
|
const downloadPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
|
||||||
const imagesPath = res.map(item => {
|
// 获取信息
|
||||||
const addr = `https:${item.split('"')[3]}`;
|
fetch(`https://www.xiaohongshu.com/discovery/item/${id}`, {
|
||||||
return axios
|
|
||||||
.get(addr, {
|
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent":
|
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1 Edg/110.0.0.0",
|
||||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
"cookie": Buffer.from(XHS_CK, 'base64').toString('utf-8')
|
||||||
},
|
}
|
||||||
responseType: "stream",
|
}).then(async resp => {
|
||||||
|
const xhsHtml = await resp.text();
|
||||||
|
const reg = /window.__INITIAL_STATE__=(.*?)<\/script>/
|
||||||
|
const resJson = xhsHtml.match(reg)[0]
|
||||||
|
const res = JSON.parse(resJson.match(reg)[1]);
|
||||||
|
const noteData = res.noteData.data.noteData
|
||||||
|
const { title, desc, type } = noteData
|
||||||
|
e.reply(`识别:小红书, ${title}\n${desc}`)
|
||||||
|
let imgPromise = []
|
||||||
|
if (type === 'video') {
|
||||||
|
const url = noteData.video.url;
|
||||||
|
this.downloadVideo(url).then(path => {
|
||||||
|
e.reply(segment.video(path + "/temp.mp4"));
|
||||||
})
|
})
|
||||||
.then(resp => {
|
return true;
|
||||||
const filepath = `${downloadPath}/${/com\/(.*)\?/.exec(addr)[1]}.jpg`;
|
} else if (type === 'normal') {
|
||||||
const writer = fs.createWriteStream(filepath);
|
noteData.imageList.map (async (item, index) => {
|
||||||
resp.data.pipe(writer);
|
imgPromise.push(this.downloadImg(item.url, downloadPath, index.toString()))
|
||||||
return new Promise((resolve, reject) => {
|
})
|
||||||
writer.on("finish", () => resolve(filepath));
|
}
|
||||||
writer.on("error", reject);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
let path = [];
|
let path = [];
|
||||||
const images = await Promise.all(imagesPath).then(paths => {
|
const images = await Promise.all(imgPromise).then(paths => {
|
||||||
return paths.map(item => {
|
return paths.map(item => {
|
||||||
path.push(item);
|
path.push(item);
|
||||||
return {
|
return {
|
||||||
@ -596,8 +593,7 @@ export class tools extends plugin {
|
|||||||
path.forEach(item => {
|
path.forEach(item => {
|
||||||
fs.unlinkSync(item);
|
fs.unlinkSync(item);
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,11 +739,14 @@ export class tools extends plugin {
|
|||||||
* 下载一张网络图片(自动以url的最后一个为名字)
|
* 下载一张网络图片(自动以url的最后一个为名字)
|
||||||
* @param img
|
* @param img
|
||||||
* @param dir
|
* @param dir
|
||||||
|
* @param fileName
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
async downloadImg(img, dir) {
|
async downloadImg(img, dir, fileName='') {
|
||||||
const filename = img.split("/").pop();
|
if (fileName === "") {
|
||||||
const filepath = `${dir}/${filename}`;
|
fileName = img.split("/").pop();
|
||||||
|
}
|
||||||
|
const filepath = `${dir}/${fileName}`;
|
||||||
const writer = fs.createWriteStream(filepath);
|
const writer = fs.createWriteStream(filepath);
|
||||||
return axios
|
return axios
|
||||||
.get(img, {
|
.get(img, {
|
||||||
|
@ -25,3 +25,5 @@ export const douyinTypeMap = {
|
|||||||
export const TEN_THOUSAND = 10000;
|
export const TEN_THOUSAND = 10000;
|
||||||
|
|
||||||
export const CAT_LIMIT = 10;
|
export const CAT_LIMIT = 10;
|
||||||
|
|
||||||
|
export const XHS_CK = 'eGhzVHJhY2tlcklkPTczODhhYmY2LTI0MDgtNGU5YS04MTUyLTE0MGVhOGY1MTQ5ZjsgeGhzVHJhY2tlcklkLnNpZz1UcGUxTkNaX3B3UkFYdG01SVJmVEs0SWUxM0xBaGZuNmNZU2N4Vi1JYWxFOyBhMT0xODY2ZDkwMDM0NmI2NmppcjMzcGpxZ2MwM3JvcG1mczAydXMxdWNoeDEwMDAwMTM1MDUzOyB3ZWJJZD1mMTNkOGJkYjhiZGM3ZGE0MzY0NjA4NWJjYzQ1MDQ1YTsgZ2lkPXlZS0tmajg4SzA4MnlZS0tmajg4cUo3UzRLREtLVjNGcXFVVjd4Q0FrUzhxRk15OGxVNmlNeTg4OHlxMjgycThmMlk0UzAySjsgZ2lkLnNpZ249YlpzcFFzSUxEUmN5akZLQmN2L1FMWVhkU3lvPTsgd2ViX3Nlc3Npb249MDMwMDM3YTRjMDQyYjE1ZTVjMTg4OTUwOGIyNDRhZDExM2UwNTM7IHhoc1RyYWNrZXI9dXJsPW5vdGVEZXRhaWwmeGhzc2hhcmU9V2VpeGluU2Vzc2lvbjsg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