From 884018a6d1446abbbedd8c6cd50fb6de56cae876 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Fri, 11 Sep 2026 03:03:50 +0300 Subject: [PATCH] ... --- src/music/audio/FluxerAudioBridge.mjs | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/music/audio/FluxerAudioBridge.mjs b/src/music/audio/FluxerAudioBridge.mjs index 39bf974..c0b6db1 100644 --- a/src/music/audio/FluxerAudioBridge.mjs +++ b/src/music/audio/FluxerAudioBridge.mjs @@ -80,9 +80,12 @@ export class FluxerAudioBridge extends EventEmitter { const direct = await this._getTrackstreamUrl(trackInfo); if (direct?.url && /webm|opus/i.test(direct.format || "")) { this._usedTrackstream = true; - logger.player("[AudioBridge] Passthrough webm/opus via trackstream (zero-copy): " + (trackInfo.title || "unknown")); + logger.player("[AudioBridge] Passthrough webm/opus via trackstream: " + (trackInfo.title || "unknown")); - await conn.play(direct.url); + const directLoaded = await this._httpRequestStream(direct.url, this._streamFetchHeaders(trackInfo)); + this._sourceStream = directLoaded.stream; + this._sourceReq = directLoaded.req || null; + await conn.play(directLoaded.stream); if (generation !== this._playGeneration) return "stopped"; if (durationMs > 0) await this._waitDuration(durationMs); @@ -105,8 +108,11 @@ export class FluxerAudioBridge extends EventEmitter { const freshDirect = await this._getTrackstreamUrl(trackInfo); if (freshDirect?.url && /webm|opus/i.test(freshDirect.format || "")) { this._usedTrackstream = true; - logger.player("[AudioBridge] Fresh trackstream is webm/opus — zero-copy passthrough: " + (trackInfo.title || "unknown")); - await conn.play(freshDirect.url); + logger.player("[AudioBridge] Fresh trackstream is webm/opus — passthrough: " + (trackInfo.title || "unknown")); + const freshLoaded = await this._httpRequestStream(freshDirect.url, this._streamFetchHeaders(trackInfo)); + this._sourceStream = freshLoaded.stream; + this._sourceReq = freshLoaded.req || null; + await conn.play(freshLoaded.stream); if (generation !== this._playGeneration) return "stopped"; if (durationMs > 0) await this._waitDuration(durationMs); if (generation !== this._playGeneration) return "stopped"; @@ -304,6 +310,26 @@ export class FluxerAudioBridge extends EventEmitter { } } + /** + * @param {object} trackInfo + * @returns {object} + * @private + */ + _streamFetchHeaders(trackInfo) { + const headers = {}; + if (trackInfo?.url && /^https?:\/\//i.test(trackInfo.url)) { + try { + const host = new URL(trackInfo.url).hostname; + if (/(^|\.)bilibili\.com$/i.test(host)) { + headers["Referer"] = "https://www.bilibili.com/"; + } else { + headers["Referer"] = new URL(trackInfo.url).origin + "/"; + } + } catch (_) {} + } + return headers; + } + /** Stop current playback and clean up resources. */ stop() { const wasPlaying = this._playing;