🐞 fix: V1.3.4 修复ks视频无法解析短链接的问题

1. 修复ks“https://v.kuaishou.com/1ff8QP”的链接无法解析问题,感谢群友《下次一定》提供
This commit is contained in:
zhiyu 2024-02-10 00:55:02 +08:00
parent 057cb842ac
commit 344e7ce846

View File

@ -877,7 +877,19 @@ export class tools extends plugin {
async kuaishou(e) { async kuaishou(e) {
// 例子https://www.kuaishou.com/short-video/3xkfs8p4pnd67p4?authorId=3xkznsztpwetngu&streamSource=find&area=homexxbrilliant // 例子https://www.kuaishou.com/short-video/3xkfs8p4pnd67p4?authorId=3xkznsztpwetngu&streamSource=find&area=homexxbrilliant
// https://v.m.chenzhongtech.com/fw/photo/3xburnkmj3auazc // https://v.m.chenzhongtech.com/fw/photo/3xburnkmj3auazc
const msg = e.msg; // https://v.kuaishou.com/1ff8QP
let msg = /(?:https?:\/\/)?(www|v)\.kuaishou\.com\/[A-Za-z\d._?%&+\-=\/#]*/g.exec(e.msg)[0];
// 跳转短号
if (msg.includes("v.kuaishou")) {
await fetch(msg, {
headers: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
}
}).then(resp => {
msg = resp.url;
})
}
logger.info(msg)
let video_id; let video_id;
if (msg.includes('/fw/photo/')) { if (msg.includes('/fw/photo/')) {
video_id = msg.match(/\/fw\/photo\/([^/?]+)/)[1]; video_id = msg.match(/\/fw\/photo\/([^/?]+)/)[1];
@ -888,16 +900,16 @@ export class tools extends plugin {
return return
} }
// 提取视频 // 提取视频
const videoUrl = `https://www.kuaishou.com/short-video/${ video_id }`; const videoUrl = XIGUA_REQ_LINK.replace("{}", `https://www.kuaishou.com/short-video/${ video_id }`);
e.reply("识别:快手");
// 发送GET请求 // 发送GET请求
const response = await axios.get(videoUrl, { axios.get(videoUrl, {
headers: { headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Language': 'zh-CN,zh;q=0.9', 'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache', 'Cache-Control': 'no-cache',
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Cookie': 'kpf=PC_WEB; clientid=3; did=web_c5627223fe1e796669894e6cb74f1461; _ga=GA1.1.1139357938.1696318390; didv=1696329758000; _ga_0P9YPW1GQ3=GS1.1.1696659232.14.0.1696659232.0.0.0; kpn=KUAISHOU_VISION',
'Pragma': 'no-cache', 'Pragma': 'no-cache',
'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Mode': 'navigate',
@ -905,24 +917,14 @@ export class tools extends plugin {
'Sec-Fetch-User': '?1', 'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1', 'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
'sec-ch-ua': '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
}, },
timeout: 10000 // 设置超时时间 timeout: 10000 // 设置超时时间
}); }).then(resp => {
const url = resp.data.data.url;
// 使用正则表达式提取视频数据 this.downloadVideo(url).then(path => {
const videoDataMatch = response.data.match(/"photoH265Url":"(.*?)"/); e.reply(segment.video(path + "/temp.mp4"));
let videoData = videoDataMatch ? videoDataMatch[1] : null; });
if (!videoData) {
e.reply("快手解析失败,可能原因:解析太多暂时失效,过一段时间再解析!");
return;
}
e.reply("识别:快手")
videoData = decodeURIComponent(videoData).replace(/\\u002F/g, '/');
this.downloadVideo(videoData).then(path => {
e.reply(segment.video(path + "/temp.mp4"));
}); });
} }
@ -1029,6 +1031,7 @@ export class tools extends plugin {
// 2. https://www.ixigua.com/7270448082586698281 // 2. https://www.ixigua.com/7270448082586698281
// 3. https://m.ixigua.com/video/7270448082586698281 // 3. https://m.ixigua.com/video/7270448082586698281
const msg = /(?:https?:\/\/)?(www|v|m)\.ixigua\.com\/[A-Za-z\d._?%&+\-=\/#]*/g.exec(e.msg)[0]; const msg = /(?:https?:\/\/)?(www|v|m)\.ixigua\.com\/[A-Za-z\d._?%&+\-=\/#]*/g.exec(e.msg)[0];
e.reply("识别:🍉视频");
const id = /ixigua\.com\/(\d+)/.exec(msg)[1] || /\/video\/(\d+)/.exec(msg)[1]; const id = /ixigua\.com\/(\d+)/.exec(msg)[1] || /\/video\/(\d+)/.exec(msg)[1];
const videoReq = `https://www.ixigua.com/${ id }`; const videoReq = `https://www.ixigua.com/${ id }`;