Spaces:
Running
Running
Z User commited on
Commit ·
2c8dab3
1
Parent(s): 86ad7da
AllMovieLand: Improved error handling, multiple p3 regex patterns, better debug
Browse files1321 unmodified lines1322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601 unmodified line1362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171321 unmodified linestry:UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"# Get title from TMDBinfo = await get_tmdb_info(tmdb_id, media_type)title = info.get("title", "")if not title:errors.append("AllMovieLand: Could not get title from TMDB")return results, errors# Step 1: Search on allmovieland.oneasync with httpx.AsyncClient(timeout=15, follow_redirects=True, headers={"User-Agent": UA}, http2=False) as client:search_resp = await client.get("https://allmovieland.one/index.php",params={"story": title, "do": "search", "subaction": "search"})search_html = search_resp.text# Parse search resultsmovie_url = Nonearticles = re.findall(r'<article[^>]*>(.*?)</article>', search_html, re.DOTALL)title_lower = title.lower()for article in articles:link_m = re.search(r'href="([^"]+)"', article)h3_m = re.search(r'<h3[^>]*>(.*?)</h3>', article)if link_m and h3_m:item_title = h3_m.group(1).strip()item_url = link_m.group(1)# Simple match: exact or containsif item_title.lower() == title_lower or title_lower in item_title.lower():movie_url = item_urlbreak# Fuzzy: pick first result if no exact matchif not movie_url and articles:for article in articles:link_m = re.search(r'href="([^"]+)"', article)if link_m:1 unmodified linebreakif not movie_url:errors.append("AllMovieLand: No search results")return results, errors# Step 2: Get movie page - extract player domain and IDmovie_resp = await client.get(movie_url, headers={"Referer": "https://allmovieland.one/"})movie_html = movie_resp.textdomain_m = re.search(r"AwsIndStreamDomain\s*=\s*'([^']+)'", movie_html)player_domain = domain_m.group(1).rstrip("/") if domain_m else Noneid_m = re.search(r"src:\s*'([^']+)'", movie_html)media_id = id_m.group(1) if id_m else Noneif not player_domain or not media_id:errors.append("AllMovieLand: Could not extract player info")return results, errors# Step 3: Get embed page - extract p3 JSON (file URL + CSRF key)embed_url = f"{player_domain}/play/{media_id}"embed_resp = await client.get(embed_url, headers={"Referer": movie_url})embed_html = embed_resp.textp3_m = re.search(r'let\s+p3\s*=\s*(\{.*?\});', embed_html)if not p3_m:errors.append("AllMovieLand: Could not find player data")return results, errorsp3 = json.loads(p3_m.group(1))file_url = p3.get("file", "").replace("\\/", "/")csrf_key = p3.get("key", "")if not file_url or not csrf_key:errors.append("AllMovieLand: Missing file URL or CSRF key")return results, errors# Step 4: POST to get file list - use fresh client per attempt (burst)file_list = Nonepost_headers = {"X-CSRF-TOKEN": csrf_key,"Referer": embed_url,"Origin": player_domain,"Accept": "application/json, text/plain, */*","User-Agent": UA,}for attempt in range(7):try:async with httpx.AsyncClient(timeout=10, follow_redirects=True, http2=False) as fresh_client:resp = await fresh_client.post(file_url, headers=post_headers)text = resp.text.strip()if text != "7" and text and text.startswith("["):file_list = json.loads(text.replace(",]", "]"))breakexcept:passif not file_list:errors.append("AllMovieLand: Could not get file list after 7 attempts")return results, errors# For movies: use all files. For TV: find matching season/episodetarget_files = []if media_type == "movie":target_files = [f for f in file_list if f.get("file")]else:s = season or 1e = episode or 1# Find seasonseason_data = Nonefor item in file_list:item_title = item.get("title", "")s_m = re.search(r'Season\s*(\d+)', item_title, re.I)if s_m and int(s_m.group(1)) == s:season_data = itembreak# Also try by idif str(item.get("id")) == str(s):season_data = itembreakif season_data and season_data.get("folder"):# Find episodeep_data = Nonefor ep_item in season_data["folder"]:ep_title = ep_item.get("title", "")e_m = re.search(r'Episode\s*(\d+)', ep_title, re.I)if e_m and int(e_m.group(1)) == e:ep_data = ep_itembreakif str(ep_item.get("episode")) == str(e):ep_data = ep_itembreakif ep_data and ep_data.get("folder"):target_files = [f for f in ep_data["folder"] if f.get("file")]if not target_files:errors.append("AllMovieLand: No matching streams found")return results, errors# Step 5: For each file, POST to get m3u8 URL (burst per file)for file_obj in target_files:file_path = file_obj.get("file", "").replace("~", "")stream_title = file_obj.get("title", "Stream")if not file_path:continueplaylist_url = f"{player_domain}/playlist/{file_path}.txt"m3u8_url = Nonefor attempt in range(7):try:async with httpx.AsyncClient(timeout=10, follow_redirects=True, http2=False) as fresh_client:resp = await fresh_client.post(playlist_url, headers=post_headers)text = resp.text.strip()if text != "7" and text and text.startswith("http"):m3u8_url = textbreakexcept:passif m3u8_url:lang = detect_language(stream_title)quality = "Auto"q_m = re.search(r'(\d{3,4})p', stream_title)if q_m:quality = q_m.group(1) + "p"results.append({"source": f"AllMovieLand","title": f"AllMovieLand - {stream_title}","quality": quality,"language": lang,"url": m3u8_url,"type": "m3u8","headers": {"Referer": f"{player_domain}/","Origin": player_domain,"User-Agent": UA,},})if not results:errors.append("AllMovieLand: Could not resolve any m3u8 URLs")except Exception as e:errors.append(f"AllMovieLand: {str(e)}")return results, errors# ===== Source Map =====SOURCE_MAP = {1321 unmodified lines1322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661 unmodified line13681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211321 unmodified linestry:UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"info = await get_tmdb_info(tmdb_id, media_type)title = info.get("title", "")if not title:errors.append("AllMovieLand: Could not get title from TMDB")return results, errors# Use single client session throughout (important for cookies/session)async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers={"User-Agent": UA}, http2=False) as client:# Step 1: Searchsearch_resp = await client.get("https://allmovieland.one/index.php",params={"story": title, "do": "search", "subaction": "search"})if search_resp.status_code != 200:errors.append(f"AllMovieLand: Search HTTP {search_resp.status_code}")return results, errorssearch_html = search_resp.textarticles = re.findall(r'<article[^>]*>(.*?)</article>', search_html, re.DOTALL)if not articles:errors.append("AllMovieLand: No search results")return results, errors# Find best matchmovie_url = Nonetitle_lower = title.lower()for article in articles:link_m = re.search(r'href="([^"]+)"', article)h3_m = re.search(r'<h3[^>]*>(.*?)</h3>', article)if link_m and h3_m:item_title = h3_m.group(1).strip().lower()if item_title == title_lower or title_lower in item_title:movie_url = link_m.group(1)breakif not movie_url:# Fallback: first resultfor article in articles:link_m = re.search(r'href="([^"]+)"', article)if link_m:1 unmodified linebreakif not movie_url:errors.append("AllMovieLand: Could not find movie URL")return results, errors# Step 2: Movie pagemovie_resp = await client.get(movie_url, headers={"Referer": "https://allmovieland.one/"})movie_html = movie_resp.text# Extract player domain and media ID from script section# The variables are inside <script> tags in tabs__contentdomain_match = re.search(r"AwsIndStreamDomain\s*=\s*['\"]([^'\"]+)['\"]", movie_html)player_domain = domain_match.group(1).rstrip("/") if domain_match else Noneid_match = re.search(r"src:\s*['\"]([^'\"]+)['\"]", movie_html)media_id = id_match.group(1) if id_match else Noneif not player_domain or not media_id:errors.append(f"AllMovieLand: No player info (domain={player_domain}, id={media_id})")return results, errors# Step 3: Embed page - get p3 dataembed_url = f"{player_domain}/play/{media_id}"embed_resp = await client.get(embed_url, headers={"Referer": movie_url})embed_html = embed_resp.text# Find p3 - try multiple patternsp3_m = re.search(r'let\s+p3\s*=\s*(\{.*?\})\s*;', embed_html)if not p3_m:p3_m = re.search(r'p3\s*=\s*(\{[^;]+\})\s*;', embed_html)if not p3_m:p3_m = re.search(r'(\{"file".*?"key".*?\})', embed_html)if not p3_m:errors.append("AllMovieLand: Could not find player data in embed")return results, errorstry:p3 = json.loads(p3_m.group(1))except json.JSONDecodeError:errors.append(f"AllMovieLand: Invalid p3 JSON: {p3_m.group(1)[:80]}")return results, errorsfile_url = p3.get("file", "").replace("\\/", "/")csrf_key = p3.get("key", "")if not file_url or not csrf_key:errors.append("AllMovieLand: Missing file URL or CSRF key in p3")return results, errors# Step 4: POST to get file list - burst with fresh clientsfile_list = Nonepost_headers = {"X-CSRF-TOKEN": csrf_key,"Referer": embed_url,"Origin": player_domain,"Accept": "application/json, text/plain, */*","User-Agent": UA,}for attempt in range(7):try:async with httpx.AsyncClient(timeout=10, follow_redirects=True, http2=False) as fresh_client:resp = await fresh_client.post(file_url, headers=post_headers)text = resp.text.strip()if text != "7" and text.startswith("["):file_list = json.loads(text.replace(",]", "]"))breakexcept:passif not file_list:errors.append("AllMovieLand: Could not get file list (7 attempts)")return results, errors# Filter files based on media typetarget_files = []if media_type == "movie":target_files = [f for f in file_list if f.get("file")]else:s = season or 1e = episode or 1for item in file_list:item_title = item.get("title", "")s_m = re.search(r'Season\s*(\d+)', item_title, re.I)if s_m and int(s_m.group(1)) == s:if item.get("folder"):for ep_item in item["folder"]:ep_title = ep_item.get("title", "")e_m = re.search(r'Episode\s*(\d+)', ep_title, re.I)if e_m and int(e_m.group(1)) == e:if ep_item.get("folder"):target_files = [f for f in ep_item["folder"] if f.get("file")]breakbreakif not target_files:target_files = [f for f in file_list if f.get("file")][:3]# Step 5: Get m3u8 URL for each file - burstfor file_obj in target_files:file_path = file_obj.get("file", "").lstrip("~")stream_title = file_obj.get("title", "Stream")if not file_path:continueplaylist_url = f"{player_domain}/playlist/{file_path}.txt"m3u8_url = Nonefor attempt in range(7):try:async with httpx.AsyncClient(timeout=10, follow_redirects=True, http2=False) as fresh_client:resp = await fresh_client.post(playlist_url, headers=post_headers)text = resp.text.strip()if text != "7" and text.startswith("http"):m3u8_url = textbreakexcept:passif m3u8_url:lang = detect_language(stream_title)quality = "Auto"q_m = re.search(r'(\d{3,4})p', stream_title)if q_m:quality = q_m.group(1) + "p"results.append({"source": "AllMovieLand","title": f"AllMovieLand - {stream_title}","quality": quality,"language": lang,"url": m3u8_url,"type": "m3u8","headers": {"Referer": f"{player_domain}/","Origin": player_domain,"User-Agent": UA,},})if not results:errors.append("AllMovieLand: Could not resolve any m3u8 URLs")except Exception as e:errors.append(f"AllMovieLand: {str(e)}")return results, errors# ===== Source Map =====SOURCE_MAP = {
main.py+126-122