Spaces:
Running
Running
v12.0.1: movies4u prefer long-lived m4uplay tokens over single-use acek tokens; persianstremio real backoff retries
Browse files1170 unmodified lines11711172117311741175117611771178117946 unmodified lines122612271228122912301231123212331234123512361237123812391240124112421170 unmodified linesseen.add(u)cand.append(r)m3u8_cands = [c for c in cand if ".m3u8" in c["url"]]if m3u8_cands:checks = await asyncio.gather(*[_valid_m3u8(c["url"]) for c in m3u8_cands])ok_m3u8 = {c["url"] for c, ok in zip(m3u8_cands, checks) if ok}else:ok_m3u8 = set()46 unmodified linesasync with httpx.AsyncClient(timeout=25, follow_redirects=True) as client:data = Nonelast_status = 0for attempt in range(3): # persianstremio (CF-fronted) intermittently 503sresp = await client.get(url, headers={"User-Agent": HEADERS["User-Agent"],"Accept": "application/json, text/plain, */*","Accept-Language": "en-US,en;q=0.9",})last_status = resp.status_codeif resp.status_code == 200:data = resp.json()breakawait asyncio.sleep(1.5 * (attempt + 1))if data is None:errors.append(f"PersianStremio: API HTTP {last_status}")return results, errors1170 unmodified lines117111721173117411751176117711781179118011811182118311841185118646 unmodified lines123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551170 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()46 unmodified linesasync with httpx.AsyncClient(timeout=25, follow_redirects=True) as client:data = Nonelast_status = 0# the vercel API intermittently 503s datacenter IPs (HF included) -># retry with real backoff before giving up (1.5s / 3s / 4.5s)for attempt in range(4):try:resp = await client.get(url, headers={"User-Agent": HEADERS["User-Agent"],"Accept": "application/json, text/plain, */*","Accept-Language": "en-US,en;q=0.9",})last_status = resp.status_codeif resp.status_code == 200:data = resp.json()breakexcept Exception:last_status = 0if attempt < 3:await asyncio.sleep(1.5 * (attempt + 1))if data is None:errors.append(f"PersianStremio: API HTTP {last_status}")return results, errors
main.py+25-12