Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files54 unmodified lines5556575859606116 unmodified lines78798081828384858687888990919293949596979899100101102103104105418 unmodified lines52452552652752852954 unmodified lines# βββ AllMovieLand βββββββββββββββββββββββββββββββββββββββββββββββββββasync def _discover_player_domain(client: httpx.AsyncClient) -> str:"""Discover the current AllMovieLand player domain from a film page."""try:r = await client.get(f"{MOVIELAND_BASE}/films/", headers={"User-Agent": UA}, timeout=8.0)if r.status_code == 200:16 unmodified linesreturn ""async def _ml_single_attempt(client: httpx.AsyncClient, player_domain: str, imdb_id: str,media_type: str, season: Optional[str], episode: Optional[str],phpsessid: str):"""Single attempt at scraping AllMovieLand. Returns (result_dict, error_str)."""cookies = {"PHPSESSID": phpsessid} if phpsessid else {}# Step 1: Load embed pageembed_url = f"{player_domain}/play/{imdb_id}"r1 = await client.get(embed_url, headers={"User-Agent": UA, "Referer": f"{MOVIELAND_BASE}/"}, cookies=cookies)if r1.status_code == 404:player_domain = await _discover_player_domain(client)if not player_domain:return None, f"embed 404, no player domain found"embed_url = f"{player_domain}/play/{imdb_id}"r1 = await client.get(embed_url, headers={"User-Agent": UA, "Referer": f"{MOVIELAND_BASE}/"}, cookies=cookies)if r1.status_code != 200:return None, f"embed status {r1.status_code}"# Step 2: Parse config from last <script> tag (phisher's approach: first { to last })scripts = re.findall(r'<script[^>]*>(.*?)</script>', r1.text, re.DOTALL)if not scripts:return None, "no script tags found"418 unmodified linesresults["embed_test"] = {"status": r.status_code, "len": len(r.text), "has_p3": "let p3" in r.text}except Exception as e:results["embed_test"] = {"error": str(e)[:80]}else:# Try hardcoded fallbacktry:54 unmodified lines555657585960616216 unmodified lines798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133418 unmodified lines55255355455555655755855956056156254 unmodified lines# βββ AllMovieLand βββββββββββββββββββββββββββββββββββββββββββββββββββasync def _discover_player_domain(client: httpx.AsyncClient) -> str:"""Discover the current AllMovieLand player domain from a film page.Also discovers the href (CDN) domain which is used for playlist/m3u8 URLs."""try:r = await client.get(f"{MOVIELAND_BASE}/films/", headers={"User-Agent": UA}, timeout=8.0)if r.status_code == 200:16 unmodified linesreturn ""async def _get_embed_via_allorigins(client: httpx.AsyncClient, embed_url: str) -> tuple:"""Try loading the embed page through allorigins proxy when direct access is blocked (e.g. on cloud hosts)."""from urllib.parse import quoteproxy_url = f"https://api.allorigins.win/raw?url={quote(embed_url, safe='')}"try:r = await client.get(proxy_url, headers={"User-Agent": UA}, timeout=15.0)if r.status_code == 200 and "let p3" in r.text:return r.text, Nonereturn None, f"proxy status {r.status_code}"except Exception as e:return None, f"proxy error: {str(e)[:50]}"async def _ml_single_attempt(client: httpx.AsyncClient, player_domain: str, imdb_id: str,media_type: str, season: Optional[str], episode: Optional[str],phpsessid: str):"""Single attempt at scraping AllMovieLand. Returns (result_dict, error_str)."""cookies = {"PHPSESSID": phpsessid} if phpsessid else {}# Step 1: Load embed page (try direct, then proxy fallback)embed_url = f"{player_domain}/play/{imdb_id}"r1 = await client.get(embed_url, headers={"User-Agent": UA, "Referer": f"{MOVIELAND_BASE}/"}, cookies=cookies)embed_html = r1.textif r1.status_code == 404 or r1.status_code == 403:# Player domain blocked (common on cloud hosts) β try allorigins proxyproxy_html, proxy_err = await _get_embed_via_allorigins(client, embed_url)if proxy_html:embed_html = proxy_htmlelse:# Last resort: try the movie page on allmovieland directly# to find an alternative player domainnew_domain = await _discover_player_domain(client)if new_domain and new_domain != player_domain:embed_url = f"{new_domain}/play/{imdb_id}"r1b = await client.get(embed_url, headers={"User-Agent": UA, "Referer": f"{MOVIELAND_BASE}/"}, cookies=cookies)if r1b.status_code == 200 and "let p3" in r1b.text:embed_html = r1b.textplayer_domain = new_domainelse:return None, f"embed blocked (direct {r1.status_code}, proxy {proxy_err})"else:return None, f"embed blocked (status {r1.status_code}, proxy {proxy_err})"if r1.status_code != 200 and "let p3" not in embed_html:return None, f"embed status {r1.status_code}"# Step 2: Parse config from last <script> tag (phisher's approach: first { to last })scripts = re.findall(r'<script[^>]*>(.*?)</script>', embed_html, re.DOTALL)if not scripts:return None, "no script tags found"418 unmodified linesresults["embed_test"] = {"status": r.status_code, "len": len(r.text), "has_p3": "let p3" in r.text}except Exception as e:results["embed_test"] = {"error": str(e)[:80]}# Test allorigins proxy for the embedif r.status_code != 200 or "let p3" not in r.text:proxy_html, proxy_err = await _get_embed_via_allorigins(client, f"{player_domain}/play/tt16366836")results["allorigins_proxy"] = {"success": proxy_html is not None, "error": proxy_err, "has_p3": proxy_html and "let p3" in proxy_html if proxy_html else False}else:# Try hardcoded fallbacktry:
app.py+44-11