بث مباشر بين سبورت | bein sport live 123 TV

export default { async fetch(request, env, ctx) { const referer = request.headers.get("Referer") || ""; const origin = request.headers.get("Origin") || ""; const allowedDomain = "123tv.fun"; if ( !referer.includes(allowedDomain) && !origin.includes(allowedDomain) ) { return new Response("Forbidden", { status: 403 }); } const target = new URL(request.url).searchParams.get("url"); if (!target) { return new Response("Missing url", { status: 400 }); } const cache = caches.default; const cacheKey = new Request(request.url, request); // cache فقط لغير m3u8 لاحقًا (نعرفها بعد الفetch) const res = await fetch(target, { headers: { "Referer": "https://912acsss8af382.shootny.com/", "origin": "https://912acsss8af382.shootny.com/", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" } }); const contentType = (res.headers.get("Content-Type") || "").toLowerCase(); const isM3U8 = contentType.includes("application/vnd.apple.mpegurl") || contentType.includes("application/x-mpegurl") || contentType.includes("audio/mpegurl"); let response; if (isM3U8) { let text = await res.text(); const base = target.substring(0, target.lastIndexOf("/") + 1); text = text.replace(/^(?!#)(.+)$/gm, (line) => { if (!line.trim()) return line; if (line.startsWith("http://") || line.startsWith("https://")) { return request.url.split("?")[0] + "?url=" + encodeURIComponent(line); } return request.url.split("?")[0] + "?url=" + encodeURIComponent(base + line); }); response = new Response(text, { headers: { "Content-Type": "application/vnd.apple.mpegurl", "Access-Control-Allow-Origin": "*", "Cache-Control": "no-store, no-cache, must-revalidate" } }); } else { const headers = new Headers(res.headers); // أي شيء ليس m3u8 = اعتبره TS headers.set("Content-Type", "video/mp2t"); headers.set("Cache-Control", "public, max-age=180"); headers.set("Access-Control-Allow-Origin", "*"); response = new Response(res.body, { status: res.status, statusText: res.statusText, headers }); ctx.waitUntil( cache.put(cacheKey, response.clone()) ); } return response; } };