feat: 添加YouTube下载画质自定义

This commit is contained in:
秋刀鱼 2024-09-30 15:40:31 +08:00
parent 3d17f93df0
commit bbbfb6b45e
5 changed files with 30 additions and 4 deletions

View File

@ -254,6 +254,8 @@ export class tools extends plugin {
this.biliDownloadMethod = this.toolsConfig.biliDownloadMethod; this.biliDownloadMethod = this.toolsConfig.biliDownloadMethod;
// 加载哔哩哔哩最高分辨率 // 加载哔哩哔哩最高分辨率
this.biliResolution = this.toolsConfig.biliResolution; this.biliResolution = this.toolsConfig.biliResolution;
// 加载油管下载画质选项
this.YouTubeGraphicsOptions = this.toolsConfig.YouTubeGraphicsOptions
// 加载抖音Cookie // 加载抖音Cookie
this.douyinCookie = this.toolsConfig.douyinCookie; this.douyinCookie = this.toolsConfig.douyinCookie;
// 加载抖音是否压缩 // 加载抖音是否压缩
@ -1524,6 +1526,11 @@ export class tools extends plugin {
// 匹配并转义 URL 中的 & 符号(仅对 Windows 进行转义) // 匹配并转义 URL 中的 & 符号(仅对 Windows 进行转义)
let url = urlRex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&') || let url = urlRex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&') ||
url2Rex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&'); url2Rex.exec(e.msg)?.[0]?.replace(/&/g, isWindows ? '^&' : '&');
//非最高画质,就按照设定的来
let graphics = ""
if (this.YouTubeGraphicsOptions != 0) {
graphics = `[height<=${this.YouTubeGraphicsOptions}]`
}
// 适配 YouTube Music // 适配 YouTube Music
if (url.includes("music")) { if (url.includes("music")) {
// https://music.youtube.com/watch?v=F4sRtMoIgUs&si=7ZYrHjlI3fHAha0F // https://music.youtube.com/watch?v=F4sRtMoIgUs&si=7ZYrHjlI3fHAha0F
@ -1533,7 +1540,7 @@ export class tools extends plugin {
await checkAndRemoveFile(path + "/temp.mp4") await checkAndRemoveFile(path + "/temp.mp4")
const title = await ytDlpGetTilt(url, isOversea, this.myProxy); const title = await ytDlpGetTilt(url, isOversea, this.myProxy);
e.reply(`${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n${ title }`); e.reply(`${ this.identifyPrefix }识别:油管,视频下载中请耐心等待 \n${ title }`);
await ytDlpHelper(path, url, isOversea, this.myProxy, true); await ytDlpHelper(path, url, isOversea, this.myProxy, true, graphics);
this.sendVideoToUpload(e, `${ path }/temp.mp4`); this.sendVideoToUpload(e, `${ path }/temp.mp4`);
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@ -19,6 +19,8 @@ biliCDN: 0 # 哔哩哔哩 CDN默认为0表示不使用
biliDownloadMethod: 0 # 哔哩哔哩的下载方式0默认使用原生稳定的下载方式如果你在乎内存可以使用轻量的wget和axel下载方式如果在乎性能可以使用Aria2下载 biliDownloadMethod: 0 # 哔哩哔哩的下载方式0默认使用原生稳定的下载方式如果你在乎内存可以使用轻量的wget和axel下载方式如果在乎性能可以使用Aria2下载
biliResolution: 1 # 哔哩哔哩的下载画质0为原画1为清晰画2为流畅画默认为0 biliResolution: 1 # 哔哩哔哩的下载画质0为原画1为清晰画2为流畅画默认为0
YouTubeGraphicsOptions: 720 #YouTobe的下载画质0为原画1080720480自定义画面高度默认为720
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; 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-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送 douyinCompression: true # true-压缩false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送
douyinComments: false # true-开启评论false-关闭评论 douyinComments: false # true-开启评论false-关闭评论

View File

@ -187,6 +187,12 @@ export const BILI_RESOLUTION_LIST = Object.freeze([
{ label: '360P 流畅', value: 6 }, { label: '360P 流畅', value: 6 },
]); ]);
export const YOUTUBE_GRAPHICS_LIST = Object.freeze([
{ label: 'Best', value: 0 },
{ label: '1080P 高清', value: 1080 },
{ label: '720P 高清', value: 720 },
{ label: '480P 清晰', value: 480 },
]);
/** /**
* 消息撤回时间 * 消息撤回时间
* @type {number} * @type {number}

View File

@ -1,6 +1,6 @@
import _ from "lodash"; import _ from "lodash";
import path from "path"; import path from "path";
import { BILI_CDN_SELECT_LIST, BILI_DOWNLOAD_METHOD, BILI_RESOLUTION_LIST } from "./constants/constant.js"; import { BILI_CDN_SELECT_LIST, BILI_DOWNLOAD_METHOD, BILI_RESOLUTION_LIST, YOUTUBE_GRAPHICS_LIST } from "./constants/constant.js";
import model from "./model/config.js"; import model from "./model/config.js";
const pluginName = `rconsole-plugin`; const pluginName = `rconsole-plugin`;
@ -201,6 +201,16 @@ export function supportGuoba() {
options: BILI_RESOLUTION_LIST, options: BILI_RESOLUTION_LIST,
} }
}, },
{
field: "tools.YouTubeGraphicsOptions",
label: "YouTube最高分辨率",
bottomHelpMessage:
"油管下载的最高分辨率默认720p请根据自己魔法流量和服务器承载能力进行调整",
component: "Select",
componentProps: {
options: YOUTUBE_GRAPHICS_LIST,
}
},
{ {
field: "tools.douyinCookie", field: "tools.douyinCookie",
label: "抖音的Cookie", label: "抖音的Cookie",

View File

@ -29,12 +29,13 @@ export function ytDlpGetTilt(url, isOversea, proxy) {
* @param isOversea 是否是海外用户 * @param isOversea 是否是海外用户
* @param proxy 代理地址 * @param proxy 代理地址
* @param merge 是否合并输出为 mp4 格式 (仅适用于视频合并需求) * @param merge 是否合并输出为 mp4 格式 (仅适用于视频合并需求)
* @param graphics YouTube画质参数
*/ */
export async function ytDlpHelper(path, url, isOversea, proxy, merge = false) { export async function ytDlpHelper(path, url, isOversea, proxy, merge = false, graphics) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const mergeOption = merge ? '--merge-output-format "mp4"' : ''; const mergeOption = merge ? '--merge-output-format "mp4"' : '';
const fParam = url.includes("youtu") ? `-f "bv[height<=720][ext=mp4]+ba[ext=m4a]"` : ""; const fParam = url.includes("youtu") ? `-f "bv${graphics}[ext=mp4]+ba[ext=m4a]"` : "";
const command = `yt-dlp ${fParam} ${constructProxyParam(isOversea, proxy)} -P ${path} -o "temp.%(ext)s" ${url}`; const command = `yt-dlp ${fParam} ${constructProxyParam(isOversea, proxy)} -P ${path} -o "temp.%(ext)s" ${url}`;