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 lines1147114811491150115111521153115411551156115711581159116011611162116311641165116611673 unmodified lines1171117211731174117511761177117811791180118111821183118411851186118711881146 unmodified linesif 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 playerasync 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 Falseif "#EXTM3U" in (vr.text or "")[:256]:return Truect = (vr.headers.get("content-type") or "").lower()return "mpegurl" in ct or "mp2t" in ct or "video/" in ctexcept Exception:return Falseseen = set()cand = []for r in results_all:3 unmodified linesseen.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()for r in cand:u = r["url"]1146 unmodified lines11471148114911501151115211531154115511563 unmodified lines1160116111621163116411651166116711681146 unmodified linesif resolved:results_all.extend(resolved)# 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 linesseen.add(u)cand.append(r)m3u8_cands = [c for c in cand if ".m3u8" in c["url"]]m3u8_cands.sort(key=lambda c: (0 if "m4uplay" in c["url"] else 1))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