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; } );