mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
🐞 fix: B站动态封装
This commit is contained in:
parent
73f1866806
commit
901435cc35
188
apps/tools.js
188
apps/tools.js
@ -254,20 +254,21 @@ export class tools extends plugin {
|
||||
}
|
||||
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0];
|
||||
// console.log(dynamicId)
|
||||
getDynamic(dynamicId).then(resp => {
|
||||
getDynamic(dynamicId).then(async 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,
|
||||
// })
|
||||
// })
|
||||
let dynamicSrcMsg = []
|
||||
resp.dynamicSrc.forEach(item => {
|
||||
e.reply(segment.image(item));
|
||||
});
|
||||
dynamicSrcMsg.push({
|
||||
message: segment.image(item),
|
||||
nickname: e.sender.card || e.user_id,
|
||||
user_id: e.user_id,
|
||||
})
|
||||
})
|
||||
await this.reply(await Bot.makeForwardMsg(dynamicSrcMsg));
|
||||
// resp.dynamicSrc.forEach(item => {
|
||||
// e.reply(segment.image(item));
|
||||
// });
|
||||
} else {
|
||||
e.reply(`识别:哔哩哔哩动态, 但是失败!`);
|
||||
}
|
||||
@ -425,85 +426,6 @@ export class tools extends plugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 请求参数
|
||||
async douyinRequest (url) {
|
||||
const params = {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
timeout: 10000,
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.head(url, params)
|
||||
.then(resp => {
|
||||
const location = resp.request.res.responseUrl;
|
||||
resolve(location);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 工具:根URL据下载视频 / 音频
|
||||
async downloadVideo (url, isProxy = false) {
|
||||
const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`;
|
||||
if (!fs.existsSync(groupPath)) {
|
||||
mkdirsSync(groupPath);
|
||||
}
|
||||
const target = `${ groupPath }/temp.mp4`;
|
||||
// 待优化
|
||||
if (fs.existsSync(target)) {
|
||||
console.log(`视频已存在`);
|
||||
fs.unlinkSync(target);
|
||||
}
|
||||
let res;
|
||||
if (!isProxy) {
|
||||
res = await axios.get(url, {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
responseType: "stream",
|
||||
});
|
||||
} else {
|
||||
res = await axios.get(url, {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
responseType: "stream",
|
||||
httpAgent: tunnel.httpOverHttp({
|
||||
proxy: { host: this.proxyAddr, port: this.proxyPort },
|
||||
}),
|
||||
httpsAgent: tunnel.httpOverHttp({
|
||||
proxy: { host: this.proxyAddr, port: this.proxyPort },
|
||||
}),
|
||||
});
|
||||
}
|
||||
console.log(`开始下载: ${ url }`);
|
||||
const writer = fs.createWriteStream(target);
|
||||
res.data.pipe(writer);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
// 工具:找到tiktok的视频id
|
||||
async getIdVideo (url) {
|
||||
const matching = url.includes("/video/");
|
||||
if (!matching) {
|
||||
this.e.reply("没找到,正在获取随机视频!");
|
||||
return null;
|
||||
}
|
||||
const idVideo = url.substring(url.indexOf("/video/") + 7, url.length);
|
||||
return idVideo.length > 19 ? idVideo.substring(0, idVideo.indexOf("?")) : idVideo;
|
||||
}
|
||||
|
||||
// acfun解析
|
||||
async acfun (e) {
|
||||
const path = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/temp/`;
|
||||
@ -675,22 +597,82 @@ export class tools extends plugin {
|
||||
});
|
||||
}
|
||||
|
||||
// 工具:下载pdf文件
|
||||
async downloadPDF (url, filename) {
|
||||
return axios({
|
||||
url: url,
|
||||
responseType: "stream",
|
||||
// 请求参数
|
||||
async douyinRequest (url) {
|
||||
const params = {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
}).then(response => {
|
||||
const writer = fs.createWriteStream(filename);
|
||||
response.data.pipe(writer);
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
timeout: 10000,
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.head(url, params)
|
||||
.then(resp => {
|
||||
const location = resp.request.res.responseUrl;
|
||||
resolve(location);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 工具:根URL据下载视频 / 音频
|
||||
async downloadVideo (url, isProxy = false) {
|
||||
const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`;
|
||||
if (!fs.existsSync(groupPath)) {
|
||||
mkdirsSync(groupPath);
|
||||
}
|
||||
const target = `${ groupPath }/temp.mp4`;
|
||||
// 待优化
|
||||
if (fs.existsSync(target)) {
|
||||
console.log(`视频已存在`);
|
||||
fs.unlinkSync(target);
|
||||
}
|
||||
let res;
|
||||
if (!isProxy) {
|
||||
res = await axios.get(url, {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
responseType: "stream",
|
||||
});
|
||||
} else {
|
||||
res = await axios.get(url, {
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
|
||||
},
|
||||
responseType: "stream",
|
||||
httpAgent: tunnel.httpOverHttp({
|
||||
proxy: { host: this.proxyAddr, port: this.proxyPort },
|
||||
}),
|
||||
httpsAgent: tunnel.httpOverHttp({
|
||||
proxy: { host: this.proxyAddr, port: this.proxyPort },
|
||||
}),
|
||||
});
|
||||
}
|
||||
console.log(`开始下载: ${ url }`);
|
||||
const writer = fs.createWriteStream(target);
|
||||
res.data.pipe(writer);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
// 工具:找到tiktok的视频id
|
||||
async getIdVideo (url) {
|
||||
const matching = url.includes("/video/");
|
||||
if (!matching) {
|
||||
this.e.reply("没找到,正在获取随机视频!");
|
||||
return null;
|
||||
}
|
||||
const idVideo = url.substring(url.indexOf("/video/") + 7, url.length);
|
||||
return idVideo.length > 19 ? idVideo.substring(0, idVideo.indexOf("?")) : idVideo;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
import schedule from "node-schedule";
|
||||
import common from "../../../lib/common/common.js";
|
||||
import axios from "axios";
|
||||
import fs from "node:fs";
|
||||
|
||||
/**
|
||||
* 请求模板
|
||||
@ -68,4 +70,28 @@ function retry(func, maxRetries = 3, delay = 1000) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具:下载pdf文件
|
||||
* @param url
|
||||
* @param filename
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
function downloadPDF (url, filename) {
|
||||
return axios({
|
||||
url: url,
|
||||
responseType: "stream",
|
||||
headers: {
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36",
|
||||
},
|
||||
}).then(response => {
|
||||
const writer = fs.createWriteStream(filename);
|
||||
response.data.pipe(writer);
|
||||
return new Promise((resolve, reject) => {
|
||||
writer.on("finish", resolve);
|
||||
writer.on("error", reject);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export { jFeatch, autoTask, retry };
|
||||
|
Loading…
x
Reference in New Issue
Block a user