export default { async fetch(request) { const url = new URL(request.url); // 1) Static m3u8 banayen jo TS ko hamare proxy se bulaye if (url.pathname.endsWith("/playlist.m3u8")) { // Apne TS links yahan add karo (1 ya zyada) const LINKS = [ "http://d4k4u.com/live/Zak11_375144/QnS6dehx/690035.ts" // , "http://d4k4u.com/live/Zak11_375144/QnS6dehx/690036.ts" // example ]; let body = "#EXTM3U\n"; body += "#EXT-X-VERSION:3\n"; body += "#EXT-X-TARGETDURATION:10\n"; body += "#EXT-X-MEDIA-SEQUENCE:0\n"; for (const L of LINKS) { body += "#EXTINF:10.0,\n"; body += "/proxy?u=" + encodeURIComponent(L) + "\n"; } body += "#EXT-X-ENDLIST\n"; return new Response(body, { headers: { "Content-Type": "application/vnd.apple.mpegurl", "Access-Control-Allow-Origin": "*", "Cache-Control": "no-store" } }); } // 2) Proxy endpoint: asal .ts ko fetch karke CORS/HTTPS ke sath serve karo if (url.pathname.startsWith("/proxy")) { const target = url.searchParams.get("u"); if (!target) return new Response("Missing ?u=", { status: 400 }); const upstream = await fetch(target, { headers: { // Kuch servers UA/Referer check karte hain "User-Agent": "Mozilla/5.0", "Referer": new URL(target).origin + "/" } }); const headers = new Headers(upstream.headers); headers.set("Content-Type", "video/mp2t"); // TS MIME headers.set("Access-Control-Allow-Origin", "*"); // CORS OK headers.set("Cache-Control", "no-store"); // live-ish return new Response(upstream.body, { status: upstream.status, headers }); } // Help text return new Response( "OK: use /playlist.m3u8 in your HLS player, or /proxy?u=", { headers: { "Content-Type": "text/plain" } } ); } }