diff --git a/apps/tools.js b/apps/tools.js index 29b7689..a84f507 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -50,7 +50,7 @@ import { TWITTER_TWEET_INFO, XHS_REQ_LINK, XHS_VIDEO, - GENERAL_REQ_LINK + GENERAL_REQ_LINK, WEIBO_SINGLE_INFO } from "../constants/tools.js"; import child_process from 'node:child_process' import { getAudio, getVideo } from "../utils/y2b.js"; @@ -145,6 +145,10 @@ export class tools extends plugin { reg: "(music.163.com|163cn.tv)", fnc: "netease", }, + { + reg: "(weibo.com|m.weibo.cn)", + fnc: "weibo", + } ], }); // 配置文件 @@ -929,6 +933,60 @@ export class tools extends plugin { } } + // 微博解析 + async weibo(e) { + let weiboId; + // 对已知情况进行判断 + if (e.msg.includes("m.weibo.cn")) { + // https://m.weibo.cn/detail/4976424138313924 + weiboId = /(?<=detail\/)[A-Za-z\d]+/.exec(e.msg)?.[0]; + } else { + // https://weibo.com/1707895270/5006106478773472 + weiboId = /(?<=weibo.com\/)[A-Za-z\d]+\/[A-Za-z\d]+/.exec(e.msg)?.[0]; + } + // 无法获取id就结束 + if (!weiboId) { + e.reply("解析失败:无法获取到wb的id"); + return; + } + const id = weiboId.split("/")[1] || weiboId; + axios.get(WEIBO_SINGLE_INFO.replace("{}", id), { + headers: { + "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", + "cookie": "_T_WM=40835919903; WEIBOCN_FROM=1110006030; MLOGIN=0; XSRF-TOKEN=4399c8", + } + }) + .then(async resp => { + const wbData = resp.data.data; + const { text, status_title, source, region_name, pics, page_info } = wbData; + e.reply(`识别:微博,${text.replace(/<[^>]+>/g, '')}\n${status_title}\n${source}\t${region_name}`); + if (pics) { + // 图片 + const images = pics.map(item => ({ + message: segment.image(item.url), + nickname: e.sender.card || e.user_id, + user_id: e.user_id, + })); + await this.reply(await Bot.makeForwardMsg(images)); + } + if (page_info) { + // 视频 + const videoUrl = page_info.urls?.mp4_720p_mp4 || page_info.urls?.mp4_hd_mp4; + try { + this.downloadVideo(videoUrl).then(path => { + e.reply(segment.video(path + "/temp.mp4")); + }); + } catch (err) { + e.reply("视频资源获取失败"); + logger.error("403错误:", err); + } + } + }); + return true; + } + /** * 通用解析 * @param e diff --git a/config/help.yaml b/config/help.yaml index f8b2248..c694581 100644 --- a/config/help.yaml +++ b/config/help.yaml @@ -62,6 +62,9 @@ - icon: miyoushe title: "米游社" desc: 米游社文章分享实时下载 + - icon: weibo + title: "微博" + desc: 微博文章分享实时下载 - icon: zuiyou title: "最右(测试阶段)" desc: 最右分享实时下载 diff --git a/config/version.yaml b/config/version.yaml index 9560eaf..8906adf 100644 --- a/config/version.yaml +++ b/config/version.yaml @@ -1,11 +1,10 @@ - { - version: 1.5.1, + version: 1.5.2, data: [ + 新增微博解析功能, 新增最右解析功能, 新增米游社解析功能, - 新增🍉解析功能, - 新增油管解析功能, 支持锅巴插件,方便查看和修改配置, 添加#R帮助获取插件帮助, 添加#R版本获取插件版本, diff --git a/constants/tools.js b/constants/tools.js index 3571c7a..a6a8b93 100644 --- a/constants/tools.js +++ b/constants/tools.js @@ -94,3 +94,9 @@ export const NETEASE_SONG_DOWNLOAD = "https://www.oranges1.top/neteaseapi.do/son * @type {string} */ export const NETEASE_SONG_DETAIL = "https://www.oranges1.top/neteaseapi.do/song/detail?ids={}" + +/** + * 单条微博的接口 + * @type {string} + */ +export const WEIBO_SINGLE_INFO = "https://m.weibo.cn/statuses/show?id={}" diff --git a/resources/img/icon/weibo.png b/resources/img/icon/weibo.png new file mode 100644 index 0000000..e34d9ef Binary files /dev/null and b/resources/img/icon/weibo.png differ