diff --git a/apps/tools.js b/apps/tools.js
index 263b79d..9783ca9 100644
--- a/apps/tools.js
+++ b/apps/tools.js
@@ -1,14 +1,14 @@
// 主库
import fetch from "node-fetch";
import fs from "node:fs";
-import { Buffer } from 'node:buffer';
+import {Buffer} from 'node:buffer';
// 其他库
import axios from "axios";
import _ from "lodash";
import tunnel from "tunnel";
-import { HttpsProxyAgent } from 'https-proxy-agent';
-import { exec, execSync } from "child_process";
-import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists } from "../utils/file.js";
+import {HttpsProxyAgent} from 'https-proxy-agent';
+import {exec, execSync} from "child_process";
+import {checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists} from "../utils/file.js";
import {
downloadBFile,
filterBiliDescLink,
@@ -21,7 +21,7 @@ import {
m4sToMp3,
mergeFileToMp4
} from "../utils/bilibili.js";
-import { downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl } from "../utils/acfun.js";
+import {downloadM3u8Videos, mergeAcFileToMp4, parseM3u8, parseUrl} from "../utils/acfun.js";
import {
BILI_DEFAULT_INTRO_LEN_LIMIT,
COMMON_USER_AGENT,
@@ -51,11 +51,11 @@ import {
import config from "../model/index.js";
import Translate from "../utils/trans-strategy.js";
import * as aBogus from "../utils/a-bogus.cjs";
-import { getBodianAudio, getBodianMusicInfo, getBodianMv } from "../utils/bodian.js";
-import { av2BV } from "../utils/bilibili-bv-av-convert.js";
+import {getBodianAudio, getBodianMusicInfo, getBodianMv} from "../utils/bodian.js";
+import {av2BV} from "../utils/bilibili-bv-av-convert.js";
import querystring from "querystring";
import PQueue from 'p-queue';
-import { getWbi } from "../utils/biliWbi.js";
+import {getWbi} from "../utils/biliWbi.js";
import {
BILI_STREAM_INFO,
BILI_SUMMARY,
@@ -73,14 +73,14 @@ import {
WEISHI_VIDEO_INFO,
XHS_REQ_LINK
} from "../constants/tools.js";
-import { processTikTokUrl } from "../utils/tiktok.js";
-import { getDS } from "../utils/mihoyo.js";
+import {processTikTokUrl} from "../utils/tiktok.js";
+import {getDS} from "../utils/mihoyo.js";
import GeneralLinkAdapter from "../utils/general-link-adapter.js";
-import { mid2id } from "../utils/weibo.js";
-import { LagrangeAdapter } from "../utils/lagrange-adapter.js";
+import {mid2id} from "../utils/weibo.js";
+import {LagrangeAdapter} from "../utils/lagrange-adapter.js";
import path from "path";
-import { OpenaiBuilder } from "../utils/openai-builder.js";
-import { contentEstimator } from "../utils/link-share-summary-util.js";
+import {OpenaiBuilder} from "../utils/openai-builder.js";
+import {contentEstimator} from "../utils/link-share-summary-util.js";
export class tools extends plugin {
/**
@@ -104,7 +104,7 @@ export class tools extends plugin {
priority: 300,
rule: [
{
- reg: `^(翻|trans)[${ tools.Constants.existsTransKey }]`,
+ reg: `^(翻|trans)[${tools.Constants.existsTransKey}]`,
fnc: "trans",
},
{
@@ -194,7 +194,7 @@ export class tools extends plugin {
},
{
reg: "(qishui.douyin.com)",
- fnc: "qishuiMusic"
+ fnc: "qishuiMusic"
}
],
});
@@ -205,7 +205,7 @@ export class tools extends plugin {
// 魔法接口
this.proxyAddr = this.toolsConfig.proxyAddr;
this.proxyPort = this.toolsConfig.proxyPort;
- this.myProxy = `http://${ this.proxyAddr }:${ this.proxyPort }`;
+ this.myProxy = `http://${this.proxyAddr}:${this.proxyPort}`;
// 加载哔哩哔哩配置
this.biliSessData = this.toolsConfig.biliSessData;
// 加载哔哩哔哩的限制时长
@@ -225,7 +225,7 @@ export class tools extends plugin {
proxy: this.myProxy,
});
// 并发队列
- this.queue = new PQueue({ concurrency: Number(this.toolsConfig.queueConcurrency) });
+ this.queue = new PQueue({concurrency: Number(this.toolsConfig.queueConcurrency)});
// 视频下载的并发数量
this.videoDownloadConcurrency = this.toolsConfig.videoDownloadConcurrency;
// ai接口
@@ -262,7 +262,7 @@ export class tools extends plugin {
const res = await this.douyinRequest(douUrl);
// 当前版本需要填入cookie
if (_.isEmpty(this.douyinCookie)) {
- e.reply(`检测到没有Cookie,无法解析抖音${ HELP_DOC }`);
+ e.reply(`检测到没有Cookie,无法解析抖音${HELP_DOC}`);
return;
}
const douId = /note\/(\d+)/g.exec(res)?.[1] || /video\/(\d+)/g.exec(res)?.[1];
@@ -283,8 +283,8 @@ export class tools extends plugin {
headers["User-Agent"],
);
// const param = resp.data.result[0].paramsencode;
- const resDyApi = `${ dyApi }&a_bogus=${ abParam }`;
- headers['Referer'] = `https://www.douyin.com/video/${ douId }`
+ const resDyApi = `${dyApi}&a_bogus=${abParam}`;
+ headers['Referer'] = `https://www.douyin.com/video/${douId}`
// 定义一个dy请求
const dyResponse = () => axios.get(resDyApi, {
headers,
@@ -301,7 +301,7 @@ export class tools extends plugin {
if (urlType === "video") {
// logger.info(item.video);
// 多位面选择:play_addr、play_addr_265、play_addr_h264
- const { play_addr: { uri: videoAddrURI }, duration, cover } = item.video;
+ const {play_addr: {uri: videoAddrURI}, duration, cover} = item.video;
// 进行时间判断,如果超过时间阈值就不发送
const dyDuration = Math.trunc(duration / 1000);
const durationThreshold = this.biliDuration;
@@ -309,14 +309,14 @@ export class tools extends plugin {
// 超过阈值,不发送的情况
const dyCover = cover.url_list?.pop();
// logger.info(cover.url_list);
- e.reply([segment.image(dyCover), `识别:抖音, ${ item.desc }\n
- ${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ Math.trunc(dyDuration / 60) }分钟,\n大于管理员设置的最大时长 ${ durationThreshold / 60 } 分钟!`])
+ e.reply([segment.image(dyCover), `识别:抖音, ${item.desc}\n
+ ${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${Math.trunc(dyDuration / 60)}分钟,\n大于管理员设置的最大时长 ${durationThreshold / 60} 分钟!`])
// 如果开启评论的就调用
await this.douyinComment(e, douId, headers);
return;
} else {
// 正常发送
- e.reply(`识别:抖音, ${ item.desc }`);
+ e.reply(`识别:抖音, ${item.desc}`);
}
// 分辨率判断是否压缩
const resolution = this.douyinCompression ? "720p" : "1080p";
@@ -336,7 +336,7 @@ export class tools extends plugin {
}*/
// logger.info(resUrl);
- const path = `${ this.getCurDownloadPath(e) }/temp.mp4`;
+ const path = `${this.getCurDownloadPath(e)}/temp.mp4`;
// 加入队列
this.queue.add(async () => {
await this.downloadVideo(resUrl).then(() => {
@@ -345,7 +345,7 @@ export class tools extends plugin {
})
} else if (urlType === "image") {
// 发送描述
- e.reply(`识别:抖音, ${ item.desc }`);
+ e.reply(`识别:抖音, ${item.desc}`);
// 无水印图片列表
let no_watermark_image_list = [];
// 有水印图片列表
@@ -368,7 +368,7 @@ export class tools extends plugin {
await this.douyinComment(e, douId, headers);
} catch (err) {
logger.error(err);
- logger.mark(`Cookie 过期或者 Cookie 没有填写,请参考\n${ HELP_DOC }\n尝试无效后可以到官方QQ群[575663150]提出 bug 等待解决`)
+ logger.mark(`Cookie 过期或者 Cookie 没有填写,请参考\n${HELP_DOC}\n尝试无效后可以到官方QQ群[575663150]提出 bug 等待解决`)
}
return true;
}
@@ -388,7 +388,7 @@ export class tools extends plugin {
new URLSearchParams(new URL(dyCommentUrl).search).toString(),
headers["User-Agent"],
);
- const commentsResp = await axios.get(`${ dyCommentUrl }&a_bogus=${ abParam }`, {
+ const commentsResp = await axios.get(`${dyCommentUrl}&a_bogus=${abParam}`, {
headers
})
// logger.info(headers)
@@ -422,10 +422,10 @@ export class tools extends plugin {
// 下载逻辑
const path = this.getCurDownloadPath(e);
await checkAndRemoveFile(path + "/temp.mp4");
- const title = execSync(`yt-dlp --get-title ${ cleanedTiktokUrl } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`)
- e.reply(`识别:TikTok,视频下载中请耐心等待 \n${ title }`);
+ const title = execSync(`yt-dlp --get-title ${cleanedTiktokUrl} ${isOversea ? "" : `--proxy ${this.myProxy}`}`)
+ e.reply(`识别:TikTok,视频下载中请耐心等待 \n${title}`);
await this.tiktokHelper(path, cleanedTiktokUrl, isOversea);
- await this.sendVideoToUpload(e, `${ path }/temp.mp4`);
+ await this.sendVideoToUpload(e, `${path}/temp.mp4`);
return true;
}
@@ -439,13 +439,13 @@ export class tools extends plugin {
*/
async tiktokHelper(path, url, isOversea) {
return new Promise((resolve, reject) => {
- const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ this.myProxy }` } -P ${ path } -o "temp.%(ext)s" ${ url }`;
+ const command = `yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} -o "temp.%(ext)s" ${url}`;
exec(command, (error, stdout) => {
if (error) {
- console.error(`Error executing command: ${ error }`);
+ console.error(`Error executing command: ${error}`);
reject(error);
} else {
- console.log(`Command output: ${ stdout }`);
+ console.log(`Command output: ${stdout}`);
resolve(stdout);
}
});
@@ -454,17 +454,17 @@ export class tools extends plugin {
// 哔哩哔哩扫码登录
async biliScan(e) {
- e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 });
+ e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', {recallMsg: 180});
// 图片发送钩子
const imgSendHook = function (e, path) {
- e.reply([segment.image(path), segment.at(e.user_id), '请扫码以完成获取'], { recallMsg: 180 })
+ e.reply([segment.image(path), segment.at(e.user_id), '请扫码以完成获取'], {recallMsg: 180})
};
// 检查路径是否存在文件夹
await mkdirIfNotExists(this.defaultPath);
// 发送请求
- const saveCodePath = `${ this.defaultPath }qrcode.png`;
+ const saveCodePath = `${this.defaultPath}qrcode.png`;
- const { SESSDATA, refresh_token } = await getScanCodeData(saveCodePath, 8, () => imgSendHook(e, saveCodePath))
+ const {SESSDATA, refresh_token} = await getScanCodeData(saveCodePath, 8, () => imgSendHook(e, saveCodePath))
// 更新到配置文件
config.updateField("tools", "biliSessData", SESSDATA);
@@ -479,7 +479,7 @@ export class tools extends plugin {
let url = e.msg === undefined ? e.message.shift().data.replaceAll("\\", "") : e.msg.trim().replaceAll("\\", "");
// 直接发送BV号的处理
if (/^BV[1-9a-zA-Z]{10}$/.exec(url)?.[0]) {
- url = `https://www.bilibili.com/video/${ url }`;
+ url = `https://www.bilibili.com/video/${url}`;
logger.info(url)
}
// 短号处理
@@ -511,11 +511,11 @@ export class tools extends plugin {
// 提取相关信息
const liveData = await this.getBiliStream(streamId);
// logger.info(liveData);
- const { title, user_cover, keyframe, description, tags } = liveData.data.data;
+ const {title, user_cover, keyframe, description, tags} = liveData.data.data;
e.reply([
segment.image(user_cover),
segment.image(keyframe),
- `识别:哔哩哔哩直播,${ title }${ description ? `\n\n简述:${ description }\n` : '' }${ tags ? `标签:${ tags }\n` : '' }`
+ `识别:哔哩哔哩直播,${title}${description ? `\n\n简述:${description}\n` : ''}${tags ? `标签:${tags}\n` : ''}`
]);
return true;
}
@@ -551,9 +551,9 @@ export class tools extends plugin {
// 视频信息获取例子:http://api.bilibili.com/x/web-interface/view?bvid=BV1hY411m7cB
// 请求视频信息
const videoInfo = await getVideoInfo(url);
- const { title, pic, desc, duration, dynamic, stat, bvid, aid, cid, owner, pages } = videoInfo;
+ const {title, pic, desc, duration, dynamic, stat, bvid, aid, cid, owner, pages} = videoInfo;
// 视频信息
- let { view, danmaku, reply, favorite, coin, share, like } = stat;
+ let {view, danmaku, reply, favorite, coin, share, like} = stat;
// 限制时长 & 考虑分页视频情况
const query = querystring.parse(url);
const curPage = query?.p || 0;
@@ -572,8 +572,8 @@ export class tools extends plugin {
// 过滤简介中的一些链接
const filteredDesc = await filterBiliDescLink(desc);
// 格式化数据
- const combineContent = `\n${ formatBiliInfo(dataProcessMap) }\n简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`;
- let biliInfo = [`识别:哔哩哔哩:${ title }`, combineContent]
+ const combineContent = `\n${formatBiliInfo(dataProcessMap)}\n简介:${truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT)}`;
+ let biliInfo = [`识别:哔哩哔哩:${title}`, combineContent]
// 总结
const summary = await this.getBiliSummary(bvid, cid, owner.mid);
// 不提取音乐,正常处理
@@ -582,26 +582,26 @@ export class tools extends plugin {
biliInfo.unshift(segment.image(pic))
// 限制视频解析
const durationInMinutes = (curDuration / 60).toFixed(0);
- biliInfo.push(`${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ durationInMinutes }分钟,\n大于管理员设置的最大时长 ${ this.biliDuration / 60 } 分钟!`)
- summary && biliInfo.push(`\n${ summary }`);
+ biliInfo.push(`${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${durationInMinutes}分钟,\n大于管理员设置的最大时长 ${this.biliDuration / 60} 分钟!`)
+ summary && biliInfo.push(`\n${summary}`);
e.reply(biliInfo);
return true;
} else {
- summary && biliInfo.push(`\n${ summary }`);
+ summary && biliInfo.push(`\n${summary}`);
e.reply(biliInfo);
}
// 创建文件,如果不存在
- const path = `${ this.getCurDownloadPath(e) }/`;
+ const path = `${this.getCurDownloadPath(e)}/`;
await mkdirIfNotExists(path);
// 加入队列
this.queue.add(async () => {
// 下载文件
getDownloadUrl(url)
.then(data => {
- this.downBili(`${ path }temp`, data.videoUrl, data.audioUrl)
+ this.downBili(`${path}temp`, data.videoUrl, data.audioUrl)
.then(_ => {
- this.sendVideoToUpload(e, `${ path }temp.mp4`)
+ this.sendVideoToUpload(e, `${path}temp.mp4`)
})
.catch(err => {
logger.error(err);
@@ -631,31 +631,31 @@ export class tools extends plugin {
const isLimitDuration = curDuration > this.biliDuration;
if (isLimitDuration) {
const durationInMinutes = (curDuration / 60).toFixed(0);
- e.reply(`当前视频(${ videoId })时长为 ${ durationInMinutes } 分钟,大于管理员设置的时长 ${ this.biliDuration / 60 } 分钟`);
+ e.reply(`当前视频(${videoId})时长为 ${durationInMinutes} 分钟,大于管理员设置的时长 ${this.biliDuration / 60} 分钟`);
return true;
}
// 获取关键信息
- const { video, audio } = dash;
+ const {video, audio} = dash;
const videoData = video?.[0];
const audioData = audio?.[0];
// 提取信息
- const { height, frameRate, baseUrl: videoBaseUrl } = videoData;
- const { baseUrl: audioBaseUrl } = audioData;
- e.reply(`正在下载${ height }p ${ Math.trunc(frameRate) }帧数 视频,请稍候...`);
- const path = `${ this.getCurDownloadPath(e) }/`;
+ const {height, frameRate, baseUrl: videoBaseUrl} = videoData;
+ const {baseUrl: audioBaseUrl} = audioData;
+ e.reply(`正在下载${height}p ${Math.trunc(frameRate)}帧数 视频,请稍候...`);
+ const path = `${this.getCurDownloadPath(e)}/`;
const that = this;
// 添加下载任务到并发队列
this.queue.add(() =>
- that.downBili(`${ path }temp`, videoBaseUrl, audioBaseUrl)
+ that.downBili(`${path}temp`, videoBaseUrl, audioBaseUrl)
.then(_ => {
- that.sendVideoToUpload(e, `${ path }temp.mp4`);
+ that.sendVideoToUpload(e, `${path}temp.mp4`);
})
.catch(err => {
- logger.error(`[R插件][B站下载引擎] ${ err }`);
+ logger.error(`[R插件][B站下载引擎] ${err}`);
e.reply("解析失败,请重试一下");
})
);
- logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${ this.queue.size }`);
+ logger.mark(`[R插件][B站下载引擎] 当前下载队列大小${this.queue.size}`);
return true;
}
@@ -685,7 +685,7 @@ export class tools extends plugin {
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0];
getDynamic(dynamicId, session).then(async resp => {
if (resp.dynamicSrc.length > 0) {
- e.reply(`识别:哔哩哔哩动态, ${ resp.dynamicDesc }`);
+ e.reply(`识别:哔哩哔哩动态, ${resp.dynamicDesc}`);
let dynamicSrcMsg = [];
resp.dynamicSrc.forEach(item => {
dynamicSrcMsg.push({
@@ -715,10 +715,10 @@ export class tools extends plugin {
// 这个有点用,但不多
let wbi = "wts=1701546363&w_rid=1073871926b3ccd99bd790f0162af634"
if (!_.isEmpty(this.biliSessData)) {
- wbi = await getWbi({ bvid, cid, up_mid }, this.biliSessData);
+ wbi = await getWbi({bvid, cid, up_mid}, this.biliSessData);
}
// 构造API
- const summaryUrl = `${ BILI_SUMMARY }?${ wbi }`;
+ const summaryUrl = `${BILI_SUMMARY}?${wbi}`;
logger.info(summaryUrl)
// 构造结果:https://api.bilibili.com/x/web-interface/view/conclusion/get?bvid=BV1L94y1H7CV&cid=1335073288&up_mid=297242063&wts=1701546363&w_rid=1073871926b3ccd99bd790f0162af634
return axios.get(summaryUrl)
@@ -730,7 +730,7 @@ export class tools extends plugin {
let resReply = "";
// 总体总结
if (summary) {
- resReply = `\n摘要:${ summary }\n`
+ resReply = `\n摘要:${summary}\n`
}
// 分段总结
if (outline) {
@@ -739,11 +739,11 @@ export class tools extends plugin {
const keyPoint = item?.part_outline;
// 时间点的总结
const specificContent = keyPoint.map(point => {
- const { timestamp, content } = point
+ const {timestamp, content} = point
const specificTime = secondsToTime(timestamp)
- return `${ specificTime } ${ content }\n`;
+ return `${specificTime} ${content}\n`;
}).join("");
- return `- ${ smallTitle }\n${ specificContent }\n`;
+ return `- ${smallTitle}\n${specificContent}\n`;
});
resReply += specificTimeSummary.join("");
}
@@ -757,7 +757,7 @@ export class tools extends plugin {
* @returns {Promise<*>}
*/
async getBiliStream(liveId) {
- return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, {
+ return axios.get(`${BILI_STREAM_INFO}?room_id=${liveId}`, {
headers: {
'User-Agent': COMMON_USER_AGENT,
}
@@ -783,14 +783,14 @@ export class tools extends plugin {
await fetch(TWITTER_TWEET_INFO.replace("{}", id), {
headers: {
"User-Agent": "v2TweetLookupJS",
- "authorization": `Bearer ${ Buffer.from(TWITTER_BEARER_TOKEN, "base64").toString() }`
+ "authorization": `Bearer ${Buffer.from(TWITTER_BEARER_TOKEN, "base64").toString()}`
},
...params,
agent: !isOversea ? '' : new HttpsProxyAgent(this.myProxy),
}).then(async resp => {
logger.info(resp)
- e.reply(`识别:小蓝鸟学习版,${ resp.data.text }`);
- const downloadPath = `${ this.getCurDownloadPath(e) }`;
+ e.reply(`识别:小蓝鸟学习版,${resp.data.text}`);
+ const downloadPath = `${this.getCurDownloadPath(e)}`;
// 创建文件夹(如果没有过这个群)
if (!fs.existsSync(downloadPath)) {
mkdirsSync(downloadPath);
@@ -805,7 +805,7 @@ export class tools extends plugin {
// 视频
await this.downloadVideo(resp.includes.media[0].variants[0].url, true).then(
_ => {
- e.reply(segment.video(`${ downloadPath }/temp.mp4`));
+ e.reply(segment.video(`${downloadPath}/temp.mp4`));
},
);
}
@@ -898,21 +898,21 @@ export class tools extends plugin {
// acfun解析
async acfun(e) {
- const path = `${ this.getCurDownloadPath(e) }/temp/`;
+ const path = `${this.getCurDownloadPath(e)}/temp/`;
await mkdirIfNotExists(path);
let inputMsg = e.msg;
// 适配手机分享:https://m.acfun.cn/v/?ac=32838812&sid=d2b0991bd6ad9c09
if (inputMsg.includes("m.acfun.cn")) {
- inputMsg = `https://www.acfun.cn/v/ac${ /ac=([^&?]*)/.exec(inputMsg)[1] }`;
+ inputMsg = `https://www.acfun.cn/v/ac${/ac=([^&?]*)/.exec(inputMsg)[1]}`;
}
parseUrl(inputMsg).then(res => {
- e.reply(`识别:猴山,${ res.videoName }`);
+ e.reply(`识别:猴山,${res.videoName}`);
parseM3u8(res.urlM3u8s[res.urlM3u8s.length - 1]).then(res2 => {
downloadM3u8Videos(res2.m3u8FullUrls, path).then(_ => {
- mergeAcFileToMp4(res2.tsNames, path, `${ path }out.mp4`).then(_ => {
- this.sendVideoToUpload(e, `${ path }out.mp4`)
+ mergeAcFileToMp4(res2.tsNames, path, `${path}out.mp4`).then(_ => {
+ this.sendVideoToUpload(e, `${path}out.mp4`)
});
});
});
@@ -948,11 +948,16 @@ export class tools extends plugin {
} else {
id = /explore\/(\w+)/.exec(msgUrl)?.[1] || /discovery\/item\/(\w+)/.exec(msgUrl)?.[1];
}
- const downloadPath = `${ this.getCurDownloadPath(e) }`;
+ const downloadPath = `${this.getCurDownloadPath(e)}`;
+ // 检测没有 cookie 则退出
+ if (_.isEmpty(this.xiaohongshuCookie)) {
+ e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck,文档:${HELP_DOC}`);
+ return;
+ }
// 注入ck
XHS_NO_WATERMARK_HEADER.cookie = this.xiaohongshuCookie;
// 获取信息
- fetch(`${ XHS_REQ_LINK }${ id }`, {
+ fetch(`${XHS_REQ_LINK}${id}`, {
headers: XHS_NO_WATERMARK_HEADER,
}).then(async resp => {
const xhsHtml = await resp.text();
@@ -960,25 +965,25 @@ export class tools extends plugin {
const res = xhsHtml.match(reg)[1].replace(/undefined/g, "null");
const resJson = JSON.parse(res);
const noteData = resJson.note.noteDetailMap[id].note;
- const { title, desc, type } = noteData;
+ const {title, desc, type} = noteData;
let imgPromise = [];
if (type === "video") {
// 封面
const cover = noteData.imageList?.[0].urlDefault;
- e.reply([segment.image(cover), `识别:小红书, ${ title }\n${ desc }`]);
+ e.reply([segment.image(cover), `识别:小红书, ${title}\n${desc}`]);
// 构造xhs视频链接
const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl;
// 下载视频
this.downloadVideo(xhsVideoUrl).then(path => {
if (path === undefined) {
// 创建文件,如果不存在
- path = `${ this.getCurDownloadPath(e) }/`;
+ path = `${this.getCurDownloadPath(e)}/`;
}
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
return true;
} else if (type === "normal") {
- e.reply(`识别:小红书, ${ title }\n${ desc }`);
+ e.reply(`识别:小红书, ${title}\n${desc}`);
noteData.imageList.map(async (item, index) => {
imgPromise.push(downloadImg(item.urlDefault, downloadPath, index.toString()));
});
@@ -1010,10 +1015,10 @@ export class tools extends plugin {
if (suffix.startsWith("reel")) {
suffix = suffix.replace("reel/", "p/");
}
- const API = `https://imginn.com/${ suffix }`;
+ const API = `https://imginn.com/${suffix}`;
// logger.info(API);
let imgPromise = [];
- const downloadPath = `${ this.getCurDownloadPath(e) }`;
+ const downloadPath = `${this.getCurDownloadPath(e)}`;
// 判断是否是海外服务器
const isOversea = await this.isOverseasServer();
// 简单封装图片下载
@@ -1042,13 +1047,13 @@ export class tools extends plugin {
const desc = html.match(/(?<=content=").*?(?=\")/g)?.[2];
const images = html.match(/
/g);
if (!_.isNull(images)) {
- e.reply(`识别:Insta,${ desc || "暂无描述" }\n`);
+ e.reply(`识别:Insta,${desc || "暂无描述"}\n`);
images.map((item, index) => {
const imgUrl = /(?<=data-src=").*?(?=")/
.exec(item)[0]
.replace(/#38/g, "")
.replace(/;/g, "");
- imgPromise.push(downloadInsImg(imgUrl, `${ downloadPath }/${ index }.jpg`));
+ imgPromise.push(downloadInsImg(imgUrl, `${downloadPath}/${index}.jpg`));
});
}
// TODO 视频,会出bug暂时不做
@@ -1087,16 +1092,16 @@ export class tools extends plugin {
const id =
/(?=musicId).*?(?=&)/.exec(e.msg.trim())?.[0].replace("musicId=", "") ||
/(?=mvId).*?(?=&)/.exec(e.msg.trim())?.[0].replace("mvId=", "");
- const { name, album, artist, albumPic120, categorys } = await getBodianMusicInfo(id);
+ const {name, album, artist, albumPic120, categorys} = await getBodianMusicInfo(id);
e.reply([
- `识别:波点音乐,${ name }-${ album }-${ artist }\n标签:${ categorys
+ `识别:波点音乐,${name}-${album}-${artist}\n标签:${categorys
.map(item => item.name)
- .join(" | ") }`,
+ .join(" | ")}`,
segment.image(albumPic120),
]);
if (e.msg.includes("musicId")) {
- const path = `${ this.getCurDownloadPath(e) }`;
- await getBodianAudio(id, path, `${ name }-${ artist }`).then(sendPath => {
+ const path = `${this.getCurDownloadPath(e)}`;
+ await getBodianAudio(id, path, `${name}-${artist}`).then(sendPath => {
// 发送语音
e.reply(segment.record(sendPath));
// 上传群文件
@@ -1107,7 +1112,7 @@ export class tools extends plugin {
} else if (e.msg.includes("mvId")) {
await getBodianMv(id).then(res => {
// 下载 && 发送
- const { coverUrl, highUrl, lowUrl, shortLowUrl } = res;
+ const {coverUrl, highUrl, lowUrl, shortLowUrl} = res;
this.downloadVideo(lowUrl).then(path => {
e.reply(segment.video(path + "/temp.mp4"));
});
@@ -1163,12 +1168,12 @@ export class tools extends plugin {
}
})
]);
- const { name: mvName, artistName: mvArtist, cover: mvCover } = mvDetailData.data?.data;
- e.reply([segment.image(mvCover), `识别:网易云MV,${ mvName } - ${ mvArtist }`]);
+ const {name: mvName, artistName: mvArtist, cover: mvCover} = mvDetailData.data?.data;
+ e.reply([segment.image(mvCover), `识别:网易云MV,${mvName} - ${mvArtist}`]);
// logger.info(mvUrlData.data)
- const { url: mvUrl } = mvUrlData.data?.data;
+ const {url: mvUrl} = mvUrlData.data?.data;
this.downloadVideo(mvUrl).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
return;
}
@@ -1187,14 +1192,14 @@ export class tools extends plugin {
// 获取歌曲信息
let title = await axios.get(AUTO_NETEASE_SONG_DETAIL.replace("{}", id)).then(res => {
const song = res.data.songs[0];
- return `${ song?.name }-${ song?.ar?.[0].name }`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
+ return `${song?.name}-${song?.ar?.[0].name}`.replace(/[\/\?<>\\:\*\|".… ]/g, "");
});
// 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||')
if (!isOversea || url == null) {
url = await this.musicTempApi(e, title, "网易云音乐");
} else {
// 不是VIP歌曲,直接识别完就下一步
- e.reply(`识别:网易云音乐,${ title }`);
+ e.reply(`识别:网易云音乐,${title}`);
}
// 动态判断后缀名
const extensionPattern = /\.([a-zA-Z0-9]+)$/;
@@ -1208,7 +1213,7 @@ export class tools extends plugin {
// 删除文件
await checkAndRemoveFile(path);
}).catch(err => {
- logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
+ logger.error(`下载音乐失败,错误信息为: ${err.message}`);
});
});
return true;
@@ -1225,9 +1230,9 @@ export class tools extends plugin {
});
const messageTitle = title + "\nR插件检测到当前为VIP音乐,正在转换...";
// ??后的内容是适配`QQ_MUSIC_TEMP_API`
- const url = vipMusicData.data.mp3 ?? vipMusicData.data.data.url;
- const cover = vipMusicData.data.img ?? vipMusicData.data.data.cover;
- await e.reply([segment.image(cover), `识别:${ musicType },${ messageTitle }`]);
+ const url = vipMusicData.data.mp3 ?? vipMusicData.data.data.url;
+ const cover = vipMusicData.data.img ?? vipMusicData.data.data.cover;
+ await e.reply([segment.image(cover), `识别:${musicType},${messageTitle}`]);
return url;
}
@@ -1262,8 +1267,8 @@ export class tools extends plugin {
})
.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 }`);
+ 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 removePath = [];
// 图片
@@ -1302,7 +1307,7 @@ export class tools extends plugin {
"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",
"referer": "https://weibo.com/",
}).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
} catch (err) {
e.reply("视频资源获取失败");
@@ -1321,7 +1326,7 @@ export class tools extends plugin {
async general(e) {
try {
const adapter = await GeneralLinkAdapter.create(e.msg);
- e.reply(`识别:${ adapter.name }${ adapter.desc ? `, ${ adapter.desc }` : '' }`);
+ e.reply(`识别:${adapter.name}${adapter.desc ? `, ${adapter.desc}` : ''}`);
logger.mark(adapter);
if (adapter.images && adapter.images.length > 0) {
const images = adapter.images.map(item => {
@@ -1336,7 +1341,7 @@ export class tools extends plugin {
// 视频:https://www.kuaishou.com/short-video/3xhjgcmir24m4nm
const url = adapter.video;
this.downloadVideo(url).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
} else {
e.reply("解析失败:无法获取到资源");
@@ -1357,13 +1362,13 @@ export class tools extends plugin {
*/
async dy2b(path, url, isOversea) {
return new Promise((resolve, reject) => {
- const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ this.myProxy }` } -P ${ path } -o "temp.%(ext)s" -f 'best[height<=720][ext=mp4]' --merge-output-format "mp4" ${ url }`;
+ const command = `yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} -o "temp.%(ext)s" -f 'best[height<=720][ext=mp4]' --merge-output-format "mp4" ${url}`;
exec(command, (error, stdout) => {
if (error) {
- console.error(`Error executing command: ${ error }`);
+ console.error(`Error executing command: ${error}`);
reject(error);
} else {
- console.log(`Command output: ${ stdout }`);
+ console.log(`Command output: ${stdout}`);
resolve(stdout);
}
});
@@ -1389,10 +1394,10 @@ export class tools extends plugin {
}
const path = this.getCurDownloadPath(e);
await checkAndRemoveFile(path + "/temp.mp4")
- const title = execSync(`yt-dlp --get-title ${ url } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`)
- e.reply(`识别:油管,视频下载中请耐心等待 \n${ title }`);
+ const title = execSync(`yt-dlp --get-title ${url} ${isOversea ? "" : `--proxy ${this.myProxy}`}`)
+ e.reply(`识别:油管,视频下载中请耐心等待 \n${title}`);
await this.dy2b(path, url, isOversea);
- this.sendVideoToUpload(e, `${ path }/temp.mp4`, videoSizeLimit)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`, videoSizeLimit)
} catch (error) {
console.error(error);
throw error; // Rethrow the error so it can be handled by the caller
@@ -1430,7 +1435,7 @@ export class tools extends plugin {
// return;
const data = respJson.data.post.post;
// 分别获取:封面、主题、内容、图片
- const { cover, subject, content, images } = data;
+ const {cover, subject, content, images} = data;
let realContent = "";
// safe JSON.parse
try {
@@ -1438,7 +1443,7 @@ export class tools extends plugin {
} catch (e) {
realContent = content;
}
- const normalMsg = `识别:米游社,${ subject }\n${ realContent?.describe || "" }`;
+ const normalMsg = `识别:米游社,${subject}\n${realContent?.describe || ""}`;
const replyMsg = cover ? [segment.image(cover), normalMsg] : normalMsg;
e.reply(replyMsg);
// 图片
@@ -1462,7 +1467,7 @@ export class tools extends plugin {
// 暂时选取分辨率较低的video进行解析
const videoUrl = resolutions[i].url;
this.downloadVideo(videoUrl).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
break;
}
@@ -1505,10 +1510,10 @@ export class tools extends plugin {
const cover = firstFeed.images[0].url;
const noWatermarkDownloadUrl = firstFeed.video_url;
- e.reply([segment.image(cover), `识别:微视,${ title }`]);
+ e.reply([segment.image(cover), `识别:微视,${title}`]);
this.downloadVideo(noWatermarkDownloadUrl).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
} catch (err) {
logger.error(err);
@@ -1558,7 +1563,7 @@ export class tools extends plugin {
images,
};
- e.reply([segment.image(shortVideoInfo.cover), `识别:最右,${ shortVideoInfo.authorName }\n${ shortVideoInfo.title }`])
+ e.reply([segment.image(shortVideoInfo.cover), `识别:最右,${shortVideoInfo.authorName}\n${shortVideoInfo.title}`])
if (shortVideoInfo.images.length > 0) {
const replyImages = shortVideoInfo.images.map(item => {
@@ -1572,7 +1577,7 @@ export class tools extends plugin {
}
if (shortVideoInfo.noWatermarkDownloadUrl) {
this.downloadVideo(shortVideoInfo.noWatermarkDownloadUrl).then(path => {
- this.sendVideoToUpload(e, `${ path }/temp.mp4`)
+ this.sendVideoToUpload(e, `${path}/temp.mp4`)
});
}
} catch (error) {
@@ -1594,17 +1599,17 @@ export class tools extends plugin {
// 检测是否存在框架
const isExistFreyr = await checkCommandExists("freyr");
if (!isExistFreyr) {
- e.reply(`检测到没有${ freyrName }需要的环境,无法解析!${ HELP_DOC }`);
+ e.reply(`检测到没有${freyrName}需要的环境,无法解析!${HELP_DOC}`);
return;
}
// 执行命令
- const result = await execSync(`freyr -d ${ currentWorkingDirectory + "/am/" } get ${ message }`);
+ const result = await execSync(`freyr -d ${currentWorkingDirectory + "/am/"} get ${message}`);
logger.info(result.toString());
// 获取信息
- let { title, album, artist } = await this.parseFreyrLog(result.toString());
+ let {title, album, artist} = await this.parseFreyrLog(result.toString());
// 兜底策略
if (freyrName === "Apple Music" && (title === "N/A" || album === "N/A" || artist === "N/A")) {
- const data = await axios.get(`https://api.fabdl.com/apple-music/get?url=${ message }`, {
+ const data = await axios.get(`https://api.fabdl.com/apple-music/get?url=${message}`, {
headers: {
"User-Agent": COMMON_USER_AGENT,
"Referer": "https://apple-music-downloader.com/",
@@ -1612,7 +1617,7 @@ export class tools extends plugin {
"Accept": "application/json, text/plain, */*",
},
})
- const { name, artists } = data.data.result;
+ const {name, artists} = data.data.result;
title = name;
artist = artists;
}
@@ -1621,7 +1626,7 @@ export class tools extends plugin {
// 国内服务器解决方案
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
// 临时接口
- const url = await this.musicTempApi(e, `${ title } ${ artist }`, freyrName);
+ const url = await this.musicTempApi(e, `${title} ${artist}`, freyrName);
// 下载音乐
downloadAudio(url, this.getCurDownloadPath(e), title, 'follow').then(async path => {
// 发送语音
@@ -1630,11 +1635,11 @@ export class tools extends plugin {
await this.uploadGroupFile(e, path);
await checkAndRemoveFile(path);
}).catch(err => {
- logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
+ logger.error(`下载音乐失败,错误信息为: ${err.message}`);
});
return true;
}
- e.reply(`识别:${ freyrName },${ title }--${ artist }`);
+ e.reply(`识别:${freyrName},${title}--${artist}`);
// 检查目录是否存在
const musicPath = currentWorkingDirectory + "/am/" + artist + "/" + album;
const that = this;
@@ -1645,7 +1650,7 @@ export class tools extends plugin {
// 读取目录中的所有文件和文件夹
fs.readdir(musicPath, (err, files) => {
if (err) {
- e.reply(`${ freyrName }解析出错,请查看日志!`)
+ e.reply(`${freyrName}解析出错,请查看日志!`)
logger.error('读取目录时出错:', err);
return;
}
@@ -1660,11 +1665,11 @@ export class tools extends plugin {
});
});
} else {
- e.reply(`下载失败!没有找到${ freyrName }下载下来文件!`);
+ e.reply(`下载失败!没有找到${freyrName}下载下来文件!`);
}
// 计数
tools.#amCount += 1;
- logger.info(`当前${ freyrName }已经下载了:${ tools.#amCount }次`);
+ logger.info(`当前${freyrName}已经下载了:${tools.#amCount}次`);
// 定时清理
if (tools.#amCount >= 5) {
await deleteFolderRecursive(currentWorkingDirectory + "/am");
@@ -1689,29 +1694,29 @@ export class tools extends plugin {
const album = albumMatch ? albumMatch[1] : 'N/A';
const artist = artistMatch ? artistMatch[1] : 'N/A';
- return { title, album, artist };
+ return {title, album, artist};
}
// 链接总结
async linkShareSummary(e) {
// 判断是否有总结的条件
if (_.isEmpty(this.aiApiKey) || _.isEmpty(this.aiApiKey)) {
- e.reply(`没有配置 Kimi,无法为您总结!${ HELP_DOC }`)
+ e.reply(`没有配置 Kimi,无法为您总结!${HELP_DOC}`)
return true;
}
- const { name, summaryLink } = contentEstimator(e.msg);
+ const {name, summaryLink} = contentEstimator(e.msg);
const builder = await new OpenaiBuilder()
.setBaseURL(this.aiBaseURL)
.setApiKey(this.aiApiKey)
.setModel(this.aiModel)
.setPrompt(SUMMARY_PROMPT)
.build();
- e.reply(`识别:${ name },正在为您总结,请稍等...`, true, { recallMsg: 60 });
- const { ans: kimiAns, model } = await builder.kimi(summaryLink);
+ e.reply(`识别:${name},正在为您总结,请稍等...`, true, {recallMsg: 60});
+ const {ans: kimiAns, model} = await builder.kimi(summaryLink);
// 计算阅读时间
const stats = estimateReadingTime(kimiAns);
- e.reply(`当前 ${ name } 预计阅读时间: ${ stats.minutes } 分钟,总字数: ${ stats.words }`)
- const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`, kimiAns]);
+ e.reply(`当前 ${name} 预计阅读时间: ${stats.minutes} 分钟,总字数: ${stats.words}`)
+ const Msg = await this.makeForwardMsg(e, [`「R插件 x ${model}」联合为您总结内容:`, kimiAns]);
await e.reply(Msg);
return true;
}
@@ -1720,7 +1725,7 @@ export class tools extends plugin {
async pictureTranslate(e) {
// 判断是否有总结的条件
if (_.isEmpty(this.aiApiKey) || _.isEmpty(this.aiApiKey)) {
- e.reply(`没有配置 Kimi,无法为您总结!${ HELP_DOC }`)
+ e.reply(`没有配置 Kimi,无法为您总结!${HELP_DOC}`)
return true;
}
// logger.info(Bot.pickGroup(e.group_id, true))
@@ -1747,11 +1752,11 @@ export class tools extends plugin {
.setModel(this.aiModel)
.setPrompt(IMAGE_TRANSLATION_PROMPT)
.build();
- e.reply(`识别:图片翻译,请稍等...`, true, { recallMsg: 60 });
+ e.reply(`识别:图片翻译,请稍等...`, true, {recallMsg: 60});
const refImgDownloadPath = this.getCurDownloadPath(e);
await downloadImg(refImgUrl, refImgDownloadPath, "demo.png");
- const { ans: kimiAns, model } = await builder.openai_pic(`${ refImgDownloadPath }/demo.png`);
- const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您识别内容:`, kimiAns]);
+ const {ans: kimiAns, model} = await builder.openai_pic(`${refImgDownloadPath}/demo.png`);
+ const Msg = await this.makeForwardMsg(e, [`「R插件 x ${model}」联合为您识别内容:`, kimiAns]);
await e.reply(Msg);
return true;
}
@@ -1774,7 +1779,7 @@ export class tools extends plugin {
musicInfo = prompt + "-" + desc;
// 空判定
if (musicInfo.trim() === "-" || prompt === undefined || desc === undefined) {
- logger.info(`没有识别到QQ音乐小程序,帮助文档如下:${ HELP_DOC }`)
+ logger.info(`没有识别到QQ音乐小程序,帮助文档如下:${HELP_DOC}`)
return true;
}
} else {
@@ -1795,7 +1800,7 @@ export class tools extends plugin {
await this.uploadGroupFile(e, path);
await checkAndRemoveFile(path);
}).catch(err => {
- logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
+ logger.error(`下载音乐失败,错误信息为: ${err.message}`);
});
return true;
}
@@ -1815,7 +1820,7 @@ export class tools extends plugin {
await this.uploadGroupFile(e, path);
await checkAndRemoveFile(path);
}).catch(err => {
- logger.error(`下载音乐失败,错误信息为: ${ err.message }`);
+ logger.error(`下载音乐失败,错误信息为: ${err.message}`);
});
return true;
}
@@ -1852,7 +1857,7 @@ export class tools extends plugin {
),
),
]).then(data => {
- return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, `${ title }.mp4`);
+ return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, `${title}.mp4`);
});
}
@@ -1890,7 +1895,7 @@ export class tools extends plugin {
* @returns {string}
*/
getCurDownloadPath(e) {
- return `${ this.defaultPath }${ e.group_id || e.user_id }`
+ return `${this.defaultPath}${e.group_id || e.user_id}`
}
/**
@@ -1898,9 +1903,9 @@ export class tools extends plugin {
* @returns {{groupPath: string, target: string}}
*/
getGroupPathAndTarget() {
- const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`;
- const target = `${ groupPath }/temp.mp4`;
- return { groupPath, target };
+ const groupPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`;
+ const target = `${groupPath}/temp.mp4`;
+ return {groupPath, target};
}
/**
@@ -1913,7 +1918,7 @@ export class tools extends plugin {
*/
async downloadVideo(url, isProxy = false, headers = null, numThreads = 1) {
// 构造群信息参数
- const { groupPath, target } = this.getGroupPathAndTarget.call(this);
+ const {groupPath, target} = this.getGroupPathAndTarget.call(this);
await mkdirIfNotExists(groupPath);
// 构造header部分内容
const userAgent = "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";
@@ -1924,10 +1929,10 @@ export class tools extends plugin {
const proxyOption = {
...(isProxy && {
httpAgent: tunnel.httpOverHttp({
- proxy: { host: this.proxyAddr, port: this.proxyPort },
+ proxy: {host: this.proxyAddr, port: this.proxyPort},
}),
httpsAgent: tunnel.httpsOverHttp({
- proxy: { host: this.proxyAddr, port: this.proxyPort },
+ proxy: {host: this.proxyAddr, port: this.proxyPort},
}),
}),
}
@@ -1962,11 +1967,11 @@ export class tools extends plugin {
* @returns {Promise<*>}
*/
async downloadVideoWithMultiThread(downloadVideoParams, numThreads) {
- const { url, headers, userAgent, proxyOption, target, groupPath } = downloadVideoParams;
+ const {url, headers, userAgent, proxyOption, target, groupPath} = downloadVideoParams;
try {
// Step 1: 请求视频资源获取 Content-Length
const headRes = await axios.head(url, {
- headers: headers || { "User-Agent": userAgent },
+ headers: headers || {"User-Agent": userAgent},
...proxyOption
});
const contentLength = headRes.headers['content-length'];
@@ -1989,7 +1994,7 @@ export class tools extends plugin {
const partAxiosConfig = {
headers: {
"User-Agent": userAgent,
- "Range": `bytes=${ start }-${ end }`
+ "Range": `bytes=${start}-${end}`
},
responseType: "stream",
...proxyOption
@@ -1997,12 +2002,12 @@ export class tools extends plugin {
promises.push(axios.get(url, partAxiosConfig).then(res => {
return new Promise((resolve, reject) => {
- const partPath = `${ target }.part${ i }`;
- logger.mark(`[R插件][视频下载引擎] 正在下载 part${ i }`)
+ const partPath = `${target}.part${i}`;
+ logger.mark(`[R插件][视频下载引擎] 正在下载 part${i}`)
const writer = fs.createWriteStream(partPath);
res.data.pipe(writer);
writer.on("finish", () => {
- logger.mark(`[R插件][视频下载引擎] part${ i + 1 } 下载完成`); // 记录线程下载完成
+ logger.mark(`[R插件][视频下载引擎] part${i + 1} 下载完成`); // 记录线程下载完成
resolve(partPath);
});
writer.on("error", reject);
@@ -2015,11 +2020,11 @@ export class tools extends plugin {
// Step 4: 合并下载的文件部分
await checkAndRemoveFile(target); // 确保目标文件不存在
- const writer = fs.createWriteStream(target, { flags: 'a' });
+ const writer = fs.createWriteStream(target, {flags: 'a'});
for (const partPath of parts) {
await new Promise((resolve, reject) => {
const reader = fs.createReadStream(partPath);
- reader.pipe(writer, { end: false });
+ reader.pipe(writer, {end: false});
reader.on('end', () => {
fs.unlinkSync(partPath); // 删除部分文件
resolve();
@@ -2032,7 +2037,7 @@ export class tools extends plugin {
return groupPath;
} catch (err) {
- logger.error(`下载视频发生错误!\ninfo:${ err }`);
+ logger.error(`下载视频发生错误!\ninfo:${err}`);
}
}
@@ -2043,9 +2048,9 @@ export class tools extends plugin {
* @param downloadVideoParams
*/
async downloadVideoWithSingleThread(downloadVideoParams) {
- const { url, headers, userAgent, proxyOption, target, groupPath } = downloadVideoParams;
+ const {url, headers, userAgent, proxyOption, target, groupPath} = downloadVideoParams;
const axiosConfig = {
- headers: headers || { "User-Agent": userAgent },
+ headers: headers || {"User-Agent": userAgent},
responseType: "stream",
...proxyOption
};
@@ -2054,7 +2059,7 @@ export class tools extends plugin {
await checkAndRemoveFile(target);
const res = await axios.get(url, axiosConfig);
- logger.mark(`开始下载: ${ url }`);
+ logger.mark(`开始下载: ${url}`);
const writer = fs.createWriteStream(target);
res.data.pipe(writer);
@@ -2063,7 +2068,7 @@ export class tools extends plugin {
writer.on("error", reject);
});
} catch (err) {
- logger.error(`下载视频发生错误!\ninfo:${ err }`);
+ logger.error(`下载视频发生错误!\ninfo:${err}`);
}
}
@@ -2129,7 +2134,7 @@ export class tools extends plugin {
const stats = fs.statSync(path);
const videoSize = (stats.size / (1024 * 1024)).toFixed(2);
if (videoSize > videoSizeLimit) {
- e.reply(`当前视频大小:${ videoSize }MB,\n大于设置的最大限制,\n改为上传群文件`);
+ e.reply(`当前视频大小:${videoSize}MB,\n大于设置的最大限制,\n改为上传群文件`);
await this.uploadGroupFile(e, path);
} else {
e.reply(segment.video(path));
@@ -2177,14 +2182,14 @@ export class tools extends plugin {
if (typeof (forwardMsg.data) === 'object') {
let detail = forwardMsg.data?.meta?.detail
if (detail) {
- detail.news = [{ text: dec }]
+ detail.news = [{text: dec}]
}
} else {
forwardMsg.data = forwardMsg.data
.replace('', '')
.replace(/\n/g, '')
.replace(/
(.+?)<\/title>/g, '___')
- .replace(/___+/, `${ dec }`)
+ .replace(/___+/, `${dec}`)
}
}