Spaces:
Running
Running
v11.2: Movies4u m3u8 via proxy (IP-bound tokens), Castle corrupt-key guards (retry+skip), final playability fixes
Browse files119 unmodified lines120121122123124125532 unmodified lines65865966066166266366410 unmodified lines6756766776786796806815 unmodified lines6876886896906916929 unmodified lines702703704705706707381 unmodified lines10891090109110921093109410951096119 unmodified linesreturn detectedreturn ""def _sf_stream_result(source: str, title: str, url: str, quality: str = "Auto",language: str = "English", headers: dict = None,532 unmodified linescontinue# some key batches contain control chars (corrupt auth_key) - retry onceif re.search(r'[\x00-\x1f\x7f]', 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 linesvurl = vd["videoUrl"]except Exception:passif re.search(r'[\x00-\x1f\x7f]', vurl):continuequality_map = {1: "480P", 2: "720P", 3: "1080P"}5 unmodified linesif not isinstance(v, dict):continuevu = v.get("url", vurl)q = v.get("resolutionDescription", v.get("resolution", quality))q = re.sub(r'^(SD|HD|FHD)\s+', '', str(q))subs = v.get("subtitles", [])9 unmodified linesresult_item["subtitles"] = subsresults.append(result_item)else:results.append({"source": "Castle","title": f"Castle [{lang_name}] - {quality}",381 unmodified linesif media_type == "tv" and not _sf_episode_matches(label, season or 1, episode or 1):continueif ".m3u8" in u:results.append(_sf_stream_result("Movies4u", f"Movies4u - {label}", u,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(119 unmodified lines120121122123124125126127128129130131132133134135136532 unmodified lines66967067167267367467510 unmodified lines6866876886896906916925 unmodified lines6986997007017027037047057069 unmodified lines716717718719720721722723381 unmodified lines11051106110711081109111011111112111311141115119 unmodified linesreturn detectedreturn ""_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 Trueif re.search(r'[\x00-\x1f\x7f]', u):return Truereturn 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 linescontinue# some key batches contain control chars (corrupt auth_key) - retry onceif _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 linesvurl = vd["videoUrl"]except Exception:passif _sf_url_has_ctrl(vurl):continuequality_map = {1: "480P", 2: "720P", 3: "1080P"}5 unmodified linesif not isinstance(v, dict):continuevu = v.get("url", vurl)# skip entries with corrupted auth_key (control chars, raw or %XX)if _sf_url_has_ctrl(vu):continueq = v.get("resolutionDescription", v.get("resolution", quality))q = re.sub(r'^(SD|HD|FHD)\s+', '', str(q))subs = v.get("subtitles", [])9 unmodified linesresult_item["subtitles"] = subsresults.append(result_item)else:if _sf_url_has_ctrl(vurl):continueresults.append({"source": "Castle","title": f"Castle [{lang_name}] - {quality}",381 unmodified linesif media_type == "tv" and not _sf_episode_matches(label, season or 1, episode or 1):continueif ".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}", 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