diff --git a/apps/tools.js b/apps/tools.js index 7eec3a9..10e9c15 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -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 diff --git a/utils/yt-dlp-util.js b/utils/yt-dlp-util.js index fcd28f3..d9ea306 100644 --- a/utils/yt-dlp-util.js +++ b/utils/yt-dlp-util.js @@ -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) {