🌟 feat: 小飞机增加多线程能力

This commit is contained in:
zhiyu1998 2024-08-13 22:08:26 +08:00
parent 1f86a31ec9
commit 823e9ddbb5
2 changed files with 12 additions and 6 deletions

View File

@ -1780,10 +1780,14 @@ export class tools extends plugin {
return;
}
const url = urlRex.exec(e.msg)[0];
const tgSavePath = `${this.getCurDownloadPath(e)}/tg`;
await mkdirIfNotExists(tgSavePath);
await startTDL(url, tgSavePath, isOversea, this.myProxy);
e.reply(`识别:小飞机(学习版)`);
const tgSavePath = `${this.getCurDownloadPath(e)}/tg`;
// 如果没有文件夹则创建
await mkdirIfNotExists(tgSavePath);
// 删除之前的文件
await deleteFolderRecursive(tgSavePath);
await startTDL(url, tgSavePath, isOversea, this.myProxy, this.videoDownloadConcurrency);
// 过滤当前文件
const mediaFiles = await getMediaFiles(tgSavePath);
if (mediaFiles.images.length > 0) {
const imagesData = mediaFiles.images.map(item => {
@ -1800,7 +1804,6 @@ export class tools extends plugin {
await this.sendVideoToUpload(e, `${tgSavePath}/${item}`);
}
}
await deleteFolderRecursive(tgSavePath);
return true;
}

View File

@ -7,13 +7,16 @@ import path from 'path'
* @param curPath
* @param isOversea
* @param proxyAddr
* @param videoDownloadConcurrency
* @returns {Promise<string>}
*/
export async function startTDL(url, curPath, isOversea, proxyAddr) {
export async function startTDL(url, curPath, isOversea, proxyAddr, videoDownloadConcurrency = 1) {
return new Promise((resolve, reject) => {
curPath = path.resolve(curPath);
const proxyStr = isOversea ? `` : `--proxy ${ proxyAddr }`;
const command = `tdl dl -u ${url} -d ${curPath} ${proxyStr}`
const concurrencyStr = videoDownloadConcurrency > 1 ? `-t ${videoDownloadConcurrency} -s 524288 -l ${videoDownloadConcurrency}` : '';
const command = `tdl dl -u ${url} -d ${curPath} ${concurrencyStr} ${proxyStr}`
logger.mark(`[R插件][TDL] ${command}`);
exec(command, (error, stdout, stderr) => {
if (error) {
reject(`[R插件][TDL]执行出错: ${error.message}`);