🦞 feat: 更新动态、dy图片解析

1. 更新B站动态解析
2. 更新dy图片解析
This commit is contained in:
zhiyu1998 2023-02-15 02:35:24 +08:00
parent 9169c343bc
commit 6cf906c193
3 changed files with 98 additions and 14 deletions

View File

@ -10,12 +10,23 @@ import tunnel from "tunnel";
import { TwitterApi } from "twitter-api-v2"; import { TwitterApi } from "twitter-api-v2";
import HttpProxyAgent from "https-proxy-agent"; import HttpProxyAgent from "https-proxy-agent";
import { mkdirsSync } from "../utils/file.js"; 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 { parseUrl, parseM3u8, downloadM3u8Videos, mergeAcFileToMp4 } from "../utils/acfun.js";
import config from "../model/index.js"; import config from "../model/index.js";
// import { get, remove, add } from "../utils/redisu.js"; // import { get, remove, add } from "../utils/redisu.js";
const transMap = { : "zh", : "jp", : "wyw", : "en" }; 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 { export class tools extends plugin {
constructor() { constructor() {
@ -38,7 +49,7 @@ export class tools extends plugin {
fnc: "tiktok", fnc: "tiktok",
}, },
{ {
reg: "(.*)(bilibili.com|b23.tv)", reg: "(.*)(bilibili.com|b23.tv|t.bilibili.com)",
fnc: "bili", fnc: "bili",
}, },
{ {
@ -75,7 +86,7 @@ export class tools extends plugin {
this.proxyAddr = this.toolsConfig.proxyAddr; this.proxyAddr = this.toolsConfig.proxyAddr;
this.proxyPort = this.toolsConfig.proxyPort; this.proxyPort = this.toolsConfig.proxyPort;
this.myProxy = `http://${this.proxyAddr}:${this.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 json = await resp.json();
const item = json.aweme_detail; const item = json.aweme_detail;
e.reply(`识别:抖音, ${item.desc}`); e.reply(`识别:抖音, ${item.desc}`);
const url_2 = item.video.play_addr.url_list[0]; const url_type_code = item.aweme_type
this.downloadVideo(url_2).then(video => { const url_type = douyinTypeMap[url_type_code]
e.reply( if (url_type === "video") {
segment.video( const url_2 = item.video.play_addr.url_list[0];
`${this.defaultPath}${this.e.group_id || this.e.user_id}/temp.mp4` 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; return true;
} }
@ -194,10 +221,39 @@ export class tools extends plugin {
await fetch(bShortUrl).then(resp => { await fetch(bShortUrl).then(resp => {
url = resp.url; url = resp.url;
}); });
} else { } else if (url.includes("www.bilibili.com")) {
url = urlRex.exec(url)[0]; 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}/`; const path = `${this.defaultPath}${this.e.group_id || this.e.user_id}/`;
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
mkdirsSync(path); mkdirsSync(path);

View File

@ -1,3 +1,3 @@
defaultPath: './data/rcmp4/' # 保存视频的位置 defaultPath: './data/rcmp4/' # 保存视频的位置
proxyAddr: '127.0.0.1' # 魔法地址 proxyAddr: '127.0.0.1' # 魔法地址
proxyPort: '6152' # 魔法端口 proxyPort: '7890' # 魔法端口

View File

@ -97,4 +97,32 @@ function mergeFileToMp4 (vFullFileName, aFullFileName, outputFileName, shouldDel
}); });
} }
export { downloadBFile, getDownloadUrl, mergeFileToMp4 } 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 }