mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
Merge pull request #22 from nikoyoke1/master
添加YouTube画质选项/优化油管链接解析[beta]
This commit is contained in:
commit
82b80c5a09
@ -254,6 +254,8 @@ export class tools extends plugin {
|
||||
this.biliDownloadMethod = this.toolsConfig.biliDownloadMethod;
|
||||
// 加载哔哩哔哩最高分辨率
|
||||
this.biliResolution = this.toolsConfig.biliResolution;
|
||||
// 加载油管下载画质选项
|
||||
this.YouTubeGraphicsOptions = this.toolsConfig.YouTubeGraphicsOptions
|
||||
// 加载抖音Cookie
|
||||
this.douyinCookie = this.toolsConfig.douyinCookie;
|
||||
// 加载抖音是否压缩
|
||||
@ -1519,12 +1521,20 @@ 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;
|
||||
//移除链接中的不需要的参数
|
||||
function removeParams(url) {
|
||||
return url.replace(/&list=[^&]*/g, '').replace(/&start_radio=[^&]*/g, '').replace(/&index=[^&]*/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 ? '^&' : '&');
|
||||
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}]`
|
||||
}
|
||||
// 适配 YouTube Music
|
||||
if (url.includes("music")) {
|
||||
// https://music.youtube.com/watch?v=F4sRtMoIgUs&si=7ZYrHjlI3fHAha0F
|
||||
@ -1534,7 +1544,7 @@ export class tools extends plugin {
|
||||
await checkAndRemoveFile(path + "/temp.mp4")
|
||||
const title = await ytDlpGetTilt(url, isOversea, this.myProxy);
|
||||
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`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -19,6 +19,8 @@ biliCDN: 0 # 哔哩哔哩 CDN,默认为0表示不使用
|
||||
biliDownloadMethod: 0 # 哔哩哔哩的下载方式:0默认使用原生稳定的下载方式,如果你在乎内存可以使用轻量的wget和axel下载方式,如果在乎性能可以使用Aria2下载
|
||||
biliResolution: 1 # 哔哩哔哩的下载画质,0为原画,1为清晰画,2为流畅画(默认为0)
|
||||
|
||||
YouTubeGraphicsOptions: 720 #YouTobe的下载画质,0为原画,1080,720,480,自定义画面高度(默认为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;
|
||||
douyinCompression: true # true-压缩,false-不压缩;是否使用压缩视频格式的抖音(默认使用),使用后加速视频发送
|
||||
douyinComments: false # true-开启评论,false-关闭评论
|
||||
|
@ -187,6 +187,12 @@ export const BILI_RESOLUTION_LIST = Object.freeze([
|
||||
{ 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}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import _ from "lodash";
|
||||
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";
|
||||
|
||||
const pluginName = `rconsole-plugin`;
|
||||
@ -201,6 +201,16 @@ export function supportGuoba() {
|
||||
options: BILI_RESOLUTION_LIST,
|
||||
}
|
||||
},
|
||||
{
|
||||
field: "tools.YouTubeGraphicsOptions",
|
||||
label: "YouTube最高分辨率",
|
||||
bottomHelpMessage:
|
||||
"油管下载的最高分辨率(默认720p,请根据自己魔法流量和服务器承载能力进行调整)",
|
||||
component: "Select",
|
||||
componentProps: {
|
||||
options: YOUTUBE_GRAPHICS_LIST,
|
||||
}
|
||||
},
|
||||
{
|
||||
field: "tools.douyinCookie",
|
||||
label: "抖音的Cookie",
|
||||
|
@ -29,12 +29,13 @@ export function ytDlpGetTilt(url, isOversea, proxy) {
|
||||
* @param isOversea 是否是海外用户
|
||||
* @param proxy 代理地址
|
||||
* @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) => {
|
||||
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}`;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user