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 lines1322132313241325132513261327132813291330133213311332133313341335133613371338133913401341134213431344134513461347134813491340135013511342135213441353135413551356134913501351135213531357135813591360136113561357136213631364136513661 unmodified line1368136913701365137113721373136813741375137613771372137313781379138013811382137513761383138413851386137913871388138913821390139113921393139413951387139613971398139914001401140213891403140414051406140714081409141014111392141214131414141513971416141714181400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014191420142114221423142414251426142714281472147314741429143014311478143214331480148114341435143614371438143914861487148814891490149114401441144214431493149414951496149714981499150015011502150315041505144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509150715081510151115121513151415151516151715181519152015211321 unmodified lines try: 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 TMDB 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
# Step 1: Search on allmovieland.one # 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: Search search_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, errors
search_html = search_resp.text articles = re.findall(r'<article[^>]*>(.*?)</article>', search_html, re.DOTALL) if not articles: errors.append("AllMovieLand: No search results") return results, errors
# Parse search results # Find best match movie_url = None articles = 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 contains if item_title.lower() == title_lower or title_lower in item_title.lower(): movie_url = item_url 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) break # Fuzzy: pick first result if no exact match if not movie_url and articles: if not movie_url: # Fallback: first result for article in articles: link_m = re.search(r'href="([^"]+)"', article) if link_m:1 unmodified line break
if not movie_url: errors.append("AllMovieLand: No search results") errors.append("AllMovieLand: Could not find movie URL") return results, errors
# Step 2: Get movie page - extract player domain and ID # Step 2: Movie page movie_resp = await client.get(movie_url, headers={"Referer": "https://allmovieland.one/"}) movie_html = movie_resp.text
domain_m = re.search(r"AwsIndStreamDomain\s*=\s*'([^']+)'", movie_html) player_domain = domain_m.group(1).rstrip("/") if domain_m else None # Extract player domain and media ID from script section # The variables are inside <script> tags in tabs__content domain_match = re.search(r"AwsIndStreamDomain\s*=\s*['\"]([^'\"]+)['\"]", movie_html) player_domain = domain_match.group(1).rstrip("/") if domain_match else None id_m = re.search(r"src:\s*'([^']+)'", movie_html) media_id = id_m.group(1) if id_m else None id_match = re.search(r"src:\s*['\"]([^'\"]+)['\"]", movie_html) media_id = id_match.group(1) if id_match else None
if not player_domain or not media_id: errors.append("AllMovieLand: Could not extract player info") errors.append(f"AllMovieLand: No player info (domain={player_domain}, id={media_id})") return results, errors
# Step 3: Get embed page - extract p3 JSON (file URL + CSRF key) # Step 3: Embed page - get p3 data embed_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 patterns p3_m = re.search(r'let\s+p3\s*=\s*(\{.*?\});', embed_html) p3_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") errors.append("AllMovieLand: Could not find player data in embed") return results, errors
try: p3 = json.loads(p3_m.group(1)) except json.JSONDecodeError: errors.append(f"AllMovieLand: Invalid p3 JSON: {p3_m.group(1)[:80]}") return results, errors
p3 = 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") errors.append("AllMovieLand: Missing file URL or CSRF key in p3") return results, errors
# Step 4: POST to get file list - use fresh client per attempt (burst) file_list = None post_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(",]", "]")) break except: pass
if 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/episode target_files = [] if media_type == "movie": target_files = [f for f in file_list if f.get("file")] else: s = season or 1 e = episode or 1 # Find season season_data = None for 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 = item break # Also try by id if str(item.get("id")) == str(s): season_data = item break if season_data and season_data.get("folder"): # Find episode ep_data = None for 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_item break if str(ep_item.get("episode")) == str(e): ep_data = ep_item break if 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: continue # Step 4: POST to get file list - burst with fresh clients file_list = None post_headers = { "X-CSRF-TOKEN": csrf_key, "Referer": embed_url, "Origin": player_domain, "Accept": "application/json, text/plain, */*", "User-Agent": UA, }
playlist_url = f"{player_domain}/playlist/{file_path}.txt" m3u8_url = None 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(playlist_url, headers=post_headers) resp = await fresh_client.post(file_url, headers=post_headers) text = resp.text.strip() if text != "7" and text and text.startswith("http"): m3u8_url = text if text != "7" and text.startswith("["): file_list = json.loads(text.replace(",]", "]")) break except: pass
if 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" if not file_list: errors.append("AllMovieLand: Could not get file list (7 attempts)") return results, errors
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, }, }) # Filter files based on media type target_files = [] if media_type == "movie": target_files = [f for f in file_list if f.get("file")] else: s = season or 1 e = episode or 1 for 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")] break break
if not target_files: target_files = [f for f in file_list if f.get("file")][:3]
# Step 5: Get m3u8 URL for each file - burst for file_obj in target_files: file_path = file_obj.get("file", "").lstrip("~") stream_title = file_obj.get("title", "Stream") if not file_path: continue
playlist_url = f"{player_domain}/playlist/{file_path}.txt" m3u8_url = None 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(playlist_url, headers=post_headers) text = resp.text.strip() if text != "7" and text.startswith("http"): m3u8_url = text break except: pass
if 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") 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