From 4ffc99b3fe9017f7695e0523cf79665739c52aaf Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sat, 22 Aug 2026 14:41:53 +0700 Subject: [PATCH] fix(media): yt-dlp format fallback chain untuk direct-file URL upload.asepharyana.my.id redirect ke file mp3 tunggal; generic extractor yt-dlp expose format ID '0' sehingga '-f bestaudio' gagal 'Requested format is not available'. Chain bestaudio[ext=m4a]/bestaudio/best tetap dapat m4a di YouTube dan jatuh ke 'best' untuk direct file. --- .../src/modules/voice-recording/mediaSource.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/discord-gateway/src/modules/voice-recording/mediaSource.ts b/services/discord-gateway/src/modules/voice-recording/mediaSource.ts index f23e744..e83b8f1 100644 --- a/services/discord-gateway/src/modules/voice-recording/mediaSource.ts +++ b/services/discord-gateway/src/modules/voice-recording/mediaSource.ts @@ -31,7 +31,7 @@ export interface ResolveOptions { timeout?: number; /** * yt-dlp format string override (e.g. "bestaudio[ext=m4a]"). - * Defaults to "bestaudio". + * Defaults to "bestaudio[ext=m4a]/bestaudio/best". */ quality?: string; } @@ -319,7 +319,11 @@ export function resolveMediaUrl( options?: ResolveOptions, ): Promise { return new Promise((resolve, reject) => { - const format = options?.quality ?? "bestaudio"; + // Fallback chain: YouTube gets progressive m4a audio; direct-file hosts + // (upload mirror / Telegram files) expose a single generic format with an + // arbitrary ID — `bestaudio` alone fails there ("Requested format is not + // available"), so fall back to `bestaudio` then plain `best`. + const format = options?.quality ?? "bestaudio[ext=m4a]/bestaudio/best"; const cookieArgs = buildCookieArgs(); const args = [ "-f",