Spaces:
Running
Running
v11.2: Movies4u m3u8 via proxy (IP-bound tokens), Castle corrupt-key guards (retry+skip), final playability fixes
Browse files119 unmodified lines120121122123124125126127128129130131132133134135136532 unmodified lines66967067166167267367467510 unmodified lines6866876886786896906916925 unmodified lines6986997007017027037047057069 unmodified lines716717718719720721722723381 unmodified lines110511061107110811091110111110931112111311141115119 unmodified lines return detected return ""
_SF_CTRL_ENC = re.compile(r'%(0[0-9a-f]|1[0-9a-f]|7f)', re.IGNORECASE)
def _sf_url_has_ctrl(u: str) -> bool: """Detect literal or percent-encoded control characters in a URL.""" if not u: return True if re.search(r'[\x00-\x1f\x7f]', u): return True return bool(_SF_CTRL_ENC.search(u))
def _sf_stream_result(source: str, title: str, url: str, quality: str = "Auto", language: str = "English", headers: dict = None,532 unmodified lines continue
# some key batches contain control chars (corrupt auth_key) - retry once if re.search(r'[\x00-\x1f\x7f]', vurl): if _sf_url_has_ctrl(vurl): vr = await client.post( f"{CASTLE_BASE}/film-api/v2.0.1/movie/getVideo2", params={"clientType": CLI, "packageName": PKG, "channel": CH, "lang": LANG},10 unmodified lines vurl = vd["videoUrl"] except Exception: pass if re.search(r'[\x00-\x1f\x7f]', vurl): if _sf_url_has_ctrl(vurl): continue
quality_map = {1: "480P", 2: "720P", 3: "1080P"}5 unmodified lines if not isinstance(v, dict): continue vu = v.get("url", vurl) # skip entries with corrupted auth_key (control chars, raw or %XX) if _sf_url_has_ctrl(vu): continue q = v.get("resolutionDescription", v.get("resolution", quality)) q = re.sub(r'^(SD|HD|FHD)\s+', '', str(q)) subs = v.get("subtitles", [])9 unmodified lines result_item["subtitles"] = subs results.append(result_item) else: if _sf_url_has_ctrl(vurl): continue results.append({ "source": "Castle", "title": f"Castle [{lang_name}] - {quality}",381 unmodified lines if media_type == "tv" and not _sf_episode_matches(label, season or 1, episode or 1): continue if ".m3u8" in u: # m4uplay tokens are IP-bound -> serve through our proxy so the # playlist AND every segment flow from the API (same IP as the token) pu = _proxy_wrap(u, ref="https://m4uplay.store/", ua=_M4U_UA) results.append(_sf_stream_result( "Movies4u", f"Movies4u - {label}", u, "Movies4u", f"Movies4u - {label}", pu, quality=_sf_quality_from_name(label), language=_sf_lang_from_name(label))) elif any(u.endswith(ext) or f"{ext}?" in u for ext in (".mkv", ".mp4")) or "googleusercontent" in u: results.append(_sf_stream_result(main.py+22-3