From 810bed52c2f0832fb044de1d20617ef97db6ae7d Mon Sep 17 00:00:00 2001 From: OpenClaw Agent Date: Thu, 30 Apr 2026 08:09:16 +0000 Subject: [PATCH] fix(master-proxy): rebuild variant URLs from filename only Origin master.m3u8 contains broken double-tokened URLs after Rok's encoder change (e.g. bcdn_token=...&token_path=... + ?token=...). Old regex matched only 'folxplay.b-cdn.net' so it skipped the broken 'folxlive.b-cdn.net' URLs and the player got malformed double tokens. New regex matches any CDN URL ending in streamN_NNNNp.m3u8 and rebuilds a clean folxlive URL with our 4h token, ignoring whatever mess the upstream sends. --- src/server.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/server.js b/src/server.js index cb3bd3a..6ba07fe 100644 --- a/src/server.js +++ b/src/server.js @@ -70,14 +70,17 @@ app.get('/stream/:n/master.m3u8', async (req, res) => { } let text = await response.text(); - // Rewrite variant URLs from folxplay → folxlive zone, replacing CDN-edge-script tokens - // with our own tokens (4-hour TTL): - // https://folxplay.b-cdn.net/live/stream1_1080p.m3u8?token=ABC&expires=N - // → https://folxlive.b-cdn.net/live/stream1_1080p.m3u8?token=OURXYZ&expires=M + // Origin master.m3u8 may contain variant URLs in any of these messed-up forms: + // https://folxplay.b-cdn.net/live/streamN_1080p.m3u8?token=ABC&expires=N + // https://folxplay.b-cdn.net/bcdn_token=XYZ&expires=N&token_path=%2Flive%2F/live/streamN_1080p.m3u8 + // https://folxlive.b-cdn.net/live/streamN_1080p.m3u8 (already plain) + // Strategy: ignore everything in the upstream URL except the trailing filename + // (streamN_*.m3u8) and rebuild a clean signed folxlive URL. text = text.replace( - /https:\/\/folxplay\.b-cdn\.net(\/[^\s?]+\.m3u8)(?:\?[^\s]*)?/g, - (_match, urlPath) => { - const { url } = signBunnyUrl(urlPath, TOKEN_TTL); + /https:\/\/[^\s]*?\/(stream\d+_\d+p\.m3u8)(?:\?[^\s]*)?/g, + (_match, filename) => { + const variantPath = `/live/${filename}`; + const { url } = signBunnyUrl(variantPath, TOKEN_TTL); return url; } );