Merge pull request #35 from nikoyoke1/master

🎈pref:优化油管视频解析策略
This commit is contained in:
Zhiyu 2024-10-18 11:05:31 +08:00 committed by GitHub
commit 3fc7c5f90d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 20 deletions

View File

@ -281,10 +281,12 @@ export class tools extends plugin {
this.biliDownloadMethod = this.toolsConfig.biliDownloadMethod;
// 加载哔哩哔哩最高分辨率
this.biliResolution = this.toolsConfig.biliResolution;
// 加载youtube的限制时长
// 加载youtube的截取时长
this.youtubeClipTime = this.toolsConfig.youtubeClipTime
// 加载youtube的解析时长
this.youtubeDuration = this.toolsConfig.youtubeDuration
// 加载油管下载画质选项
this.YouTubeGraphicsOptions = this.toolsConfig.YouTubeGraphicsOptions
this.youtubeGraphicsOptions = this.toolsConfig.youtubeGraphicsOptions
// 加载抖音Cookie
this.douyinCookie = this.toolsConfig.douyinCookie;
// 加载抖音是否压缩
@ -1613,7 +1615,7 @@ export class tools extends plugin {
musicUrlReg2.exec(message)?.[3] ||
musicUrlReg.exec(message)?.[2] ||
musicUrlReg3.exec(message)?.[2] ||
/id=(\d+)/.exec(message)[1];
/(?<!user)id=(\d+)/.exec(message)[1];
// 如果没有下载地址跳出if
if (_.isEmpty(id)) {
e.reply(`识别:网易云音乐,解析失败!`);
@ -1922,7 +1924,7 @@ export class tools extends plugin {
// 构造时间范围字符串
return `00:00:00-${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
}
const timeRange = await formatTime(this.youtubeDuration)
const timeRange = await formatTime(this.youtubeClipTime)
const isOversea = await this.isOverseasServer();
if (!isOversea && !(await testProxy(this.proxyAddr, this.proxyPort))) {
e.reply("检测到没有梯子,无法解析油管");
@ -1944,8 +1946,8 @@ export class tools extends plugin {
let url = removeParams(urlRex.exec(e.msg)?.[0] || url2Rex.exec(e.msg)?.[0]).replace(/&/g, isWindows ? '^&' : '&')
//非最高画质,就按照设定的来
let graphics = ""
if (this.YouTubeGraphicsOptions != 0) {
graphics = `[height<=${ this.YouTubeGraphicsOptions }]`
if (this.youtubeGraphicsOptions != 0) {
graphics = `[height<=${ this.youtubeGraphicsOptions }]`
}
// 适配 YouTube Music
if (url.includes("music")) {
@ -1954,7 +1956,7 @@ export class tools extends plugin {
}
const path = this.getCurDownloadPath(e);
await checkAndRemoveFile(path + "/temp.mp4")
await checkAndRemoveFile(path + "/Thumbnail.png")
await checkAndRemoveFile(path + "/thumbnail.png")
await ytDlpGetThumbnail(path, url, isOversea, this.myProxy)
const title = await ytDlpGetTilt(url, isOversea, this.myProxy).toString().replace(/\n/g, '');
// logger.info('标题------',title)
@ -1968,13 +1970,20 @@ export class tools extends plugin {
if (Duration > this.youtubeDuration) {
e.reply([
segment.image(`${path}/thumbnail.png`),
`${this.identifyPrefix}识别:油管,视频下载中请耐心等待 \n视频标题:${title}${DIVIDING_LINE.replace('{}', '限制说明')}\n视频时长:${(Duration / 60).toFixed(2).replace(/\.00$/, '')} 分钟\n大于管理员限定时长:${(this.youtubeDuration / 60).toFixed(2).replace(/\.00$/, '')} 分钟\n将截取限定时间部分`
`${this.identifyPrefix}识别:油管,视频时长超限 \n视频标题:${title}\n${DIVIDING_LINE.replace('{}', '限制说明').replace(/\n/g, '')}\n视频时长:${(Duration / 60).toFixed(2).replace(/\.00$/, '')} 分钟\n大于管理员限定解析时长:${(this.youtubeDuration / 60).toFixed(2).replace(/\.00$/, '')} 分钟`
]);
} else if (Duration > this.youtubeClipTime && timeRange != '00:00:00-00:00:00') {
e.reply([
segment.image(`${path}/thumbnail.png`),
`${this.identifyPrefix}识别:油管,视频截取中请耐心等待 \n视频标题:${title}\n✂️${DIVIDING_LINE.replace('{}', '截取说明').replace(/\n/g, '')}✂️\n视频时长:${(Duration / 60).toFixed(2).replace(/\.00$/, '')} 分钟\n大于管理员限定截取时长:${(this.youtubeClipTime / 60).toFixed(2).replace(/\.00$/, '')} 分钟\n将截取视频片段`
]);
} else {
e.reply([segment.image(`${ path }/thumbnail.png`),`${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n视频标题:${ title }\n视频时长:${(Duration / 60).toFixed(2).replace(/\.00$/, '')} 分钟`]);
}
await ytDlpHelper(path, url, isOversea, this.myProxy, this.videoDownloadConcurrency, true, graphics, timeRange);
this.sendVideoToUpload(e, `${path}/temp.mp4`);
} else {
e.reply([segment.image(`${path}/thumbnail.png`), `${this.identifyPrefix}识别:油管,视频下载中请耐心等待 \n视频标题:${title}\n视频时长:${(Duration / 60).toFixed(2).replace(/\.00$/, '')} 分钟`]);
await ytDlpHelper(path, url, isOversea, this.myProxy, this.videoDownloadConcurrency, true, graphics, timeRange);
this.sendVideoToUpload(e, `${path}/temp.mp4`);
}
} catch (error) {
logger.error(error);
throw error; // Rethrow the error so it can be handled by the caller

View File

@ -27,8 +27,9 @@ neteaseCookie: '' # 网易云ck
neteaseCloudAPIServer: '' # 网易云自建服务器地址
neteaseCloudAudioQuality: exhigh # 网易云解析最高音质 默认exhigh(极高) 分类standard => 标准,higher => 较高, exhigh=>极高, lossless=>无损, hires=>Hi-Res, jyeffect => 高清环绕声, sky => 沉浸环绕声, dolby => 杜比全景声, jymaster => 超清母带
YouTubeGraphicsOptions: 720 # YouTobe的下载画质0为原画1080720480自定义画面高度默认为720
youtubeDuration: 300 # YouTobe限制的最大视频时长默认5分钟单位
youtubeGraphicsOptions: 720 # YouTobe的下载画质0为原画1080720480自定义画面高度默认为720
youtubeClipTime: # YouTobe限制的最大视频时长默认不开启单位秒 最好不要超过5分钟否则截取效率非常低
youtubeDuration: 480 # YouTobe限制的最大视频时长默认8分钟单位秒 最好不要超过30分钟否则截取效率非常低
douyinCookie: '' # douyin's cookie, 格式odin_tt=xxx;passport_fe_beating_status=xxx;sid_guard=xxx;uid_tt=xxx;uid_tt_ss=xxx;sid_tt=xxx;sessionid=xxx;sessionid_ss=xxx;sid_ucp_v1=xxx;ssid_ucp_v1=xxx;passport_assist_user=xxx;ttwid=xxx;
douyinCompression: true # true-压缩false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送

View File

@ -222,17 +222,28 @@ export function supportGuoba() {
},
{
field: "tools.youtubeDuration",
label: "YouTuBe最大时长",
label: "YouTuBe最大解析时长",
bottomHelpMessage:
"超过时长会截取指定时间单位保护魔法的流量计算公式5分钟 x 60秒 = 300秒",
"超过时长不解析单位保护魔法的流量计算公式8分钟 x 60秒 = 480秒默认8分钟最好不超过30分钟",
component: "InputNumber",
required: false,
componentProps: {
placeholder: "请输入YouTuBe视频最大时长限制默认5分钟",
placeholder: "请输入YouTuBe视频最大时长限制",
},
},
{
field: "tools.YouTubeGraphicsOptions",
field: "tools.youtubeClipTime",
label: "YouTuBe截取时长",
bottomHelpMessage:
"超过时长会截取指定时间单位保护魔法的流量计算公式3分钟 x 60秒 = 180秒默认不开启最好不超过5分钟,0表无限or不开启",
component: "InputNumber",
required: false,
componentProps: {
placeholder: "请输入截取时长",
},
},
{
field: "tools.youtubeGraphicsOptions",
label: "YouTube最高分辨率",
bottomHelpMessage:
"油管下载的最高分辨率默认720p请根据自己魔法流量和服务器承载能力进行调整",