From 6cf906c1932ebb42c20ebabfb785f52a388dd403 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Wed, 15 Feb 2023 02:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=9E=20feat:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E3=80=81dy=E5=9B=BE=E7=89=87=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 更新B站动态解析 2. 更新dy图片解析 --- apps/tools.js | 80 ++++++++++++++++++++++++++++++++++++++++------- config/tools.yaml | 2 +- utils/bilibili.js | 30 +++++++++++++++++- 3 files changed, 98 insertions(+), 14 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 322dd1f..6e8641f 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -10,12 +10,23 @@ import tunnel from "tunnel"; import { TwitterApi } from "twitter-api-v2"; import HttpProxyAgent from "https-proxy-agent"; import { mkdirsSync } from "../utils/file.js"; -import { downloadBFile, getDownloadUrl, mergeFileToMp4 } from "../utils/bilibili.js"; +import { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } from "../utils/bilibili.js"; import { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js"; import config from "../model/index.js"; // import { get, remove, add } from "../utils/redisu.js"; const transMap = { 中: "zh", 日: "jp", 文: "wyw", 英: "en" }; +const douyinTypeMap = { + 2: 'image', + 4: 'video', + 68: 'image', + 0: 'video', + 51: 'video', + 55: 'video', + 58: 'video', + 61: 'video', + 150: 'image' +} export class tools extends plugin { constructor() { @@ -38,7 +49,7 @@ export class tools extends plugin { fnc: "tiktok", }, { - reg: "(.*)(bilibili.com|b23.tv)", + reg: "(.*)(bilibili.com|b23.tv|t.bilibili.com)", fnc: "bili", }, { @@ -75,7 +86,7 @@ export class tools extends plugin { this.proxyAddr = this.toolsConfig.proxyAddr; this.proxyPort = this.toolsConfig.proxyPort; this.myProxy = `http://${this.proxyAddr}:${this.proxyPort}`; - console.log(this.myProxy) + // console.log(this.myProxy) } // 翻译插件 @@ -117,14 +128,30 @@ export class tools extends plugin { const json = await resp.json(); const item = json.aweme_detail; e.reply(`识别:抖音, ${item.desc}`); - const url_2 = item.video.play_addr.url_list[0]; - this.downloadVideo(url_2).then(video => { - e.reply( - segment.video( - `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4` - ) - ); - }); + const url_type_code = item.aweme_type + const url_type = douyinTypeMap[url_type_code] + if (url_type === "video") { + const url_2 = item.video.play_addr.url_list[0]; + this.downloadVideo(url_2).then(video => { + e.reply( + segment.video( + `${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4` + ) + ); + }); + } else if (url_type === "image") { + // 无水印图片列表/No watermark image list + // let no_watermark_image_list = [] + // 有水印图片列表/With watermark image list + // let watermark_image_list = [] + for (let i of item.images) { + // 无水印图片列表 + // no_watermark_image_list.push(i.url_list[0]) + // 有水印图片列表 + // watermark_image_list.push(i.download_url_list[0]) + e.reply(segment.image(i.url_list[0])) + } + } }); return true; } @@ -194,10 +221,39 @@ export class tools extends plugin { await fetch(bShortUrl).then(resp => { url = resp.url; }); - } else { + } else if (url.includes("www.bilibili.com")) { url = urlRex.exec(url)[0]; } + // 动态 + if (url.includes('t.bilibili.com')) { + // 去除多余参数 + if (url.includes('?')) { + url = url.substring(0, url.indexOf("?")); + } + const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0] + // console.log(dynamicId) + getDynamic(dynamicId).then((resp) => { + if (resp.dynamicSrc.length > 0) { + e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`) + // let dynamicSrcMsg = [] + // resp.dynamicSrc.forEach(item => { + // dynamicSrcMsg.push({ + // message: segment.image(item), + // nickname: e.sender.card || e.user_id, + // user_id: e.user_id, + // }) + // }) + resp.dynamicSrc.forEach(item => { + e.reply(segment.image(item)) + }) + } else { + e.reply(`识别:哔哩哔哩动态, 但是失败!`) + } + }) + return true + } + const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/`; if (!fs.existsSync(path)) { mkdirsSync(path); diff --git a/config/tools.yaml b/config/tools.yaml index bcee6f7..e1b3e7b 100644 --- a/config/tools.yaml +++ b/config/tools.yaml @@ -1,3 +1,3 @@ defaultPath: './data/rcmp4/' # 保存视频的位置 proxyAddr: '127.0.0.1' # 魔法地址 -proxyPort: '6152' # 魔法端口 \ No newline at end of file +proxyPort: '7890' # 魔法端口 \ No newline at end of file diff --git a/utils/bilibili.js b/utils/bilibili.js index bc19a45..a54738d 100644 --- a/utils/bilibili.js +++ b/utils/bilibili.js @@ -97,4 +97,32 @@ function mergeFileToMp4 (vFullFileName, aFullFileName, outputFileName, shouldDel }); } -export { downloadBFile, getDownloadUrl, mergeFileToMp4 } \ No newline at end of file +function getDynamic(dynamicId) { + const dynamicApi = `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id=${dynamicId}` + return axios.get(dynamicApi, { + headers: { + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36', + 'referer': 'https://www.bilibili.com', + } + }).then(resp => { + const dynamicData = resp.data.data.card + const card = JSON.parse(dynamicData.card) + const dynamicOrigin = card.item + const dynamicDesc = dynamicOrigin.description + + const pictures = dynamicOrigin.pictures + let dynamicSrc = [] + for (let pic of pictures) { + const img_src = pic.img_src + dynamicSrc.push(img_src) + } + // console.log(dynamic_src) + return { + dynamicSrc, + dynamicDesc + } + }) +} + +export { downloadBFile, getDownloadUrl, mergeFileToMp4, getDynamic } \ No newline at end of file