From 0b12e2d4967085a85cc2dc63658fb85a10e47400 Mon Sep 17 00:00:00 2001 From: Supositware Date: Wed, 28 Aug 2024 14:17:46 +0200 Subject: [PATCH] Add proxy option to yt-dlp --- .env.example | 3 ++- commands/utility/download.js | 5 +++-- utils/videos.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 083ff08..b7647db 100644 --- a/.env.example +++ b/.env.example @@ -16,4 +16,5 @@ botsggEndpoint=https://discord.bots.gg/api/v1 stableHordeApi=0000000000 stableHordeID=0000 NODE_ENV=development -ytdlpMaxResolution=720 \ No newline at end of file +ytdlpMaxResolution=720 +proxy=socks5://localhost:3128 \ No newline at end of file diff --git a/commands/utility/download.js b/commands/utility/download.js index 109ea96..53e9228 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -8,6 +8,7 @@ let client; let maxFileSize; let { ytdlpMaxResolution } = process.env; +const { proxy } = process.env; // Convert to number as process.env is always a string ytdlpMaxResolution = Number(ytdlpMaxResolution); @@ -60,7 +61,7 @@ export default { if (format) { let qualitys = await new Promise((resolve, reject) => { - execFile('./bin/yt-dlp', [url, '--print', '%()j'], (err, stdout, stderr) => { + execFile('./bin/yt-dlp', [proxy ? '--proxy' : '', proxy ? proxy : '', url, '--print', '%()j'], (err, stdout, stderr) => { if (err) { reject(stderr); } @@ -310,7 +311,7 @@ async function checkSize(url, format, args, interaction, tries = 0) { async function getVideoDescription(urlArg) { return await new Promise((resolve, reject) => { - execFile('./bin/yt-dlp', [urlArg, '--no-warnings', '-O', '%(description)s'], (err, stdout, stderr) => { + execFile('./bin/yt-dlp', [proxy ? '--proxy' : '', proxy ? proxy : '', urlArg, '--no-warnings', '-O', '%(description)s'], (err, stdout, stderr) => { if (err) { reject(stderr); } diff --git a/utils/videos.js b/utils/videos.js index 174618f..f964e89 100644 --- a/utils/videos.js +++ b/utils/videos.js @@ -1,6 +1,6 @@ import os from 'node:os'; import { execFile } from 'node:child_process'; -const { NODE_ENV, ytdlpMaxResolution } = process.env; +const { NODE_ENV, ytdlpMaxResolution, proxy } = process.env; export default { downloadVideo, @@ -15,7 +15,7 @@ export default { }; async function downloadVideo(urlArg, output, format = `bestvideo[height<=?${ytdlpMaxResolution}]+bestaudio/best`) { await new Promise((resolve, reject) => { - execFile('./bin/yt-dlp', ['-f', format, urlArg, '-o', `${os.tmpdir()}/${output}.%(ext)s`, '--force-overwrites', '--no-playlist', '--remux-video=mp4/webm/mov', '--no-warnings'], (err, stdout, stderr) => { + execFile('./bin/yt-dlp', [proxy ? '--proxy' : '', proxy ? proxy : '', '-f', format, urlArg, '-o', `${os.tmpdir()}/${output}.%(ext)s`, '--force-overwrites', '--no-playlist', '--remux-video=mp4/webm/mov', '--no-warnings'], (err, stdout, stderr) => { if (err) { return reject(stderr); }