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.
This commit is contained in:
asepharyana
2026-08-22 14:41:53 +07:00
parent 81ce5188ea
commit 4ffc99b3fe
@@ -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<MediaSourceResolution> {
return new Promise<MediaSourceResolution>((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",