diff --git a/apps/tools.js b/apps/tools.js index cd962e8..651196c 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -301,7 +301,7 @@ export class tools extends plugin { let url = e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim(); // 短号处理 if (url.includes("b23.tv")) { - const bShortUrl = bShortRex.exec(url)[0]; + const bShortUrl = bShortRex.exec(url)?.[0]; await fetch(bShortUrl, { method: "HEAD" }).then(resp => { @@ -784,7 +784,55 @@ export class tools extends plugin { * @return {Promise} */ async kuaishou(e) { + // 例子:https://www.kuaishou.com/short-video/3xkfs8p4pnd67p4?authorId=3xkznsztpwetngu&streamSource=find&area=homexxbrilliant + // https://v.m.chenzhongtech.com/fw/photo/3xburnkmj3auazc + const msg = e.msg; + let video_id; + if (msg.includes('/fw/photo/')) { + video_id = msg.match(/\/fw\/photo\/([^/?]+)/)[1]; + } else if (msg.includes("short-video")) { + video_id = msg.match(/short-video\/([^/?]+)/)[1]; + } else { + e.reply("无法提取快手的信息,请重试或者换一个视频!") + return + } + // 提取视频 + const videoUrl = `https://www.kuaishou.com/short-video/${video_id}`; + // 发送GET请求 + const response = await axios.get(videoUrl, { + 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-Language': 'zh-CN,zh;q=0.9', + 'Cache-Control': 'no-cache', + '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', + 'Sec-Fetch-Dest': 'document', + 'Sec-Fetch-Mode': 'navigate', + 'Sec-Fetch-Site': 'none', + 'Sec-Fetch-User': '?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', + '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 // 设置超时时间 + }); + + // 使用正则表达式提取视频数据 + const videoDataMatch = response.data.match(/"photoH265Url":"(.*?)"/); + 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")); + }); } /** diff --git a/config/help.yaml b/config/help.yaml index 98d5e3e..9f3188e 100644 --- a/config/help.yaml +++ b/config/help.yaml @@ -47,12 +47,12 @@ - icon: redbook title: "小红书" desc: 小红书分享实时下载 + - icon: kuaishou + title: "快手(测试阶段)" + desc: 快手分享实时下载 - icon: literature title: "论文" desc: SCI论文实时解析 - - icon: netease - title: "网易云音乐" - desc: 网易云音乐解析 - icon: bodian title: "波点音乐" desc: 波点云音乐点解析 diff --git a/config/version.yaml b/config/version.yaml index a5dc360..c5fbb65 100644 --- a/config/version.yaml +++ b/config/version.yaml @@ -1,9 +1,9 @@ - { - version: 1.1.1, + version: 1.1.2, data: [ + 新增快手解析功能, 新增竹白百科功能, - 新增Instagram解析功能, 重构翻译功能, 适配锅巴插件,方便查看和修改配置, 添加#R帮助获取插件帮助, diff --git a/resources/img/icon/kuaishou.png b/resources/img/icon/kuaishou.png new file mode 100644 index 0000000..0809d93 Binary files /dev/null and b/resources/img/icon/kuaishou.png differ