From fb57635f4ce0a3c8bf69b4b4f68314a89219beaf Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Sun, 3 Mar 2024 11:15:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20V1.5.3=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dmiyoushe=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98=20&=20wei?= =?UTF-8?q?bo=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复weibo解析中部分视频无法解析的问题(🌸感谢Mix群友在群里提供测试样例和问题) 2. 修复miyoushe中无法解析部分视频的问题(🌸感谢群友湘潭在群里提供测试样例和问题) --- apps/tools.js | 31 ++++++++++++++++++++++--------- config/version.yaml | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index a84f507..0e4b838 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -965,7 +965,7 @@ export class tools extends plugin { if (pics) { // 图片 const images = pics.map(item => ({ - message: segment.image(item.url), + message: segment.image(item?.large.url || item.url), nickname: e.sender.card || e.user_id, user_id: e.user_id, })); @@ -975,7 +975,12 @@ export class tools extends plugin { // 视频 const videoUrl = page_info.urls?.mp4_720p_mp4 || page_info.urls?.mp4_hd_mp4; try { - this.downloadVideo(videoUrl).then(path => { + this.downloadVideo(videoUrl, false, { + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36", + "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.9", + "referer": "https://weibo.com/", + }).then(path => { e.reply(segment.video(path + "/temp.mp4")); }); } catch (err) { @@ -1153,9 +1158,18 @@ export class tools extends plugin { } }).then(async resp => { const respJson = await resp.json(); + // debug专用 + // fs.writeFile('data.json', JSON.stringify(respJson), (err) => { + // if (err) { + // console.error('Error writing file:', err); + // } else { + // console.log('JSON saved to file successfully.'); + // } + // }); + // return; const data = respJson.data.post.post; // 分别获取:封面、主题、内容、图片 - const { cover, subject, content, images, structured_content } = data; + const { cover, subject, content, images } = data; let realContent = ""; // safe JSON.parse try { @@ -1178,15 +1192,14 @@ export class tools extends plugin { e.reply(Bot.makeForwardMsg(replyImages)); } // 视频 - const sc = JSON.parse(structured_content); - logger.info(sc.length) - if (sc?.[0]?.insert.vod.resolutions) { + let vod_list = respJson.data.post?.vod_list; + if (vod_list.length > 0) { + const resolutions = vod_list?.[0]?.resolutions; // 逐个遍历是否包含url - for (let i = 0; i < sc.length; i++) { - const resolutions = sc?.[i]?.insert.vod.resolutions; + for (let i = 0; i < resolutions.length; i++) { if (resolutions) { // 暂时选取分辨率较低的video进行解析 - const videoUrl = resolutions[0].url; + const videoUrl = resolutions[i].url; this.downloadVideo(videoUrl).then(path => { e.reply(segment.video(path + "/temp.mp4")); }); diff --git a/config/version.yaml b/config/version.yaml index 8906adf..5560b65 100644 --- a/config/version.yaml +++ b/config/version.yaml @@ -1,5 +1,5 @@ - { - version: 1.5.2, + version: 1.5.3, data: [ 新增微博解析功能,