mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🐞 fix: V1.3.1 修复油管解析bug
修复油管解析无法匹配youtube.com的情况
This commit is contained in:
parent
9c0aae9f48
commit
df30b619ca
@ -17,7 +17,7 @@ import {
|
|||||||
XHS_NO_WATERMARK_HEADER,
|
XHS_NO_WATERMARK_HEADER,
|
||||||
REDIS_YUNZAI_ISOVERSEA,
|
REDIS_YUNZAI_ISOVERSEA,
|
||||||
} from "../constants/constant.js";
|
} from "../constants/constant.js";
|
||||||
import {containsChinese, formatBiliInfo, getIdVideo, secondsToTime} from "../utils/common.js";
|
import { containsChinese, formatBiliInfo, getIdVideo, secondsToTime } from "../utils/common.js";
|
||||||
import config from "../model/index.js";
|
import config from "../model/index.js";
|
||||||
import Translate from "../utils/trans-strategy.js";
|
import Translate from "../utils/trans-strategy.js";
|
||||||
import * as xBogus from "../utils/x-bogus.cjs";
|
import * as xBogus from "../utils/x-bogus.cjs";
|
||||||
@ -915,7 +915,7 @@ export class tools extends plugin {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async y2b(e) {
|
async y2b(e) {
|
||||||
const urlRex = /(?:https?:\/\/)?www\.youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
|
const urlRex = /(?:https?:\/\/)?(www\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
|
||||||
let url = urlRex.exec(e.msg)[0];
|
let url = urlRex.exec(e.msg)[0];
|
||||||
// 获取url查询参数
|
// 获取url查询参数
|
||||||
const query = querystring.parse(url.split("?")[1]);
|
const query = querystring.parse(url.split("?")[1]);
|
||||||
@ -929,13 +929,13 @@ export class tools extends plugin {
|
|||||||
|
|
||||||
let rs = { title: '', thumbnail: '', formats: [] };
|
let rs = { title: '', thumbnail: '', formats: [] };
|
||||||
try {
|
try {
|
||||||
let cmd = `yt-dlp --print-json --skip-download ${this.y2bCk !== undefined ? `--cookies ${this.y2bCk}` : ''} '${url}' ${isProxy ? `--proxy ${this.proxyAddr}:${this.proxyPort}` : ''} 2> /dev/null`
|
let cmd = `yt-dlp --print-json --skip-download ${ this.y2bCk !== undefined ? `--cookies ${ this.y2bCk }` : '' } '${ url }' ${ isProxy ? `--proxy ${ this.proxyAddr }:${ this.proxyPort }` : '' } 2> /dev/null`
|
||||||
logger.mark('解析视频, 命令:', cmd);
|
logger.mark('解析视频, 命令:', cmd);
|
||||||
rs = child_process.execSync(cmd).toString();
|
rs = child_process.execSync(cmd).toString();
|
||||||
try {
|
try {
|
||||||
rs = JSON.parse(rs);
|
rs = JSON.parse(rs);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let cmd = `yt-dlp --print-json --skip-download ${this.y2bCk !== undefined ? `--cookies ${this.y2bCk}` : ''} '${url}?p=1' ${isProxy ? `--proxy ${this.proxyAddr}:${this.proxyPort}` : ''} 2> /dev/null`;
|
let cmd = `yt-dlp --print-json --skip-download ${ this.y2bCk !== undefined ? `--cookies ${ this.y2bCk }` : '' } '${ url }?p=1' ${ isProxy ? `--proxy ${ this.proxyAddr }:${ this.proxyPort }` : '' } 2> /dev/null`;
|
||||||
logger.mark('尝试分P, 命令:', cmd);
|
logger.mark('尝试分P, 命令:', cmd);
|
||||||
rs = child_process.execSync(cmd).toString();
|
rs = child_process.execSync(cmd).toString();
|
||||||
rs = JSON.parse(rs);
|
rs = JSON.parse(rs);
|
||||||
@ -947,13 +947,13 @@ export class tools extends plugin {
|
|||||||
const transedTitle = await this.translateEngine.translate(rs.title, '中');
|
const transedTitle = await this.translateEngine.translate(rs.title, '中');
|
||||||
// const transedDescription = await this.translateEngine.translate(rs.description, '中');
|
// const transedDescription = await this.translateEngine.translate(rs.description, '中');
|
||||||
e.reply(`识别:油管,
|
e.reply(`识别:油管,
|
||||||
${rs.title.trim()}\n
|
${ rs.title.trim() }\n
|
||||||
${DIVIDING_LINE.replace("{}", "R插件翻译引擎服务")}\n
|
${ DIVIDING_LINE.replace("{}", "R插件翻译引擎服务") }\n
|
||||||
${transedTitle}\n
|
${ transedTitle }\n
|
||||||
${rs.description}
|
${ rs.description }
|
||||||
`);
|
`);
|
||||||
} else {
|
} else {
|
||||||
e.reply(`识别:油管,${rs.title}`);
|
e.reply(`识别:油管,${ rs.title }`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error.toString());
|
logger.error(error.toString());
|
||||||
@ -984,17 +984,17 @@ export class tools extends plugin {
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
// 格式化yt-dlp的请求
|
// 格式化yt-dlp的请求
|
||||||
const format = `${bestVideo.id}x${bestAudio.id}`
|
const format = `${ bestVideo.id }x${ bestAudio.id }`
|
||||||
// 下载地址格式化
|
// 下载地址格式化
|
||||||
const path = `${v}${ p ? `/p${p}` : '' }`;
|
const path = `${ v }${ p ? `/p${ p }` : '' }`;
|
||||||
const fullpath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/${path}`;
|
const fullpath = `${ this.defaultPath }${ this.e.group_id || this.e.user_id }/${ path }`;
|
||||||
// yt-dlp下载
|
// yt-dlp下载
|
||||||
let cmd = //`cd '${__dirname}' && (cd tmp > /dev/null || (mkdir tmp && cd tmp)) &&` +
|
let cmd = //`cd '${__dirname}' && (cd tmp > /dev/null || (mkdir tmp && cd tmp)) &&` +
|
||||||
`yt-dlp ${this.y2bCk !== undefined ? `--cookies ${this.y2bCk}` : ''} https://youtu.be/${v} -f ${format.replace('x', '+')} ` +
|
`yt-dlp ${ this.y2bCk !== undefined ? `--cookies ${ this.y2bCk }` : '' } https://youtu.be/${ v } -f ${ format.replace('x', '+') } ` +
|
||||||
`-o '${fullpath}/${v}.%(ext)s' ${isProxy ? `--proxy ${this.proxyAddr}:${this.proxyPort}` : ''} -k --write-info-json`;
|
`-o '${ fullpath }/${ v }.%(ext)s' ${ isProxy ? `--proxy ${ this.proxyAddr }:${ this.proxyPort }` : '' } -k --write-info-json`;
|
||||||
try {
|
try {
|
||||||
await child_process.execSync(cmd);
|
await child_process.execSync(cmd);
|
||||||
e.reply(segment.video(`${fullpath}/${v}.mp4`))
|
e.reply(segment.video(`${ fullpath }/${ v }.mp4`))
|
||||||
// 清理文件
|
// 清理文件
|
||||||
await deleteFolderRecursive(fullpath);
|
await deleteFolderRecursive(fullpath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -1165,7 +1165,7 @@ export class tools extends plugin {
|
|||||||
writer.on("error", reject);
|
writer.on("error", reject);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`下载视频发生错误!\ninfo:${err}`);
|
logger.error(`下载视频发生错误!\ninfo:${ err }`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1183,7 +1183,7 @@ export class tools extends plugin {
|
|||||||
os: os,
|
os: os,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
e.reply(`当前服务器:${os ? '海外服务器' : '国内服务器'}`)
|
e.reply(`当前服务器:${ os ? '海外服务器' : '国内服务器' }`)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user