🐞 fix: V1.5.3 修复miyoushe解析问题 & weibo解析问题

1. 修复weibo解析中部分视频无法解析的问题(🌸感谢Mix群友在群里提供测试样例和问题)
2. 修复miyoushe中无法解析部分视频的问题(🌸感谢群友湘潭在群里提供测试样例和问题)
This commit is contained in:
zhiyu1998 2024-03-03 11:15:10 +08:00
parent c123d68537
commit fb57635f4c
2 changed files with 23 additions and 10 deletions

View File

@ -965,7 +965,7 @@ export class tools extends plugin {
if (pics) { if (pics) {
// 图片 // 图片
const images = pics.map(item => ({ 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, nickname: e.sender.card || e.user_id,
user_id: 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; const videoUrl = page_info.urls?.mp4_720p_mp4 || page_info.urls?.mp4_hd_mp4;
try { 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")); e.reply(segment.video(path + "/temp.mp4"));
}); });
} catch (err) { } catch (err) {
@ -1153,9 +1158,18 @@ export class tools extends plugin {
} }
}).then(async resp => { }).then(async resp => {
const respJson = await resp.json(); 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 data = respJson.data.post.post;
// 分别获取:封面、主题、内容、图片 // 分别获取:封面、主题、内容、图片
const { cover, subject, content, images, structured_content } = data; const { cover, subject, content, images } = data;
let realContent = ""; let realContent = "";
// safe JSON.parse // safe JSON.parse
try { try {
@ -1178,15 +1192,14 @@ export class tools extends plugin {
e.reply(Bot.makeForwardMsg(replyImages)); e.reply(Bot.makeForwardMsg(replyImages));
} }
// 视频 // 视频
const sc = JSON.parse(structured_content); let vod_list = respJson.data.post?.vod_list;
logger.info(sc.length) if (vod_list.length > 0) {
if (sc?.[0]?.insert.vod.resolutions) { const resolutions = vod_list?.[0]?.resolutions;
// 逐个遍历是否包含url // 逐个遍历是否包含url
for (let i = 0; i < sc.length; i++) { for (let i = 0; i < resolutions.length; i++) {
const resolutions = sc?.[i]?.insert.vod.resolutions;
if (resolutions) { if (resolutions) {
// 暂时选取分辨率较低的video进行解析 // 暂时选取分辨率较低的video进行解析
const videoUrl = resolutions[0].url; const videoUrl = resolutions[i].url;
this.downloadVideo(videoUrl).then(path => { this.downloadVideo(videoUrl).then(path => {
e.reply(segment.video(path + "/temp.mp4")); e.reply(segment.video(path + "/temp.mp4"));
}); });

View File

@ -1,5 +1,5 @@
- { - {
version: 1.5.2, version: 1.5.3,
data: data:
[ [
新增<span class="cmd">微博解析</span>功能, 新增<span class="cmd">微博解析</span>功能,