Support a proxy for networks where YouTube is unreachable

YTDLP_PROXY routes every yt-dlp call — search, metadata and the audio
stream, for YouTube and SoundCloud alike — through an http(s) or SOCKS
proxy such as a local Psiphon. Startup logs which proxy is in use with
any credentials stripped.

ffmpeg has no SOCKS support, so with a proxy configured playback always
goes through the yt-dlp pipe instead of a resolved CDN URL: nothing
escapes past the proxy, at the cost of slower seeking. Direct links keep
using ffmpeg, which gets the proxy only when it speaks http(s).

Verified against a dead proxy: requests fail through it rather than
quietly going direct.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Leonid Pershin
2026-09-09 00:24:09 +03:00
co-authored by Claude Opus 5
parent 6d65134f8e
commit 71b9b7fe17
7 changed files with 104 additions and 24 deletions
+12
View File
@@ -33,6 +33,7 @@ interface YtDlpEntry {
function baseArgs(): string[] {
const args = ["--no-warnings", "--no-playlist-reverse", "--ignore-config", "--no-color"];
if (config.YTDLP_COOKIES) args.push("--cookies", config.YTDLP_COOKIES);
if (config.YTDLP_PROXY) args.push("--proxy", config.YTDLP_PROXY);
for (const value of config.YTDLP_EXTRACTOR_ARGS?.split(";") ?? []) {
const trimmed = value.trim();
if (trimmed) args.push("--extractor-args", trimmed);
@@ -40,6 +41,17 @@ function baseArgs(): string[] {
return args;
}
/** Proxy URLs often carry credentials, which have no business in logs. */
export function describeProxy(): string | null {
if (!config.YTDLP_PROXY) return null;
try {
const url = new URL(config.YTDLP_PROXY);
return `${url.protocol}//${url.username ? "***@" : ""}${url.host}`;
} catch {
return "(некорректный URL)";
}
}
export type CookieStatus = "ok" | "read-only" | "missing";
/**