mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
🎈 pref: 通用化ytDlpHelper
This commit is contained in:
parent
009f50c516
commit
3b9efa2b04
@ -13,10 +13,13 @@ import {
|
|||||||
BILI_DEFAULT_INTRO_LEN_LIMIT,
|
BILI_DEFAULT_INTRO_LEN_LIMIT,
|
||||||
COMMON_USER_AGENT,
|
COMMON_USER_AGENT,
|
||||||
DIVIDING_LINE,
|
DIVIDING_LINE,
|
||||||
douyinTypeMap, DOWNLOAD_WAIT_DETECT_FILE_TIME,
|
douyinTypeMap,
|
||||||
HELP_DOC, MESSAGE_RECALL_TIME,
|
DOWNLOAD_WAIT_DETECT_FILE_TIME,
|
||||||
|
HELP_DOC,
|
||||||
|
MESSAGE_RECALL_TIME,
|
||||||
REDIS_YUNZAI_ISOVERSEA,
|
REDIS_YUNZAI_ISOVERSEA,
|
||||||
REDIS_YUNZAI_LAGRANGE, REDOS_YUNZAI_WHITELIST,
|
REDIS_YUNZAI_LAGRANGE,
|
||||||
|
REDOS_YUNZAI_WHITELIST,
|
||||||
SUMMARY_PROMPT,
|
SUMMARY_PROMPT,
|
||||||
transMap,
|
transMap,
|
||||||
TWITTER_BEARER_TOKEN,
|
TWITTER_BEARER_TOKEN,
|
||||||
@ -82,7 +85,7 @@ import { redisExistKey, redisGetKey, redisSetKey } from "../utils/redis-util.js"
|
|||||||
import { saveTDL, startTDL } from "../utils/tdl-util.js";
|
import { saveTDL, startTDL } from "../utils/tdl-util.js";
|
||||||
import Translate from "../utils/trans-strategy.js";
|
import Translate from "../utils/trans-strategy.js";
|
||||||
import { mid2id } from "../utils/weibo.js";
|
import { mid2id } from "../utils/weibo.js";
|
||||||
import { dy2b } from "../utils/yt-dlp-util.js";
|
import { ytDlpGetTilt, ytDlpHelper } from "../utils/yt-dlp-util.js";
|
||||||
import { textArrayToMakeForward } from "../utils/yunzai-util.js";
|
import { textArrayToMakeForward } from "../utils/yunzai-util.js";
|
||||||
|
|
||||||
export class tools extends plugin {
|
export class tools extends plugin {
|
||||||
@ -433,36 +436,14 @@ export class tools extends plugin {
|
|||||||
// 下载逻辑
|
// 下载逻辑
|
||||||
const path = this.getCurDownloadPath(e);
|
const path = this.getCurDownloadPath(e);
|
||||||
await checkAndRemoveFile(path + "/temp.mp4");
|
await checkAndRemoveFile(path + "/temp.mp4");
|
||||||
const title = execSync(`yt-dlp --get-title ${ cleanedTiktokUrl } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`)
|
const title = ytDlpGetTilt(url, isOversea, this.myProxy);
|
||||||
e.reply(`识别:TikTok,视频下载中请耐心等待 \n${ title }`);
|
e.reply(`识别:TikTok,视频下载中请耐心等待 \n${ title }`);
|
||||||
await this.tiktokHelper(path, cleanedTiktokUrl, isOversea);
|
await ytDlpHelper(path, cleanedTiktokUrl, isOversea, this.myProxy);
|
||||||
await this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
await this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* yt-dlp for tiktok 工具
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
* @param path 下载路径
|
|
||||||
* @param url 下载链接
|
|
||||||
* @param isOversea 是否是海外用户
|
|
||||||
*/
|
|
||||||
async tiktokHelper(path, url, isOversea) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ this.myProxy }` } -P ${ path } -o "temp.%(ext)s" ${ url }`;
|
|
||||||
exec(command, (error, stdout) => {
|
|
||||||
if (error) {
|
|
||||||
console.error(`Error executing command: ${ error }`);
|
|
||||||
reject(error);
|
|
||||||
} else {
|
|
||||||
console.log(`Command output: ${ stdout }`);
|
|
||||||
resolve(stdout);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 哔哩哔哩扫码登录
|
// 哔哩哔哩扫码登录
|
||||||
async biliScan(e) {
|
async biliScan(e) {
|
||||||
e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 });
|
e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 });
|
||||||
@ -1367,9 +1348,9 @@ export class tools extends plugin {
|
|||||||
}
|
}
|
||||||
const path = this.getCurDownloadPath(e);
|
const path = this.getCurDownloadPath(e);
|
||||||
await checkAndRemoveFile(path + "/temp.mp4")
|
await checkAndRemoveFile(path + "/temp.mp4")
|
||||||
const title = execSync(`yt-dlp --get-title ${ url } ${ isOversea ? "" : `--proxy ${ this.myProxy }` }`)
|
const title = await ytDlpGetTilt(url, isOversea, this.myProxy);
|
||||||
e.reply(`识别:油管,视频下载中请耐心等待 \n${ title }`);
|
e.reply(`识别:油管,视频下载中请耐心等待 \n${ title }`);
|
||||||
await dy2b(path, url, isOversea, this.myProxy);
|
await ytDlpHelper(path, url, isOversea, this.myProxy, true);
|
||||||
this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
this.sendVideoToUpload(e, `${ path }/temp.mp4`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -1,4 +1,25 @@
|
|||||||
import { exec } from "child_process";
|
import { exec, execSync } from "child_process";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建梯子参数
|
||||||
|
* @param isOversea
|
||||||
|
* @param proxy
|
||||||
|
* @returns {string|string}
|
||||||
|
*/
|
||||||
|
function constructProxyParam(isOversea, proxy) {
|
||||||
|
return isOversea ? "" : `--proxy ${ proxy }`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标题
|
||||||
|
* @param url
|
||||||
|
* @param isOversea
|
||||||
|
* @param proxy
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
export function ytDlpGetTilt(url, isOversea, proxy) {
|
||||||
|
return execSync(`yt-dlp --get-title ${ constructProxyParam(isOversea, proxy) } ${ url }`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* yt-dlp 工具类
|
* yt-dlp 工具类
|
||||||
@ -6,10 +27,14 @@ import { exec } from "child_process";
|
|||||||
* @param path 下载路径
|
* @param path 下载路径
|
||||||
* @param url 下载链接
|
* @param url 下载链接
|
||||||
* @param isOversea 是否是海外用户
|
* @param isOversea 是否是海外用户
|
||||||
|
* @param proxy 代理地址
|
||||||
|
* @param merge 是否合并输出为 mp4 格式 (仅适用于视频合并需求)
|
||||||
*/
|
*/
|
||||||
export async function dy2b(path, url, isOversea, proxy) {
|
export async function ytDlpHelper(path, url, isOversea, proxy, merge = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const command = `yt-dlp ${ isOversea ? "" : `--proxy ${ proxy }` } -P ${ path } -o "temp.%(ext)s" --merge-output-format "mp4" ${ url }`;
|
const mergeOption = merge ? '--merge-output-format "mp4"' : '';
|
||||||
|
const command = `yt-dlp ${ constructProxyParam(isOversea, proxy) } -P ${ path } -o "temp.%(ext)s" ${ mergeOption } ${ url }`;
|
||||||
|
|
||||||
exec(command, (error, stdout) => {
|
exec(command, (error, stdout) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Error executing command: ${error}`);
|
console.error(`Error executing command: ${error}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user