mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
自动清理YouTube缩略图
This commit is contained in:
parent
6a27b52741
commit
27933d2a38
@ -2163,20 +2163,16 @@ export class tools extends plugin {
|
|||||||
// 使用安全标题作为文件名前缀
|
// 使用安全标题作为文件名前缀
|
||||||
const videoFilename = `${safeTitlePrefix}.mp4`;
|
const videoFilename = `${safeTitlePrefix}.mp4`;
|
||||||
const audioFilename = `${safeTitlePrefix}.flac`;
|
const audioFilename = `${safeTitlePrefix}.flac`;
|
||||||
const thumbnailFilename = `${safeTitlePrefix}_thumbnail.png`; // 确保缩略图文件名也唯一
|
const thumbnailFilenamePrefix = `${safeTitlePrefix}_thumbnail`;
|
||||||
|
|
||||||
// 清理可能存在的旧文件或同名文件
|
// 清理可能存在的旧文件或同名文件
|
||||||
await checkAndRemoveFile(path + "/" + videoFilename);
|
await checkAndRemoveFile(`${path}/${videoFilename}`);
|
||||||
await checkAndRemoveFile(path + "/" + audioFilename);
|
await checkAndRemoveFile(`${path}/${audioFilename}`);
|
||||||
await checkAndRemoveFile(path + "/" + thumbnailFilename);
|
await checkAndRemoveFile(`${path}/${thumbnailFilenamePrefix}.png`);
|
||||||
// 清理旧的 temp 文件,以防万一
|
|
||||||
await checkAndRemoveFile(path + "/temp.mp4");
|
|
||||||
await checkAndRemoveFile(path + "/temp.flac");
|
|
||||||
await checkAndRemoveFile(path + "/thumbnail.png");
|
|
||||||
|
|
||||||
|
// 下载缩略图并获取实际文件名
|
||||||
await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, safeTitlePrefix + "_thumbnail"); // 传递不带扩展名的前缀
|
const actualThumbnailFilename = await ytDlpGetThumbnail(path, url, isOversea, this.myProxy, this.youtubeCookiePath, thumbnailFilenamePrefix);
|
||||||
const fullThumbnailPath = `${path}/${thumbnailFilename}`;
|
const fullThumbnailPath = `${path}/${actualThumbnailFilename}`;
|
||||||
|
|
||||||
|
|
||||||
// 音频逻辑
|
// 音频逻辑
|
||||||
@ -2204,17 +2200,21 @@ export class tools extends plugin {
|
|||||||
segment.image(fullThumbnailPath),
|
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$/, '') } 分钟`
|
`${ 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') {
|
} else if (Duration > this.youtubeClipTime && timeRange != '00:00:00-00:00:00') {
|
||||||
e.reply([
|
e.reply([
|
||||||
segment.image(fullThumbnailPath),
|
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将截取视频片段`
|
`${ 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);
|
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 {
|
} else {
|
||||||
e.reply([segment.image(fullThumbnailPath), `${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n视频标题:${ rawTitle }\n视频时长:${ (Duration / 60).toFixed(2).replace(/\.00$/, '') } 分钟`]);
|
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);
|
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) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
@ -3290,5 +3290,6 @@ export class tools extends plugin {
|
|||||||
} else {
|
} else {
|
||||||
await e.group.sendFile(path);
|
await e.group.sendFile(path);
|
||||||
}
|
}
|
||||||
|
await checkAndRemoveFile(path); // 上传成功后删除
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user