diff --git a/apps/tools.js b/apps/tools.js index 3e10502..b2f508f 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -31,10 +31,12 @@ import { BILI_EP_INFO, BILI_ONLINE, BILI_SSID_INFO, + BILI_STREAM_FLV, BILI_STREAM_INFO, BILI_SUMMARY, DY_COMMENT, - DY_INFO, DY_LIVE_INFO, + DY_INFO, + DY_LIVE_INFO, DY_TOUTIAO_INFO, GENERAL_REQ_LINK, HIBI_API_SERVICE, @@ -75,7 +77,7 @@ import { downloadImg, estimateReadingTime, formatBiliInfo, - retryAxiosReq, saveJsonToFile, + retryAxiosReq, secondsToTime, testProxy, truncateString, @@ -124,7 +126,7 @@ export class tools extends plugin { priority: 300, rule: [ { - reg: `^(翻|trans)[${tools.Constants.existsTransKey}]`, + reg: `^(翻|trans)[${ tools.Constants.existsTransKey }]`, fnc: "trans", }, { @@ -227,7 +229,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.identifyPrefix = this.toolsConfig.identifyPrefix; // 加载哔哩哔哩配置 @@ -308,7 +310,7 @@ export class tools extends plugin { const urlRex = /(http:\/\/|https:\/\/)(v|live).douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/; // 检测无效链接,例如:v.douyin.com if (!urlRex.test(e.msg)) { - e.reply(`检测到这是一个无效链接,无法解析抖音${HELP_DOC}`); + e.reply(`检测到这是一个无效链接,无法解析抖音${ HELP_DOC }`); return; } // 获取链接 @@ -323,7 +325,7 @@ export class tools extends plugin { /live\/(\d+)/.exec(douUrl)?.[1]; // 当前版本需要填入cookie if (_.isEmpty(this.douyinCookie) || _.isEmpty(douId)) { - e.reply(`检测到没有Cookie 或者 这是一个无效链接,无法解析抖音${HELP_DOC}`); + e.reply(`检测到没有Cookie 或者 这是一个无效链接,无法解析抖音${ HELP_DOC }`); return; } // 以下是更新了很多次的抖音API历史,且用且珍惜 @@ -343,7 +345,7 @@ export class tools extends plugin { headers["User-Agent"], ); // const param = resp.data.result[0].paramsencode; - const resDyApi = `${dyApi}&a_bogus=${abParam}`; + const resDyApi = `${ dyApi }&a_bogus=${ abParam }`; headers['Referer'] = `https://www.douyin.com/` // 定义一个dy请求 const dyResponse = () => axios.get(resDyApi, { @@ -357,29 +359,10 @@ export class tools extends plugin { if (douUrl.includes("live")) { const item = await data.data.data?.[0]; const { title, cover, user_count_str, stream_url } = item; - const dySendContent = `${this.identifyPrefix}识别:抖音直播,${title}` - e.reply([segment.image(cover?.url_list?.[0]), dySendContent, `\n🏄‍♂️在线人数:${user_count_str}人正在观看`]); + const dySendContent = `${ this.identifyPrefix }识别:抖音直播,${ title }` + e.reply([segment.image(cover?.url_list?.[0]), dySendContent, `\n🏄‍♂️在线人数:${ user_count_str }人正在观看`]); // 下载10s的直播流 - const outputFilePath = `${this.getCurDownloadPath(e)}/stream_10s.flv` - const file = fs.createWriteStream(outputFilePath); - axios.get(stream_url?.flv_pull_url?.FULL_HD1, { - responseType: 'stream' - }).then(response => { - logger.info("正在下载直播流..."); - // 将流数据写入文件 - response.data.pipe(file); - - // 设置 10 秒后停止下载 - setTimeout(() => { - logger.info('直播下载10秒钟到,停止下载。'); - response.data.destroy(); // 销毁流 - e.reply(segment.video(outputFilePath)); - file.close(); // 关闭文件流 - }, 10000); // 10秒 = 10000毫秒 - }).catch(error => { - console.error('下载失败:', error.message); - fs.unlink(outputFilePath, () => {}); // 下载失败时删除文件 - }); + this.sendStreamSegment(e, stream_url?.flv_pull_url?.HD1); return; } const item = await data.aweme_detail; @@ -400,20 +383,20 @@ export class tools extends plugin { const dyDuration = Math.trunc(duration / 1000); const durationThreshold = this.biliDuration; // 一些共同发送内容 - let dySendContent = `${this.identifyPrefix}识别:抖音,${item.author.nickname}\n📝 简介:${item.desc}`; + let dySendContent = `${ this.identifyPrefix }识别:抖音,${ item.author.nickname }\n📝 简介:${ item.desc }`; if (dyDuration >= durationThreshold) { // 超过阈值,不发送的情况 // 封面 const dyCover = cover.url_list?.pop(); // logger.info(cover.url_list); dySendContent += `\n - ${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${Math.trunc(dyDuration / 60)}分钟,\n大于管理员设置的最大时长 ${durationThreshold / 60} 分钟!`; + ${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ Math.trunc(dyDuration / 60) }分钟,\n大于管理员设置的最大时长 ${ durationThreshold / 60 } 分钟!`; e.reply([segment.image(dyCover), dySendContent]); // 如果开启评论的就调用 await this.douyinComment(e, douId, headers); return; } - e.reply(`${dySendContent}`); + e.reply(`${ dySendContent }`); // 分辨率判断是否压缩 const resolution = this.douyinCompression ? "720p" : "1080p"; // 使用今日头条 CDN 进一步加快解析速度 @@ -432,14 +415,14 @@ export class tools extends plugin { }*/ // logger.info(resUrl); - const path = `${this.getCurDownloadPath(e)}/temp.mp4`; + const path = `${ this.getCurDownloadPath(e) }/temp.mp4`; // 加入队列 await this.downloadVideo(resUrl).then(() => { this.sendVideoToUpload(e, path) }); } else if (urlType === "image") { // 发送描述 - e.reply(`${this.identifyPrefix}识别:抖音, ${item.desc}`); + e.reply(`${ this.identifyPrefix }识别:抖音, ${ item.desc }`); // 无水印图片列表 let no_watermark_image_list = []; // 有水印图片列表 @@ -462,11 +445,41 @@ 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; } + /** + * 下载直播片段 + * @param e + * @param stream_url + * @param second + */ + sendStreamSegment(e, stream_url, second = 10) { + const outputFilePath = `${ this.getCurDownloadPath(e) }/stream_10s.flv` + const file = fs.createWriteStream(outputFilePath); + axios.get(stream_url, { + responseType: 'stream' + }).then(response => { + logger.info("[R插件][发送直播流] 正在下载直播流..."); + // 将流数据写入文件 + response.data.pipe(file); + + // 设置 10 秒后停止下载 + setTimeout(() => { + logger.info('[R插件][发送直播流] 直播下载10秒钟到,停止下载!'); + response.data.destroy(); // 销毁流 + e.reply(segment.video(outputFilePath)); + file.close(); // 关闭文件流 + }, second * 1000); // 10秒 = 10000毫秒 + }).catch(error => { + console.error('下载失败:', error.message); + fs.unlink(outputFilePath, () => { + }); // 下载失败时删除文件 + }); + } + /** * 获取 DY 评论 * @param e @@ -482,7 +495,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) @@ -517,9 +530,9 @@ export class tools extends plugin { const path = this.getCurDownloadPath(e); await checkAndRemoveFile(path + "/temp.mp4"); const title = ytDlpGetTilt(url, isOversea, this.myProxy); - e.reply(`${this.identifyPrefix}识别:TikTok,视频下载中请耐心等待 \n${title}`); + e.reply(`${ this.identifyPrefix }识别:TikTok,视频下载中请耐心等待 \n${ title }`); await ytDlpHelper(path, cleanedTiktokUrl, isOversea, this.myProxy); - await this.sendVideoToUpload(e, `${path}/temp.mp4`); + await this.sendVideoToUpload(e, `${ path }/temp.mp4`); return true; } @@ -534,7 +547,7 @@ export class tools extends plugin { // 检查路径是否存在文件夹 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)) @@ -551,7 +564,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) } // 短号处理 @@ -581,9 +594,18 @@ export class tools extends plugin { const streamId = parsedUrl.pathname.match(idPattern)?.[1]; // logger.info(streamId) // 提取相关信息 - const liveData = await this.getBiliStream(streamId); + const liveData = await this.getBiliStreamInfo(streamId); // saveJsonToFile(liveData.data); - const { title, user_cover, keyframe, description, tags, live_time, parent_area_name, area_name } = liveData.data.data; + const { + title, + user_cover, + keyframe, + description, + tags, + live_time, + parent_area_name, + area_name + } = liveData.data.data; e.reply([ segment.image(user_cover), segment.image(keyframe), @@ -594,6 +616,9 @@ export class tools extends plugin { `${ live_time ? `⏰ 直播时间:${ live_time }` : '' }`, ].filter(item => item.trim() !== "").join("\n") ]); + const streamData = await this.getBiliStream(streamId); + const { url: streamUrl } = streamData.data.data.durl[0]; + await this.sendStreamSegment(e, streamUrl); return true; } // 处理专栏 @@ -611,7 +636,7 @@ export class tools extends plugin { return true; } // 创建文件,如果不存在, - const path = `${this.getCurDownloadPath(e)}/`; + const path = `${ this.getCurDownloadPath(e) }/`; await mkdirIfNotExists(path); // 处理番剧 if (url.includes("play\/ep") || url.includes("play\/ss")) { @@ -619,7 +644,7 @@ export class tools extends plugin { // 如果使用了BBDown && 没有填写session 就放开下载 if (this.biliUseBBDown) { // 下载文件 - await this.biliDownloadStrategy(e, `https://www.bilibili.com/bangumi/play/ep${ep}`, path); + await this.biliDownloadStrategy(e, `https://www.bilibili.com/bangumi/play/ep${ ep }`, path); } return true; } @@ -643,7 +668,7 @@ export class tools extends plugin { // 限制视频解析 if (isLimitDuration) { const durationInMinutes = (curDuration / 60).toFixed(0); - biliInfo.push(`${DIVIDING_LINE.replace('{}', '限制说明')}\n当前视频时长约:${durationInMinutes}分钟,\n大于管理员设置的最大时长 ${this.biliDuration / 60} 分钟!`); + biliInfo.push(`${ DIVIDING_LINE.replace('{}', '限制说明') }\n当前视频时长约:${ durationInMinutes }分钟,\n大于管理员设置的最大时长 ${ this.biliDuration / 60 } 分钟!`); e.reply(biliInfo); return true; } else { @@ -681,21 +706,21 @@ export class tools extends plugin { "弹幕数量": danmaku, "评论": reply }; - combineContent += `\n${formatBiliInfo(dataProcessMap)}`; + combineContent += `\n${ formatBiliInfo(dataProcessMap) }`; } // 是否显示简介 if (this.biliDisplayIntro) { // 过滤简介中的一些链接 const filteredDesc = await filterBiliDescLink(desc); - combineContent += `\n📝 简介:${truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT)}`; + combineContent += `\n📝 简介:${ truncateString(filteredDesc, this.toolsConfig.biliIntroLenLimit || BILI_DEFAULT_INTRO_LEN_LIMIT) }`; } // 是否显示在线人数 if (this.biliDisplayOnline) { // 拼接在线人数 const onlineTotal = await this.biliOnlineTotal(bvid, cid); - combineContent += `\n🏄‍♂️️ 当前视频有 ${onlineTotal.total} 人在观看,其中 ${onlineTotal.count} 人在网页端观看`; + combineContent += `\n🏄‍♂️️ 当前视频有 ${ onlineTotal.total } 人在观看,其中 ${ onlineTotal.count } 人在网页端观看`; } - let biliInfo = [`${this.identifyPrefix}识别:哔哩哔哩:${title}`, combineContent] + let biliInfo = [`${ this.identifyPrefix }识别:哔哩哔哩:${ title }`, combineContent] // 是否显示封面 if (this.biliDisplayCover) { // 加入图片 @@ -742,10 +767,10 @@ export class tools extends plugin { const title = result.title; e.reply([ segment.image(resp.result.cover), - `${this.identifyPrefix}识别:哔哩哔哩番剧,${title}\n🎯 评分: ${result?.rating?.score ?? '-'} / ${result?.rating?.count ?? '-'}\n📺 ${result.new_ep.desc}, ${result.seasons[0].new_ep.index_show}\n`, - `${formatBiliInfo(dataProcessMap)}`, - `\n\n🪶 在线观看: ${await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + title)}`, - `\n🌸 在线观看: ${await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + title)}` + `${ this.identifyPrefix }识别:哔哩哔哩番剧,${ title }\n🎯 评分: ${ result?.rating?.score ?? '-' } / ${ result?.rating?.count ?? '-' }\n📺 ${ result.new_ep.desc }, ${ result.seasons[0].new_ep.index_show }\n`, + `${ formatBiliInfo(dataProcessMap) }`, + `\n\n🪶 在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK + title) }`, + `\n🌸 在线观看: ${ await urlTransformShortLink(ANIME_SERIES_SEARCH_LINK2 + title) }` ], true); return ep; } @@ -761,7 +786,7 @@ export class tools extends plugin { return this.queue.add(async () => { // =================以下是调用BBDown的逻辑===================== // 下载视频和音频 - const tempPath = `${path}temp`; + const tempPath = `${ path }temp`; // 检测是否开启BBDown if (this.biliUseBBDown) { // 检测环境的 BBDown @@ -769,7 +794,7 @@ export class tools extends plugin { // 存在 BBDown if (isExistBBDown) { // 删除之前的文件 - await checkAndRemoveFile(`${tempPath}.mp4`); + await checkAndRemoveFile(`${ tempPath }.mp4`); // 下载视频 await startBBDown(url, path, { biliSessData: this.biliSessData, @@ -778,7 +803,7 @@ export class tools extends plugin { biliResolution: this.biliResolution, }); // 发送视频 - return this.sendVideoToUpload(e, `${tempPath}.mp4`); + return this.sendVideoToUpload(e, `${ tempPath }.mp4`); } e.reply("🚧 R插件提醒你:开启但未检测到当前环境有【BBDown】,即将使用默认下载方式 ( ◡̀_◡́)ᕤ"); } @@ -790,7 +815,7 @@ export class tools extends plugin { await this.downBili(tempPath, data.videoUrl, data.audioUrl); // 上传视频 - return this.sendVideoToUpload(e, `${tempPath}.mp4`); + return this.sendVideoToUpload(e, `${ tempPath }.mp4`); } catch (err) { // 错误处理 logger.error('[R插件][哔哩哔哩视频发送]下载错误,具体原因为:', err); @@ -839,7 +864,7 @@ export class tools extends plugin { const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0]; getDynamic(dynamicId, session).then(async resp => { if (resp.dynamicSrc.length > 0) { - e.reply(`${this.identifyPrefix}识别:哔哩哔哩动态, ${resp.dynamicDesc}`); + e.reply(`${ this.identifyPrefix }识别:哔哩哔哩动态, ${ resp.dynamicDesc }`); let dynamicSrcMsg = []; resp.dynamicSrc.forEach(item => { dynamicSrcMsg.push({ @@ -872,7 +897,7 @@ export class tools extends plugin { 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) @@ -884,7 +909,7 @@ export class tools extends plugin { let resReply = ""; // 总体总结 if (summary) { - resReply = `\n摘要:${summary}\n` + resReply = `\n摘要:${ summary }\n` } // 分段总结 if (outline) { @@ -895,9 +920,9 @@ export class tools extends plugin { const specificContent = keyPoint.map(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(""); } @@ -910,8 +935,21 @@ export class tools extends plugin { * @param liveId * @returns {Promise<*>} */ + async getBiliStreamInfo(liveId) { + return axios.get(`${ BILI_STREAM_INFO }?room_id=${ liveId }`, { + headers: { + 'User-Agent': COMMON_USER_AGENT, + } + }); + } + + /** + * 获取直播流 + * @param liveId + * @returns {Promise<*>} + */ async getBiliStream(liveId) { - return axios.get(`${BILI_STREAM_INFO}?room_id=${liveId}`, { + return axios.get(`${ BILI_STREAM_FLV }?cid=${ liveId }`, { headers: { 'User-Agent': COMMON_USER_AGENT, } @@ -940,14 +978,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(`${this.identifyPrefix}识别:小蓝鸟学习版,${resp.data.text}`); - const downloadPath = `${this.getCurDownloadPath(e)}`; + e.reply(`${ this.identifyPrefix }识别:小蓝鸟学习版,${ resp.data.text }`); + const downloadPath = `${ this.getCurDownloadPath(e) }`; // 创建文件夹(如果没有过这个群) if (!fs.existsSync(downloadPath)) { mkdirsSync(downloadPath); @@ -962,7 +1000,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`)); }, ); } @@ -1012,7 +1050,7 @@ export class tools extends plugin { } // 提取视频 let videoUrl = GENERAL_REQ_LINK.link.replace("{}", twitterUrl); - e.reply(`${this.identifyPrefix}识别:小蓝鸟学习版`); + e.reply(`${ this.identifyPrefix }识别:小蓝鸟学习版`); const config = { headers: { 'Accept': 'ext/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.7', @@ -1062,24 +1100,24 @@ 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] }`; } else if (inputMsg.includes("ac")) { // 如果是 inputMsg = "https://www.acfun.cn/v/" + /ac\d+/.exec(inputMsg)[0]; } parseUrl(inputMsg).then(res => { - e.reply(`${this.identifyPrefix}识别:猴山,${res.videoName}`); + e.reply(`${ this.identifyPrefix }识别:猴山,${ 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`) }); }); }); @@ -1121,14 +1159,14 @@ 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\n${HELP_DOC}`); + e.reply(`2024-8-2后反馈必须使用ck,不然无法解析请填写相关ck\n${ HELP_DOC }`); return; } // 获取信息 - fetch(`${XHS_REQ_LINK}${id}`, { + fetch(`${ XHS_REQ_LINK }${ id }`, { headers: XHS_NO_WATERMARK_HEADER, }).then(async resp => { const xhsHtml = await resp.text(); @@ -1140,7 +1178,7 @@ export class tools extends plugin { if (type === "video") { // 封面 const cover = noteData.imageList?.[0].urlDefault; - e.reply([segment.image(cover), `${this.identifyPrefix}识别:小红书, ${title}\n${desc}`]); + e.reply([segment.image(cover), `${ this.identifyPrefix }识别:小红书, ${ title }\n${ desc }`]); // ⚠️ (暂时废弃)构造xhs视频链接(有水印) const xhsVideoUrl = noteData.video.media.stream.h264?.[0]?.masterUrl; @@ -1150,20 +1188,20 @@ export class tools extends plugin { 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(`${this.identifyPrefix}识别:小红书, ${title}\n${desc}`); + e.reply(`${ this.identifyPrefix }识别:小红书, ${ title }\n${ desc }`); const imagePromises = []; // 使用 for..of 循环处理异步下载操作 for (let [index, item] of noteData.imageList.entries()) { imagePromises.push(downloadImg({ img: item.urlDefault, dir: downloadPath, - fileName: `${index}.png`, + fileName: `${ index }.png`, downloadMethod: this.biliDownloadMethod, })); } @@ -1198,14 +1236,14 @@ export class tools extends plugin { /(?=mvId).*?(?=&)/.exec(e.msg.trim())?.[0].replace("mvId=", ""); const { name, album, artist, albumPic120, categorys } = await getBodianMusicInfo(id); e.reply([ - `${this.identifyPrefix}识别:波点音乐,${name}-${album}-${artist}\n标签:${categorys + `${ this.identifyPrefix }识别:波点音乐,${ 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)); // 上传群文件 @@ -1273,11 +1311,11 @@ export class tools extends plugin { }) ]); const { name: mvName, artistName: mvArtist, cover: mvCover } = mvDetailData.data?.data; - e.reply([segment.image(mvCover), `${this.identifyPrefix}识别:网易云MV,${mvName} - ${mvArtist}`]); + e.reply([segment.image(mvCover), `${ this.identifyPrefix }识别:网易云MV,${ mvName } - ${ mvArtist }`]); // logger.info(mvUrlData.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; } @@ -1296,14 +1334,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 cleanFilename(`${song?.name}-${song?.ar?.[0].name}`); + return cleanFilename(`${ song?.name }-${ song?.ar?.[0].name }`); }); // 一般这个情况是VIP歌曲 (如果没有url或者是国内, 国内全走临时接口,后续如果不要删除逻辑'!isOversea ||') if (!isOversea || url == null) { url = await this.musicTempApi(e, title, "网易云音乐"); } else { // 不是VIP歌曲,直接识别完就下一步 - e.reply(`${this.identifyPrefix}识别:网易云音乐,${title}`); + e.reply(`${ this.identifyPrefix }识别:网易云音乐,${ title }`); } // 动态判断后缀名 const extensionPattern = /\.([a-zA-Z0-9]+)$/; @@ -1317,7 +1355,7 @@ export class tools extends plugin { // 删除文件 await checkAndRemoveFile(path); }).catch(err => { - logger.error(`下载音乐失败,错误信息为: ${err.message}`); + logger.error(`下载音乐失败,错误信息为: ${ err.message }`); }); }); return true; @@ -1341,7 +1379,7 @@ export class tools extends plugin { // ??后的内容是适配`QQ_MUSIC_TEMP_API`、最后是汽水 const url = vipMusicData.data?.music_url ?? vipMusicData.data?.data?.music_url ?? vipMusicData.data?.music; const cover = vipMusicData.data?.cover ?? vipMusicData.data?.data?.cover ?? vipMusicData.data?.cover; - await e.reply([segment.image(cover), `${this.identifyPrefix}识别:${musicType},${messageTitle}`]); + await e.reply([segment.image(cover), `${ this.identifyPrefix }识别:${ musicType },${ messageTitle }`]); return url; } @@ -1373,13 +1411,13 @@ export class tools extends plugin { "User-Agent": COMMON_USER_AGENT, "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", "cookie": "_T_WM=40835919903; WEIBOCN_FROM=1110006030; MLOGIN=0; XSRF-TOKEN=4399c8", - "Referer": `https://m.weibo.cn/detail/${id}`, + "Referer": `https://m.weibo.cn/detail/${ id }`, } }) .then(async resp => { const wbData = resp.data.data; const { text, status_title, source, region_name, pics, page_info } = wbData; - e.reply(`${this.identifyPrefix}识别:微博,${text.replace(/<[^>]+>/g, '')}\n${status_title}\n${source}\t${region_name ?? ''}`); + e.reply(`${ this.identifyPrefix }识别:微博,${ text.replace(/<[^>]+>/g, '') }\n${ status_title }\n${ source }\t${ region_name ?? '' }`); if (pics) { // 下载图片并格式化消息 const imagesPromise = pics.map(item => { @@ -1423,7 +1461,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/", }, 1).then(path => { - this.sendVideoToUpload(e, `${path}/temp.mp4`) + this.sendVideoToUpload(e, `${ path }/temp.mp4`) }); } catch (err) { e.reply("视频资源获取失败"); @@ -1442,7 +1480,7 @@ export class tools extends plugin { async general(e) { try { const adapter = await GeneralLinkAdapter.create(e.msg); - e.reply(`${this.identifyPrefix}识别:${adapter.name}${adapter.desc ? `, ${adapter.desc}` : ''}`); + e.reply(`${ this.identifyPrefix }识别:${ adapter.name }${ adapter.desc ? `, ${ adapter.desc }` : '' }`); logger.mark(adapter); if (adapter.images && adapter.images.length > 0) { const images = adapter.images.map(item => { @@ -1458,7 +1496,7 @@ export class tools extends plugin { const url = adapter.video; this.downloadVideo(url).then(path => { logger.info(path); - this.sendVideoToUpload(e, `${path}/temp.mp4`) + this.sendVideoToUpload(e, `${ path }/temp.mp4`) }); } else { e.reply("解析失败:无法获取到资源"); @@ -1494,9 +1532,9 @@ export class tools extends plugin { const path = this.getCurDownloadPath(e); await checkAndRemoveFile(path + "/temp.mp4") const title = await ytDlpGetTilt(url, isOversea, this.myProxy); - e.reply(`${this.identifyPrefix}识别:油管,视频下载中请耐心等待 \n${title}`); + e.reply(`${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n${ title }`); await ytDlpHelper(path, url, isOversea, this.myProxy, true); - this.sendVideoToUpload(e, `${path}/temp.mp4`); + this.sendVideoToUpload(e, `${ path }/temp.mp4`); } catch (error) { console.error(error); throw error; // Rethrow the error so it can be handled by the caller @@ -1542,7 +1580,7 @@ export class tools extends plugin { } catch (e) { realContent = content; } - const normalMsg = `${this.identifyPrefix}识别:米游社,${subject}\n${realContent?.describe || ""}`; + const normalMsg = `${ this.identifyPrefix }识别:米游社,${ subject }\n${ realContent?.describe || "" }`; const replyMsg = cover ? [segment.image(cover), normalMsg] : normalMsg; e.reply(replyMsg); // 图片 @@ -1566,7 +1604,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; } @@ -1611,10 +1649,10 @@ export class tools extends plugin { const cover = firstFeed.images[0].url; const noWatermarkDownloadUrl = firstFeed.video_url; - e.reply([segment.image(cover), `${this.identifyPrefix}识别:微视,${title}`]); + e.reply([segment.image(cover), `${ this.identifyPrefix }识别:微视,${ title }`]); this.downloadVideo(noWatermarkDownloadUrl).then(path => { - this.sendVideoToUpload(e, `${path}/temp.mp4`) + this.sendVideoToUpload(e, `${ path }/temp.mp4`) }); } catch (err) { logger.error(err); @@ -1663,7 +1701,7 @@ export class tools extends plugin { images, }; - e.reply(`${this.identifyPrefix}识别:最右,${shortVideoInfo.authorName}\n${shortVideoInfo.title}`) + e.reply(`${ this.identifyPrefix }识别:最右,${ shortVideoInfo.authorName }\n${ shortVideoInfo.title }`) if (shortVideoInfo.images.length > 0) { const replyImages = shortVideoInfo.images.map(item => { @@ -1677,7 +1715,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) { @@ -1699,17 +1737,17 @@ export class tools extends plugin { // 检测是否存在框架 const isExistFreyr = await checkToolInCurEnv("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()); // 兜底策略 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/", @@ -1726,7 +1764,7 @@ export class tools extends plugin { // 国内服务器解决方案 if (!isOversea) { // 临时接口 - 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 => { // 发送语音 @@ -1735,22 +1773,22 @@ export class tools extends plugin { await this.uploadGroupFile(e, path); await checkAndRemoveFile(path); }).catch(err => { - logger.error(`下载音乐失败,错误信息为: ${err.message}`); + logger.error(`下载音乐失败,错误信息为: ${ err.message }`); }); } else { // freyr 逻辑 - e.reply(`${this.identifyPrefix}识别:${freyrName},${title}--${artist}`); + e.reply(`${ this.identifyPrefix }识别:${ freyrName },${ title }--${ artist }`); // 检查目录是否存在 const musicPath = currentWorkingDirectory + "/am/" + artist + "/" + album; // 找到音频文件 const mediaFiles = await getMediaFilesAndOthers(musicPath); for (let other of mediaFiles.others) { - await this.uploadGroupFile(e, `${musicPath}/${other}`); + await this.uploadGroupFile(e, `${ musicPath }/${ other }`); } } // 计数 tools.#amCount += 1; - logger.info(`当前${freyrName}已经下载了:${tools.#amCount}次`); + logger.info(`当前${ freyrName }已经下载了:${ tools.#amCount }次`); // 定时清理 if (tools.#amCount >= 5) { await deleteFolderRecursive(currentWorkingDirectory + "/am"); @@ -1801,13 +1839,13 @@ export class tools extends plugin { .setModel(this.aiModel) .setPrompt(SUMMARY_PROMPT) .build(); - e.reply(`${this.identifyPrefix}识别:${name},正在为您总结,请稍等...`, true, { recallMsg: MESSAGE_RECALL_TIME }); + e.reply(`${ this.identifyPrefix }识别:${ name },正在为您总结,请稍等...`, true, { recallMsg: MESSAGE_RECALL_TIME }); const { ans: kimiAns, model } = await builder.kimi(summaryLink); // 计算阅读时间 const stats = estimateReadingTime(kimiAns); const titleMatch = kimiAns.match(/(Title|标题)([::])\s*(.*?)\n/)?.[3]; - e.reply(`《${titleMatch}》 预计阅读时间: ${stats.minutes} 分钟,总字数: ${stats.words}`) - const Msg = await Bot.makeForwardMsg(textArrayToMakeForward(e, [`「R插件 x ${model}」联合为您总结内容:`, kimiAns])); + e.reply(`《${ titleMatch }》 预计阅读时间: ${ stats.minutes } 分钟,总字数: ${ stats.words }`) + const Msg = await Bot.makeForwardMsg(textArrayToMakeForward(e, [`「R插件 x ${ model }」联合为您总结内容:`, kimiAns])); await e.reply(Msg); return true; } @@ -1822,7 +1860,7 @@ export class tools extends plugin { async tempSummary(name, summaryLink, e) { const content = await llmRead(summaryLink); const titleMatch = content.match(/Title:\s*(.*?)\n/)?.[1]; - e.reply(`${this.identifyPrefix}识别:${name} - ${titleMatch},正在为您总结,请稍等...`, true); + e.reply(`${ this.identifyPrefix }识别:${ name } - ${ titleMatch },正在为您总结,请稍等...`, true); const summary = await deepSeekChat(content, SUMMARY_PROMPT); const Msg = await Bot.makeForwardMsg(textArrayToMakeForward(e, [`「R插件 x DeepSeek」联合为您总结内容:`, summary])); await e.reply(Msg); @@ -1846,7 +1884,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 { @@ -1856,7 +1894,7 @@ export class tools extends plugin { } // 删除特殊字符 musicInfo = cleanFilename(musicInfo); - logger.info(`[R插件][qqMusic] 识别音乐为:${musicInfo}`); + logger.info(`[R插件][qqMusic] 识别音乐为:${ musicInfo }`); // 使用临时接口下载 const url = await this.musicTempApi(e, musicInfo, "QQ音乐"); // 下载音乐 @@ -1867,7 +1905,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; } @@ -1876,7 +1914,7 @@ export class tools extends plugin { async qishuiMusic(e) { const normalRegex = /^(.*?)\s*https?:\/\//; const musicInfo = normalRegex.exec(e.msg)?.[1].trim().replace("@汽水音乐", ""); - logger.info(`[R插件][qishuiMusic] 识别音乐为:${musicInfo}`); + logger.info(`[R插件][qishuiMusic] 识别音乐为:${ musicInfo }`); // 使用临时接口下载 const url = await this.musicTempApi(e, musicInfo, "汽水音乐"); // 下载音乐 @@ -1887,7 +1925,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; } @@ -1907,7 +1945,7 @@ export class tools extends plugin { // 检查当前环境 const isExistTdl = await checkToolInCurEnv("tdl"); if (!isExistTdl) { - e.reply(`未检测到必要的环境,无法解析小飞机${HELP_DOC}`); + e.reply(`未检测到必要的环境,无法解析小飞机${ HELP_DOC }`); return; } const url = urlRex.exec(e.msg)[0]; @@ -1917,8 +1955,8 @@ export class tools extends plugin { e.reply("文件已保存到 Save Messages!"); return true; } - e.reply(`${this.identifyPrefix}识别:小飞机(学习版)`); - const tgSavePath = `${this.getCurDownloadPath(e)}/tg`; + e.reply(`${ this.identifyPrefix }识别:小飞机(学习版)`); + const tgSavePath = `${ this.getCurDownloadPath(e) }/tg`; // 如果没有文件夹则创建 await mkdirIfNotExists(tgSavePath); // 删除之前的文件 @@ -1928,7 +1966,7 @@ export class tools extends plugin { const mediaFiles = await getMediaFilesAndOthers(tgSavePath); if (mediaFiles.images.length > 0) { const imagesData = mediaFiles.images.map(item => { - const fileContent = fs.readFileSync(`${tgSavePath}/${item}`); + const fileContent = fs.readFileSync(`${ tgSavePath }/${ item }`); return { message: segment.image(fileContent), nickname: e.sender.card || e.user_id, @@ -1938,11 +1976,11 @@ export class tools extends plugin { e.reply(await Bot.makeForwardMsg(imagesData), true, { recallMsg: MESSAGE_RECALL_TIME }); } else if (mediaFiles.videos.length > 0) { for (const item of mediaFiles.videos) { - await this.sendVideoToUpload(e, `${tgSavePath}/${item}`); + await this.sendVideoToUpload(e, `${ tgSavePath }/${ item }`); } } else { for (let other of mediaFiles.others) { - await this.uploadGroupFile(e, `${tgSavePath}/${other}`); + await this.uploadGroupFile(e, `${ tgSavePath }/${ other }`); } } return true; @@ -1954,7 +1992,7 @@ export class tools extends plugin { const msg = /https:\/\/tieba\.baidu\.com\/p\/[A-Za-z0-9]+/.exec(e.msg)?.[0]; const id = /\/p\/([A-Za-z0-9]+)/.exec(msg)?.[1]; // 获取帖子详情 - const hibi = HIBI_API_SERVICE + `/tieba/post_detail?tid=${id}`; + const hibi = HIBI_API_SERVICE + `/tieba/post_detail?tid=${ id }`; const hibiResp = await fetch(hibi, { headers: { "User-Agent": COMMON_USER_AGENT, @@ -1965,7 +2003,7 @@ export class tools extends plugin { const top = postList[0]; // 提取标题和内容 const { title, content } = top; - let sendContent = `${this.identifyPrefix}识别:贴吧,${title}` + let sendContent = `${ this.identifyPrefix }识别:贴吧,${ title }` let extractImages = []; // 如果内容中有图片、文本或视频,它会将它们添加到 sendContent 消息中 if (content && content.length > 0) { @@ -1977,12 +2015,12 @@ export class tools extends plugin { if (cdn_src) extractImages.push(segment.image(cdn_src)); // 处理文本 - if (text) sendContent.push(`\n\n📝 简介:${text}`); + if (text) sendContent.push(`\n\n📝 简介:${ text }`); // 处理视频 if (link) { const filePath = await this.downloadVideo(link); - this.sendVideoToUpload(e, `${filePath}/temp.mp4`); + this.sendVideoToUpload(e, `${ filePath }/temp.mp4`); } } } @@ -2032,7 +2070,7 @@ export class tools extends plugin { const tag = e.msg.replace(/#验车/g, ""); - const reqUrl = `https://whatslink.info/api/v1/link?url=${tag}`; + const reqUrl = `https://whatslink.info/api/v1/link?url=${ tag }`; const resp = await axios.get(reqUrl, { headers: { "User-Agent": COMMON_USER_AGENT, @@ -2042,7 +2080,7 @@ export class tools extends plugin { e.reply("没有找到相关磁力"); return; } - await e.reply(`🧲 [R插件 x Mix] 联合为您验车:\n${resp.data.name}`, false, { recallMsg: MESSAGE_RECALL_TIME }); + await e.reply(`🧲 [R插件 x Mix] 联合为您验车:\n${ resp.data.name }`, false, { recallMsg: MESSAGE_RECALL_TIME }); if (resp.data?.screenshots === null) { e.reply("没有找到相关媒体"); return; @@ -2094,7 +2132,7 @@ export class tools extends plugin { this.videoDownloadConcurrency ), ]).then(data => { - return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, `${title}.mp4`); + return mergeFileToMp4(data[0].fullFileName, data[1].fullFileName, `${ title }.mp4`); }); } @@ -2132,7 +2170,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 }` } /** @@ -2140,8 +2178,8 @@ 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`; + const groupPath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }`; + const target = `${ groupPath }/temp.mp4`; return { groupPath, target }; } @@ -2163,7 +2201,7 @@ export class tools extends plugin { // 构造代理参数 const proxyOption = { ...(isProxy && { - httpAgent: new HttpsProxyAgent(`http://${this.proxyAddr}:${this.proxyPort}`), + httpAgent: new HttpsProxyAgent(`http://${ this.proxyAddr }:${ this.proxyPort }`), }), } @@ -2180,7 +2218,7 @@ export class tools extends plugin { target, groupPath, } - logger.info(`[R插件][视频下载]:当前队列长度为 ${this.queue.size + 1}`); + logger.info(`[R插件][视频下载]:当前队列长度为 ${ this.queue.size + 1 }`); return await this.queue.add(async () => { // 如果是用户设置了单线程,则不分片下载 if (numThreads === 1) { @@ -2230,7 +2268,7 @@ export class tools extends plugin { const partAxiosConfig = { headers: { "User-Agent": userAgent, - "Range": `bytes=${start}-${end}` + "Range": `bytes=${ start }-${ end }` }, responseType: "stream", ...proxyOption @@ -2238,12 +2276,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); @@ -2273,7 +2311,7 @@ export class tools extends plugin { return groupPath; } catch (err) { - logger.error(`下载视频发生错误!\ninfo:${err}`); + logger.error(`下载视频发生错误!\ninfo:${ err }`); } } @@ -2288,39 +2326,39 @@ export class tools extends plugin { // 构造aria2c命令参数 const aria2cArgs = [ - `"${url}"`, + `"${ url }"`, `--out="temp.mp4"`, - `--dir="${groupPath}"`, - `--user-agent="${userAgent}"`, - `--max-connection-per-server=${numThreads}`, // 每个服务器的最大连接数 - `--split=${numThreads}`, // 分成 6 个部分进行下载 + `--dir="${ groupPath }"`, + `--user-agent="${ userAgent }"`, + `--max-connection-per-server=${ numThreads }`, // 每个服务器的最大连接数 + `--split=${ numThreads }`, // 分成 6 个部分进行下载 ]; // 如果有自定义头信息 if (headers) { for (const [key, value] of Object.entries(headers)) { - aria2cArgs.push(`--header="${key}: ${value}"`); + aria2cArgs.push(`--header="${ key }: ${ value }"`); } } // 如果使用代理 if (proxyOption && proxyOption.httpAgent) { const proxyUrl = proxyOption.httpAgent.proxy.href; - aria2cArgs.push(`--all-proxy="${proxyUrl}"`); + aria2cArgs.push(`--all-proxy="${ proxyUrl }"`); } try { await checkAndRemoveFile(target); - logger.mark(`开始下载: ${url}`); + logger.mark(`开始下载: ${ url }`); // 执行aria2c命令 - const command = `aria2c ${aria2cArgs.join(' ')}`; + const command = `aria2c ${ aria2cArgs.join(' ') }`; exec(command, (error, stdout, stderr) => { if (error) { - logger.error(`下载视频发生错误!\ninfo:${stderr}`); + logger.error(`下载视频发生错误!\ninfo:${ stderr }`); throw error; } else { - logger.mark(`下载完成: ${url}`); + logger.mark(`下载完成: ${ url }`); } }); @@ -2328,7 +2366,7 @@ export class tools extends plugin { let count = 0; return new Promise((resolve, reject) => { const checkInterval = setInterval(() => { - logger.info(logger.red(`[R插件][Aria2] 没有检测到文件!重试第${count + 1}次`)); + logger.info(logger.red(`[R插件][Aria2] 没有检测到文件!重试第${ count + 1 }次`)); count += 1; if (fs.existsSync(target)) { logger.info("[R插件][Aria2] 检测到文件!"); @@ -2343,7 +2381,7 @@ export class tools extends plugin { }, DOWNLOAD_WAIT_DETECT_FILE_TIME); }); } catch (err) { - logger.error(`下载视频发生错误!\ninfo:${err}`); + logger.error(`下载视频发生错误!\ninfo:${ err }`); throw err; } } @@ -2359,38 +2397,38 @@ export class tools extends plugin { // 构造axel命令参数 const axelArgs = [ - `-n ${numThreads}`, - `-o "${target}"`, - `-U "${userAgent}"`, + `-n ${ numThreads }`, + `-o "${ target }"`, + `-U "${ userAgent }"`, url ]; // 如果有自定义头信息 if (headers) { for (const [key, value] of Object.entries(headers)) { - axelArgs.push(`-H "${key}: ${value}"`); + axelArgs.push(`-H "${ key }: ${ value }"`); } } // 如果使用代理 if (proxyOption && proxyOption.httpAgent) { const proxyUrl = proxyOption.httpAgent.proxy.href; - axelArgs.push(`--proxy="${proxyUrl}"`); + axelArgs.push(`--proxy="${ proxyUrl }"`); } try { await checkAndRemoveFile(target); - logger.mark(`开始下载: ${url}`); + logger.mark(`开始下载: ${ url }`); // 执行axel命令 - const command = `axel ${axelArgs.join(' ')}`; + const command = `axel ${ axelArgs.join(' ') }`; exec(command, (error, stdout, stderr) => { if (error) { - logger.error(`下载视频发生错误!\ninfo:${stderr}`); + logger.error(`下载视频发生错误!\ninfo:${ stderr }`); throw error; } else { - logger.mark(`下载完成: ${url}`); + logger.mark(`下载完成: ${ url }`); } }); @@ -2398,12 +2436,12 @@ export class tools extends plugin { // 监听文件生成完成 return new Promise((resolve, reject) => { const checkInterval = setInterval(() => { - logger.info(logger.red(`[R插件][Aria2] 没有检测到文件!重试第${count + 1}次`)); + logger.info(logger.red(`[R插件][Aria2] 没有检测到文件!重试第${ count + 1 }次`)); count += 1; if (fs.existsSync(target)) { logger.info("[R插件][Axel] 检测到文件!"); clearInterval(checkInterval); - logger.info(`[R插件][Axel] 下载到${groupPath}`); + logger.info(`[R插件][Axel] 下载到${ groupPath }`); resolve(groupPath); } if (count === 6) { @@ -2414,7 +2452,7 @@ export class tools extends plugin { }, DOWNLOAD_WAIT_DETECT_FILE_TIME); }); } catch (err) { - logger.error(`下载视频发生错误!\ninfo:${err}`); + logger.error(`下载视频发生错误!\ninfo:${ err }`); throw err; } } @@ -2437,7 +2475,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); @@ -2446,7 +2484,7 @@ export class tools extends plugin { writer.on("error", reject); }); } catch (err) { - logger.error(`下载视频发生错误!\ninfo:${err}`); + logger.error(`下载视频发生错误!\ninfo:${ err }`); } } @@ -2543,13 +2581,13 @@ export class tools extends plugin { } // 正常发送视频 if (videoSize > videoSizeLimit) { - e.reply(`当前视频大小:${videoSize}MB,\n大于设置的最大限制:${videoSizeLimit}MB,\n改为上传群文件`); + e.reply(`当前视频大小:${ videoSize }MB,\n大于设置的最大限制:${ videoSizeLimit }MB,\n改为上传群文件`); await this.uploadGroupFile(e, path); } else { e.reply(segment.video(path)); } } catch (err) { - logger.error(`[R插件][发送视频判断是否需要上传] 发生错误:\n ${err}`); + logger.error(`[R插件][发送视频判断是否需要上传] 发生错误:\n ${ err }`); // logger.info(logger.yellow(`上传发生错误,R插件正在为你采用备用策略,请稍等,如果发不出来请再次尝试!`)); // e.reply(segment.video(path)); } diff --git a/constants/tools.js b/constants/tools.js index 471bf94..91035a4 100644 --- a/constants/tools.js +++ b/constants/tools.js @@ -61,6 +61,13 @@ export const BILI_SCAN_CODE_DETECT = "https://passport.bilibili.com/x/passport-l */ export const BILI_STREAM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info" +/** + * 根据真实直播间号获取直播视频流 + * https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live/live_stream.md + * @type {string} + */ +export const BILI_STREAM_FLV = "https://api.live.bilibili.com/room/v1/Room/playUrl" + /** * 获取视频在线人数_web端 * https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/video/online.md