mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(audio): resolve HTTP 403 on radio streams and improve direct media decode fallback
- Update default User-Agent across SafeHttp, HttpStreams, FluxerAudioBridge, and Player to a modern Chrome browser string, preventing HTTP 403 blocks on Icecast/SomaFM streams. - Guard SafeHttp probe in Route C with try/catch to gracefully fall through to in-process FFmpeg decode when direct HTTP streaming probes fail. - Restrict YouTube origin and referer headers in FFmpeg to YouTube/Googlevideo domains only so external audio hosts and radio CDNs are not rejected. - Prevent false error rejections on FFmpeg exit when audio has already been delivered to the voice connection. - Improve error reporting in Route 3d so enabled allowLoadstream configurations report actual underlying decode errors instead of false toggle prompts.
This commit is contained in:
1 parent
3ea54939b9
commit
e3dd7ad914
4 files changed
+38
-24
No files matched your search
@@ -182,25 +182,36 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
return "stopped";
|
return "stopped";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Route C: direct URL — only for tracks WITHOUT an encoded payload
|
/* ── Route C: direct URL — only for tracks WITHOUT an encoded payload
|
||||||
// (Bilibili proxy, radio, direct links). Encoded tracks that reached
|
(Bilibili proxy, radio, direct links). Encoded tracks that reached
|
||||||
// this point get the explicit error below instead of fetching their
|
this point get the explicit error below instead of fetching their
|
||||||
// source page.
|
source page. */
|
||||||
if (!trackInfo.encoded && trackInfo.url && trackInfo.url.startsWith("http")) {
|
if (!trackInfo.encoded && trackInfo.url && trackInfo.url.startsWith("http")) {
|
||||||
logger.player("[AudioBridge] Route 3: Fetching directly via SafeHttp: " + trackInfo.url.substring(0, 80) + "...");
|
logger.player("[AudioBridge] Route 3: Fetching directly via SafeHttp: " + trackInfo.url.substring(0, 80) + "...");
|
||||||
const { openPublicStream } = await import("./SafeHttp.mjs");
|
let stream = null;
|
||||||
const { stream, req } = await openPublicStream(trackInfo.url, {
|
let routed = null;
|
||||||
headers: { "User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)" },
|
try {
|
||||||
});
|
const { openPublicStream } = await import("./SafeHttp.mjs");
|
||||||
this._sourceStream = stream;
|
const opened = await openPublicStream(trackInfo.url, {
|
||||||
this._sourceReq = req || null;
|
headers: {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
|
"Accept": "*/*",
|
||||||
|
"Icy-MetaData": "1",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
stream = opened.stream;
|
||||||
|
this._sourceStream = stream;
|
||||||
|
this._sourceReq = opened.req || null;
|
||||||
|
routed = await this._routeByMagic(stream);
|
||||||
|
} catch (openErr) {
|
||||||
|
logger.warn("[AudioBridge] Route 3 SafeHttp probe failed (" + openErr.message + "), falling back to in-process ffmpeg...");
|
||||||
|
}
|
||||||
|
|
||||||
const routed = await this._routeByMagic(stream);
|
if (routed?.kind === "webm") {
|
||||||
if (routed.kind === "webm") {
|
|
||||||
logger.player("[AudioBridge] Route 3a: webm/opus passthrough: " + (trackInfo.title || "unknown"));
|
logger.player("[AudioBridge] Route 3a: webm/opus passthrough: " + (trackInfo.title || "unknown"));
|
||||||
this._stream = routed.stream;
|
this._stream = routed.stream;
|
||||||
await conn.play(routed.stream);
|
await conn.play(routed.stream);
|
||||||
} else if (routed.kind === "ogg") {
|
} else if (routed?.kind === "ogg") {
|
||||||
logger.player("[AudioBridge] Route 3b: ogg/opus remux to webm: " + (trackInfo.title || "unknown"));
|
logger.player("[AudioBridge] Route 3b: ogg/opus remux to webm: " + (trackInfo.title || "unknown"));
|
||||||
const oggResult = await this._remuxOggToWebM(routed.stream);
|
const oggResult = await this._remuxOggToWebM(routed.stream);
|
||||||
this._stream = oggResult;
|
this._stream = oggResult;
|
||||||
@@ -230,9 +241,12 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
}
|
}
|
||||||
return "stopped";
|
return "stopped";
|
||||||
} else {
|
} else {
|
||||||
stream.destroy();
|
if (stream) {
|
||||||
this._sourceStream = null;
|
try { stream.destroy(); } catch (_) {}
|
||||||
logger.player("[AudioBridge] Route 3c: Direct stream is " + routed.kind + " (MP3/AAC?) — resolving through Lavalink...");
|
this._sourceStream = null;
|
||||||
|
}
|
||||||
|
const streamKind = routed?.kind || "pcm";
|
||||||
|
logger.player("[AudioBridge] Route 3c: Direct stream is " + streamKind + " (MP3/AAC?) — resolving through Lavalink...");
|
||||||
|
|
||||||
const encoded = this._lavalink
|
const encoded = this._lavalink
|
||||||
? await this._resolveUrlViaLavalink(trackInfo.url, trackInfo.guildId)
|
? await this._resolveUrlViaLavalink(trackInfo.url, trackInfo.guildId)
|
||||||
@@ -243,8 +257,8 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
const result3c = await this._playViaTrackstream(conn, trackInfo, { seekMs, durationMs, generation });
|
const result3c = await this._playViaTrackstream(conn, trackInfo, { seekMs, durationMs, generation });
|
||||||
if (result3c !== null) return result3c;
|
if (result3c !== null) return result3c;
|
||||||
if (generation !== this._playGeneration) return "stopped";
|
if (generation !== this._playGeneration) return "stopped";
|
||||||
// Trackstream could not serve the resolved track either — fall
|
/* Trackstream could not serve the resolved track either — fall
|
||||||
// through to loadstream when allowed, else the explicit error.
|
through to loadstream when allowed, else the explicit error. */
|
||||||
if (loadstreamEnabled) {
|
if (loadstreamEnabled) {
|
||||||
try {
|
try {
|
||||||
const loaded3c = await this._streamFromLoadstream(trackInfo, seekMs, null);
|
const loaded3c = await this._streamFromLoadstream(trackInfo, seekMs, null);
|
||||||
@@ -298,13 +312,13 @@ export class FluxerAudioBridge extends EventEmitter {
|
|||||||
|
|
||||||
if (loadstreamEnabled) {
|
if (loadstreamEnabled) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"[AudioBridge] Direct stream is " + routed.kind + " (MP3/AAC/PCM?) — NodeLink could not resolve an encoded track " +
|
"[AudioBridge] Direct stream is " + streamKind + " (MP3/AAC/PCM?) — NodeLink could not resolve an encoded track " +
|
||||||
"and in-process FFmpeg failed" + (ffmpegFailReason ? ": " + ffmpegFailReason : ". Ensure ffmpeg is installed in PATH.")
|
"and in-process FFmpeg failed" + (ffmpegFailReason ? ": " + ffmpegFailReason : ". Ensure ffmpeg is installed in PATH.")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"[AudioBridge] Direct stream is " + routed.kind + " (MP3/AAC/PCM?) — this format needs server-side decoding or ffmpeg. " +
|
"[AudioBridge] Direct stream is " + streamKind + " (MP3/AAC/PCM?) — this format needs server-side decoding or ffmpeg. " +
|
||||||
"Set audio.allowLoadstream to true in config.json (requires a NodeLink exposing /v4/loadstream), " +
|
"Set audio.allowLoadstream to true in config.json (requires a NodeLink exposing /v4/loadstream), " +
|
||||||
"or ensure ffmpeg is installed in PATH."
|
"or ensure ffmpeg is installed in PATH."
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ const HttpStreams = {
|
|||||||
port: urlObj.port,
|
port: urlObj.port,
|
||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: { "User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)", ...headers },
|
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", ...headers },
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||||
res.resume();
|
res.resume();
|
||||||
@@ -125,7 +125,7 @@ const HttpStreams = {
|
|||||||
port: urlObj.port,
|
port: urlObj.port,
|
||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: { "User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)", ...headers },
|
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", ...headers },
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||||
if (connectTimer) { clearTimeout(connectTimer); connectTimer = null; }
|
if (connectTimer) { clearTimeout(connectTimer); connectTimer = null; }
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ function requestOnce(u, { headers, lookup, connectTimeoutMs, idleTimeoutMs }) {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
agent: false,
|
agent: false,
|
||||||
lookup,
|
lookup,
|
||||||
headers: { Accept: "*/*", "Accept-Encoding": "identity", ...headers },
|
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", Accept: "*/*", "Accept-Encoding": "identity", ...headers },
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
settled = true;
|
settled = true;
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ class Player extends EventEmitter {
|
|||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
method: options.method || "GET",
|
method: options.method || "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)",
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
"Accept": "*/*",
|
"Accept": "*/*",
|
||||||
...options.headers,
|
...options.headers,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user