Spaces:
Running
Running
v12.0.1: movies4u prefer long-lived m4uplay tokens over single-use acek tokens; persianstremio real backoff retries
Browse files1170 unmodified lines1171117211731174117511761177117811791180117611811182118311841185118646 unmodified lines12331234123512361237123812291230123112321233123412351236123712381239123912401241124212431244124512461247124812491250125112521253125412551170 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]) ok_m3u8 = {c["url"] for c, ok in zip(m3u8_cands, checks) if ok} 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 lines async with httpx.AsyncClient(timeout=25, follow_redirects=True) as client: data = None last_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): for attempt in range(3): # persianstremio (CF-fronted) intermittently 503s 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_code if resp.status_code == 200: data = resp.json() break await asyncio.sleep(1.5 * (attempt + 1)) 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_code if resp.status_code == 200: data = resp.json() break except Exception: last_status = 0 if attempt < 3: await asyncio.sleep(1.5 * (attempt + 1)) if data is None: errors.append(f"PersianStremio: API HTTP {last_status}") return results, errorsmain.py+25-12