From 39e2f300611333294b9f23a410cb15a521fcbd9e Mon Sep 17 00:00:00 2001 From: MiX1024 <116636746+MiX1024@users.noreply.github.com> Date: Sun, 21 Apr 2024 21:00:52 +0800 Subject: [PATCH] Update tools.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修一下油管解析 --- apps/tools.js | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 9f526b0..9baf21d 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -137,7 +137,7 @@ export class tools extends plugin { }, { reg: "(youtube.com|youtu.be)", - fnc: "y2b" + fnc: "sy2b" }, { reg: "(miyoushe.com)", @@ -1147,28 +1147,39 @@ export class tools extends plugin { * @param e * @returns {Promise} */ - async y2b(e) { - const urlRex = /(?:https?:\/\/)?(www\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g; - // https://youtu.be/9IoNgzpURDw?si=XlvOAxqqjF9FJYcF - const url2Rex = /(?:https?:\/\/)?youtu\.be\/[A-Za-z\d._?%&+\-=\/#]*/g; - let url = urlRex.exec(e.msg)?.[0] || url2Rex.exec(e.msg)?.[0]; - // 判断海外 + async dy2b(path,url) { + return new Promise((resolve, reject) => { + const command = `yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} -o "temp.%(ext)s" -f 'bv[height<=720][ext=mp4]+ba[ext=m4a]' --merge-output-format "mp4" ${url}`; + exec(command, (error, stdout) => { + if (error) { + console.error(`Error executing command: ${error}`); + reject(error); + } else { + console.log(`Command output: ${stdout}`); + resolve(stdout); + } + }); + }); + } + + async sy2b(e){ + let videoSizeLimit = 15 const isOversea = await this.isOverseasServer(); - // 如果不是海外用户且没有梯子直接返回 if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) { e.reply("检测到没有梯子,无法解析油管"); return false; } - try { - // Perform the HTTP GET request - const title = execSync(`yt-dlp --get-title https://www.youtube.com/shorts/JNdllQl3n0g ${isOversea ? "" : `--proxy ${this.myProxy}`}`) - e.reply(`识别:油管,${title}`); - const path = this.getCurDownloadPath(e); - execSync(`yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} ${url} -o "temp.%(ext)s" --merge-output-format "mp4"`) - e.reply(segment.video(path + "/temp.mp4")); - await checkAndRemoveFile(path + "/temp.mp4"); - } catch (error) { + const urlRex = /(?:https?:\/\/)?(www\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g; + const url2Rex = /(?:https?:\/\/)?youtu\.be\/[A-Za-z\d._?%&+\-=\/#]*/g; + let url = urlRex.exec(e.msg)?.[0] || url2Rex.exec(e.msg)?.[0]; + 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}`); + await this.dy2b(path,url) + 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 }