Spaces:
Running
Running
v12.0.2: movies4u - drop pre-validation (it burns single-use tokens), return fresh tokens m4uplay-first capped at 2
Browse files1146 unmodified lines11471148114911501151115211531154115511561157115811591160116111621163116411501151115211531154115511563 unmodified lines116011611162117411751176117711631179118011811182118311841185116411651166116711681146 unmodified lines if resolved: results_all.extend(resolved)
# validate candidate m3u8s before returning them - acek-cdn/m4uplay sometimes # serve PNG block pages or dead tokens; never hand those to the player async def _valid_m3u8(mu: str) -> bool: try: async with httpx.AsyncClient(timeout=httpx.Timeout(10, connect=6), follow_redirects=True) as vc: vr = await vc.get(mu, headers={"User-Agent": _M4U_UA, "Referer": "https://m4uplay.store/"}) if vr.status_code != 200: return False if "#EXTM3U" in (vr.text or "")[:256]: return True ct = (vr.headers.get("content-type") or "").lower() return "mpegurl" in ct or "mp2t" in ct or "video/" in ct except Exception: return False
# m4uplay / acek-cdn m3u8 tokens are extremely short-lived and behave as # effectively single-use (a validation GET burns them -> PNG block page for # the player). So we do NOT pre-validate; instead return FRESH tokens per # scrape, m4uplay-hosted first (longest-lived), capped at 2 entries. seen = set() cand = [] for r in results_all:3 unmodified lines seen.add(u) cand.append(r) m3u8_cands = [c for c in cand if ".m3u8" in c["url"]] # m4uplay-hosted tokens are long-lived; acek-cdn tokens behave as effectively # single-use (the validation GET itself can burn them -> PNG block page right # after). So: prefer m4uplay entries; only keep an acek entry when nothing # better validated. m3u8_cands.sort(key=lambda c: (0 if "m4uplay" in c["url"] else 1)) if m3u8_cands: checks = await asyncio.gather(*[_valid_m3u8(c["url"]) for c in m3u8_cands]) valid = [c["url"] for c, ok in zip(m3u8_cands, checks) if ok] m4u_ok = [u for u in valid if "m4uplay" in u] ok_m3u8 = set(m4u_ok) if m4u_ok else set(valid[:1]) else: ok_m3u8 = set() m3u8_cands = m3u8_cands[:2] ok_m3u8 = {c["url"] for c in m3u8_cands}
for r in cand: u = r["url"]main.py+6-26