From 6a27b5274152993c478f1e04583f2bf80ace242d Mon Sep 17 00:00:00 2001 From: CSSZYF <63802741+CSSZYF@users.noreply.github.com> Date: Sun, 15 Jun 2025 02:14:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=94=BB=E8=9B=87=E6=B7=BB=E8=B6=B3=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=AF=BC=E8=87=B4=E5=AF=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=80=A0=E6=88=90=E6=97=A0=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E5=8F=91=E9=80=81=E7=BE=A4=E9=9F=B3=E4=B9=90=E7=9A=84?= =?UTF-8?q?=E8=B4=9F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/tools.js b/apps/tools.js index 58f58e7..56ec063 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -3290,6 +3290,5 @@ export class tools extends plugin { } else { await e.group.sendFile(path); } - await checkAndRemoveFile(path); // 上传成功后删除 } } From 27933d2a3864f6eb53e6e7784b237e24b4a547f9 Mon Sep 17 00:00:00 2001 From: CSSZYF <63802741+CSSZYF@users.noreply.github.com> Date: Sun, 15 Jun 2025 02:40:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86YouTube?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 56ec063..bbea87a 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -2163,20 +2163,16 @@ export class tools extends plugin { // 使用安全标题作为文件名前缀 const videoFilename = `${safeTitlePrefix}.mp4`; const audioFilename = `${safeTitlePrefix}.flac`; - const thumbnailFilename = `${safeTitlePrefix}_thumbnail.png`; // 确保缩略图文件名也唯一 + const thumbnailFilenamePrefix = `${safeTitlePrefix}_thumbnail`; // 清理可能存在的旧文件或同名文件 - await checkAndRemoveFile(path + "/" + videoFilename); - await checkAndRemoveFile(path + "/" + audioFilename); - await checkAndRemoveFile(path + "/" + thumbnailFilename); - // 清理旧的 temp 文件,以防万一 - await checkAndRemoveFile(path + "/temp.mp4"); - await checkAndRemoveFile(path + "/temp.flac"); - await checkAndRemoveFile(path + "/thumbnail.png"); + await checkAndRemoveFile(`${path}/${videoFilename}`); + await checkAndRemoveFile(`${path}/${audioFilename}`); + await checkAndRemoveFile(`${path}/${thumbnailFilenamePrefix}.png`); - - await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, safeTitlePrefix + "_thumbnail"); // 传递不带扩展名的前缀 - const fullThumbnailPath = `${path}/${thumbnailFilename}`; + // 下载缩略图并获取实际文件名 + const actualThumbnailFilename = await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, thumbnailFilenamePrefix); + const fullThumbnailPath = `${path}/${actualThumbnailFilename}`; // 音频逻辑 @@ -2204,17 +2200,21 @@ export class tools extends plugin { segment.image(fullThumbnailPath), `${ this.identifyPrefix }识别:油管,视频时长超限 \n视频标题:${ rawTitle }\n⌚${ DIVIDING_LINE.replace('{}', '限制说明').replace(/\n/g, '') }⌚\n视频时长:${ (Duration / 60).toFixed(2).replace(/\.00$/, '') } 分钟\n大于管理员限定解析时长:${ (this.youtubeDuration / 60).toFixed(2).replace(/\.00$/, '') } 分钟` ]); + await checkAndRemoveFile(fullThumbnailPath); // 删除缩略图 } else if (Duration > this.youtubeClipTime && timeRange != '00:00:00-00:00:00') { e.reply([ segment.image(fullThumbnailPath), `${ this.identifyPrefix }识别:油管,视频截取中请耐心等待 \n视频标题:${ rawTitle }\n✂️${ DIVIDING_LINE.replace('{}', '截取说明').replace(/\n/g, '') }✂️\n视频时长:${ (Duration / 60).toFixed(2).replace(/\.00$/, '') } 分钟\n大于管理员限定截取时长:${ (this.youtubeClipTime / 60).toFixed(2).replace(/\.00$/, '') } 分钟\n将截取视频片段` ]); + // 注意:sendVideoToUpload 内部会删除视频文件,但不会删除缩略图 await ytDlpHelper(path, url, isOversea, this.myProxy, this.videoDownloadConcurrency, safeTitlePrefix, true, graphics, timeRange, this.youtubeCookiePath); - this.sendVideoToUpload(e, `${ path }/${ videoFilename }`); + await this.sendVideoToUpload(e, `${ path }/${ videoFilename }`); + await checkAndRemoveFile(fullThumbnailPath); // 删除缩略图 } else { e.reply([segment.image(fullThumbnailPath), `${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n视频标题:${ rawTitle }\n视频时长:${ (Duration / 60).toFixed(2).replace(/\.00$/, '') } 分钟`]); await ytDlpHelper(path, url, isOversea, this.myProxy, this.videoDownloadConcurrency, safeTitlePrefix, true, graphics, timeRange, this.youtubeCookiePath); - this.sendVideoToUpload(e, `${ path }/${ videoFilename }`); + await this.sendVideoToUpload(e, `${ path }/${ videoFilename }`); + await checkAndRemoveFile(fullThumbnailPath); // 删除缩略图 } } catch (error) { logger.error(error); @@ -3290,5 +3290,6 @@ export class tools extends plugin { } else { await e.group.sendFile(path); } + await checkAndRemoveFile(path); // 上传成功后删除 } } From e398a4cb992463caed32e3badb58d546110cd25c Mon Sep 17 00:00:00 2001 From: CSSZYF <63802741+CSSZYF@users.noreply.github.com> Date: Sun, 15 Jun 2025 02:43:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8=20Windows=20?= =?UTF-8?q?=E4=B8=AD=20&=20=E5=AD=97=E7=AC=A6=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/yt-dlp-util.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/utils/yt-dlp-util.js b/utils/yt-dlp-util.js index 762dddc..686af48 100644 --- a/utils/yt-dlp-util.js +++ b/utils/yt-dlp-util.js @@ -43,7 +43,7 @@ export function ytDlpGetDuration(url, isOversea, proxy, cookiePath = "") { return new Promise((resolve, reject) => { // 构造 cookie 参数 const cookieParam = constructCookiePath(url, cookiePath); - const command = `yt-dlp --get-duration --skip-download ${cookieParam} ${constructProxyParam(isOversea, proxy)} ${url}`; + const command = `yt-dlp --get-duration --skip-download ${cookieParam} ${constructProxyParam(isOversea, proxy)} "${url}"`; exec(command, (error, stdout, stderr) => { if (error) { logger.error(`[R插件][yt-dlp审计] Error executing ytDlpGetDuration: ${error}. Stderr: ${stderr}`); @@ -69,7 +69,7 @@ export function ytDlpGetTilt(url, isOversea, proxy, cookiePath = "") { const cookieParam = constructCookiePath(url, cookiePath); // 构造 编码 参数 const encodingParam = constructEncodingParam(url); - const command = `yt-dlp --get-title --skip-download ${cookieParam} ${ constructProxyParam(isOversea, proxy) } ${ url } ${encodingParam}`; + const command = `yt-dlp --get-title --skip-download ${cookieParam} ${ constructProxyParam(isOversea, proxy) } "${url}" ${encodingParam}`; exec(command, (error, stdout, stderr) => { if (error) { logger.error(`[R插件][yt-dlp审计] Error executing ytDlpGetTilt: ${error}. Stderr: ${stderr}`); @@ -92,16 +92,29 @@ export function ytDlpGetTilt(url, isOversea, proxy, cookiePath = "") { */ export function ytDlpGetThumbnail(path, url, isOversea, proxy, cookiePath = "", thumbnailFilenamePrefix = "thumbnail") { return new Promise((resolve, reject) => { - // 构造 cookie 参数 const cookieParam = constructCookiePath(url, cookiePath); - const finalThumbnailName = thumbnailFilenamePrefix || "thumbnail"; // 确保有默认值 - const command = `yt-dlp --write-thumbnail --convert-thumbnails png --skip-download ${cookieParam} ${constructProxyParam(isOversea, proxy)} ${url} -P "${path}" -o "${finalThumbnailName}.%(ext)s"`; + const finalThumbnailName = thumbnailFilenamePrefix || "thumbnail"; + const command = `yt-dlp --write-thumbnail --convert-thumbnails png --skip-download ${cookieParam} ${constructProxyParam(isOversea, proxy)} "${url}" -P "${path}" -o "${finalThumbnailName}.%(ext)s"`; + exec(command, (error, stdout, stderr) => { if (error) { logger.error(`[R插件][yt-dlp审计] Error executing ytDlpGetThumbnail: ${error}. Stderr: ${stderr}`); - reject(error); + return reject(error); + } + // 从yt-dlp的输出中提取文件名 + const match = stdout.match(/Writing thumbnail to: (.*)/); + if (match && match[1]) { + const thumbnailPath = match[1].trim(); + // 只返回文件名部分 + const thumbnailFilename = thumbnailPath.split(/[\\/]/).pop(); + logger.info(`[R插件][yt-dlp审计] Thumbnail downloaded: ${thumbnailFilename}`); + resolve(thumbnailFilename); } else { - resolve(); // The return value is not used + // 兜底方案:如果无法从输出中解析,则按原逻辑拼接 + logger.warn("[R插件][yt-dlp审计] Could not parse thumbnail filename from stdout. Falling back to default."); + // 尝试查找文件,因为yt-dlp可能没有输出我们期望的格式 + const expectedPngPath = `${finalThumbnailName}.png`; + resolve(expectedPngPath); } }); }); @@ -132,12 +145,12 @@ export async function ytDlpHelper(path, url, isOversea, proxy, maxThreads, outpu if (url.includes("music")) { // 这里是 YouTube Music的处理逻辑 // e.g yt-dlp -x --audio-format mp3 https://youtu.be/5wEtefq9VzM -o test.mp3 - command = `yt-dlp -x --audio-format flac -f ba ${cookieParam} ${constructProxyParam(isOversea, proxy)} -P "${path}" -o "${finalOutputFilename}.flac" ${url}`; + command = `yt-dlp -x --audio-format flac -f ba ${cookieParam} ${constructProxyParam(isOversea, proxy)} -P "${path}" -o "${finalOutputFilename}.flac" "${url}"`; } else { // 正常情况下的处理逻辑 const fParam = url.includes("youtu") ? `--download-sections "*${timeRange}" -f "bv${graphics}[ext=mp4]+ba[ext=m4a]" ` : ""; - command = `yt-dlp -N ${maxThreads} ${fParam} --concurrent-fragments ${maxThreads} ${cookieParam} ${constructProxyParam(isOversea, proxy)} -P "${path}" -o "${finalOutputFilename}.%(ext)s" ${url}`; + command = `yt-dlp -N ${maxThreads} ${fParam} --concurrent-fragments ${maxThreads} ${cookieParam} ${constructProxyParam(isOversea, proxy)} -P "${path}" -o "${finalOutputFilename}.%(ext)s" "${url}"`; } logger.info(`[R插件][yt-dlp审计] ${command}`);