mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🦞 feat: 更新动态、dy图片解析
1. 更新B站动态解析 2. 更新dy图片解析
This commit is contained in:
parent
9169c343bc
commit
6cf906c193
@ -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);
|
||||
|
@ -1,3 +1,3 @@
|
||||
defaultPath: './data/rcmp4/' # 保存视频的位置
|
||||
proxyAddr: '127.0.0.1' # 魔法地址
|
||||
proxyPort: '6152' # 魔法端口
|
||||
proxyPort: '7890' # 魔法端口
|
@ -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 }
|
Loading…
x
Reference in New Issue
Block a user