Merge pull request #21 from nikoyoke1/master

优化 油管视频下载策略 标题输出
This commit is contained in:
Zhiyu 2024-09-27 07:44:36 +00:00 committed by GitHub
commit b89ef59739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -1432,7 +1432,12 @@ export class tools extends plugin {
try {
const urlRex = /(?:https?:\/\/)?(www\.|music\.)?youtube\.com\/[A-Za-z\d._?%&+\-=\/#]*/g;
const url2Rex = /(?:https?:\/\/)?youtu\.be\/[A-Za-z\d._?%&+\-=\/#]*/g;
let url = urlRex.exec(e.msg)?.[0]?.replace(/&/g, '^&') || url2Rex.exec(e.msg)?.[0]?.replace(/&/g, '^&');
// 检测操作系统平台
const isWindows = process.platform === 'win32';
// 匹配并转义 URL 中的 & 符号(仅对 Windows 进行转义)
let url = urlRex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&') ||
url2Rex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&');
// 适配 YouTube Music
if (url.includes("music")) {
// https://music.youtube.com/watch?v=F4sRtMoIgUs&si=7ZYrHjlI3fHAha0F

View File

@ -18,7 +18,7 @@ function constructProxyParam(isOversea, proxy) {
* @returns string
*/
export function ytDlpGetTilt(url, isOversea, proxy) {
return execSync(`yt-dlp --get-title ${constructProxyParam(isOversea, proxy)} ${url}`);
return execSync(`yt-dlp --get-title ${constructProxyParam(isOversea, proxy)} ${url} --encoding utf8`);
}
/**
@ -34,7 +34,7 @@ export async function ytDlpHelper(path, url, isOversea, proxy, merge = false) {
return new Promise((resolve, reject) => {
const mergeOption = merge ? '--merge-output-format "mp4"' : '';
const command = `yt-dlp ${constructProxyParam(isOversea, proxy)} -P ${path} -o "temp.%(ext)s" ${mergeOption} ${url}`;
const command = `yt-dlp -f "bv[height<=720][ext=mp4]+ba[ext=m4a]" ${constructProxyParam(isOversea, proxy)} -P ${path} -o "temp.%(ext)s" ${url}`;
exec(command, (error, stdout) => {
if (error) {