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.
This commit is contained in:
OpenClaw Agent 2026-04-30 08:09:16 +00:00
parent e950aed6b8
commit 810bed52c2

View File

@ -70,14 +70,17 @@ app.get('/stream/:n/master.m3u8', async (req, res) => {
} }
let text = await response.text(); let text = await response.text();
// Rewrite variant URLs from folxplay → folxlive zone, replacing CDN-edge-script tokens // Origin master.m3u8 may contain variant URLs in any of these messed-up forms:
// with our own tokens (4-hour TTL): // https://folxplay.b-cdn.net/live/streamN_1080p.m3u8?token=ABC&expires=N
// https://folxplay.b-cdn.net/live/stream1_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/stream1_1080p.m3u8?token=OURXYZ&expires=M // 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( text = text.replace(
/https:\/\/folxplay\.b-cdn\.net(\/[^\s?]+\.m3u8)(?:\?[^\s]*)?/g, /https:\/\/[^\s]*?\/(stream\d+_\d+p\.m3u8)(?:\?[^\s]*)?/g,
(_match, urlPath) => { (_match, filename) => {
const { url } = signBunnyUrl(urlPath, TOKEN_TTL); const variantPath = `/live/${filename}`;
const { url } = signBunnyUrl(variantPath, TOKEN_TTL);
return url; return url;
} }
); );