diff --git a/README.md b/README.md index 7be1e27..2934774 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,19 @@ sudo apt-get install ffmpeg # Windows 参考:https://www.jianshu.com/p/5015a477de3c ```` +`油管解析`需要 `yt-dlp` 的依赖才能完成解析(三选一): +```shell +# 三选一 +# ubuntu (国内 or 国外,且安装了snap) +snap install yt-dlp +# debian 海外 +curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ~/.local/bin/yt-dlp +chmod a+rx ~/.local/bin/yt-dlp +# debian 国内 +curl -L https://ghproxy.net/https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ~/.local/bin/yt-dlp +chmod a+rx ~/.local/bin/yt-dlp +``` + 4. 【可选】小程序解析适配了: * 喵崽:[Yoimiya / Miao-Yunzai](https://gitee.com/yoimiya-kokomi/Miao-Yunzai) * TRSS:[时雨◎星空 / Yunzai](https://gitee.com/TimeRainStarSky/Yunzai) @@ -165,18 +178,21 @@ git clone -b 1.5.1 https://gitee.com/kyrzy0416/rconsole-plugin.git - [插件库](https://gitee.com/Hikari666/Yunzai-Bot-plugins-index) ## 🙏 贡献 -🌸感谢下面的朋友对我插件的贡献(排名不分高低)🌸 +🌸 感谢下面的朋友对我插件的贡献(排名不分高低) * [好冷](https://gitee.com/hetangx) 提供Windows解决方案 * [一杯凉](https://gitee.com/yibeiliang) 提供小程序解析冲突解决方案 * [x0rz4](https://gitee.com/x0rz4) 提供依赖掉包解决方案 -🌸同时鸣谢感谢以下开发者对 `R插件` 出的贡献🌸: +🌸 同时鸣谢感谢以下开发者对 `R插件` 出的贡献: +🌸 感谢以下框架的开源: +- [yt-dlp:A youtube-dl fork with additional features and fixes](https://github.com/yt-dlp/yt-dlp) + ## ☕ 请我喝一杯瑞幸咖啡 如果你觉得插件能帮助到你增进好友关系,那么你可以在有条件的情况下[请我喝一杯瑞幸咖啡](https://afdian.net/a/zhiyu1998),这是我开源这个插件的最大动力! 感谢以下朋友的支持!(排名不分多少) diff --git a/apps/tools.js b/apps/tools.js index b86bbe7..9f526b0 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -7,6 +7,7 @@ import axios from "axios"; import _ from "lodash"; import tunnel from "tunnel"; import HttpProxyAgent from "https-proxy-agent"; +import { execSync } from "child_process"; import { checkAndRemoveFile, deleteFolderRecursive, mkdirIfNotExists, readCurrentDir } from "../utils/file.js"; import { downloadBFile, @@ -1161,40 +1162,12 @@ export class tools extends plugin { try { // Perform the HTTP GET request - const formData = { - "link": url, - "from": "ytbsaver" - } - const params = new URLSearchParams(); - Object.keys(formData).forEach(key => params.append(key, formData[key])); - - const config = { - headers: { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36", - "origin": "https://www.ytbsaver.com" - }, - } - // 如果不是海外,则使用代理 - if (!isOversea) { - config.httpsAgent = tunnel.httpsOverHttp({ - proxy: { - host: this.proxyAddr, - port: this.proxyPort - }, - }); - } - - const response = await axios.post("https://api.ytbvideoly.com/api/thirdvideo/parse", params.toString(), config); - - const { title, /*thumbnail,*/ duration, formats } = response.data.data; - e.reply(`识别:油管,${ title }\n时长:${ formatSeconds(duration) }`); - if (formats.length > 0) { - // 大概率是720p - const videoUrl = formats?.[formats.length - 1].url; - this.downloadVideo(videoUrl, !isOversea).then(path => { - e.reply(segment.video(path + "/temp.mp4")); - }); - } + 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) { console.error(error); throw error; // Rethrow the error so it can be handled by the caller