Merge pull request #3 from MiX1024/master

🐞fix: 修复油管解析
This commit is contained in:
Zhiyu 2024-04-21 21:18:06 +08:00 committed by GitHub
commit 72121208ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -137,7 +137,7 @@ export class tools extends plugin {
}, },
{ {
reg: "(youtube.com|youtu.be)", reg: "(youtube.com|youtu.be)",
fnc: "y2b" fnc: "sy2b"
}, },
{ {
reg: "(miyoushe.com)", reg: "(miyoushe.com)",
@ -1147,28 +1147,39 @@ export class tools extends plugin {
* @param e * @param e
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async y2b(e) { async dy2b(path,url) {
const urlRex = /(?:https?:\/\/)?(www\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g; return new Promise((resolve, reject) => {
// https://youtu.be/9IoNgzpURDw?si=XlvOAxqqjF9FJYcF 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 url2Rex = /(?:https?:\/\/)?youtu\.be\/[A-Za-z\d._?%&+\-=\/#]*/g; exec(command, (error, stdout) => {
let url = urlRex.exec(e.msg)?.[0] || url2Rex.exec(e.msg)?.[0]; if (error) {
// 判断海外 console.error(`Error executing command: ${error}`);
reject(error);
} else {
console.log(`Command output: ${stdout}`);
resolve(stdout);
}
});
});
}
async sy2b(e){
let videoSizeLimit = 30
const isOversea = await this.isOverseasServer(); const isOversea = await this.isOverseasServer();
// 如果不是海外用户且没有梯子直接返回
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) { if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
e.reply("检测到没有梯子,无法解析油管"); e.reply("检测到没有梯子,无法解析油管");
return false; return false;
} }
try { try {
// Perform the HTTP GET request const urlRex = /(?:https?:\/\/)?(www\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const title = execSync(`yt-dlp --get-title https://www.youtube.com/shorts/JNdllQl3n0g ${isOversea ? "" : `--proxy ${this.myProxy}`}`) const url2Rex = /(?:https?:\/\/)?youtu\.be\/[A-Za-z\d._?%&+\-=\/#]*/g;
e.reply(`识别:油管,${title}`); let url = urlRex.exec(e.msg)?.[0] || url2Rex.exec(e.msg)?.[0];
const path = this.getCurDownloadPath(e); const path = this.getCurDownloadPath(e)
execSync(`yt-dlp ${isOversea ? "" : `--proxy ${this.myProxy}`} -P ${path} ${url} -o "temp.%(ext)s" --merge-output-format "mp4"`) await checkAndRemoveFile(path + "/temp.mp4")
e.reply(segment.video(path + "/temp.mp4")); const title = execSync(`yt-dlp --get-title ${url} ${isOversea ? "" : `--proxy ${this.myProxy}`}`)
await checkAndRemoveFile(path + "/temp.mp4"); e.reply(`识别:油管,视频下载中请耐心等待 \n${title}`);
} catch (error) { await this.dy2b(path,url)
this.sendVideoToUpload(e, `${path}/temp.mp4`,videoSizeLimit)
}catch (error) {
console.error(error); console.error(error);
throw error; // Rethrow the error so it can be handled by the caller throw error; // Rethrow the error so it can be handled by the caller
} }