Spaces:
Running
Running
Z User commited on
Commit ·
0db2d27
1
Parent(s): d722b8e
v6.1: Fix NetMirror - multi-match for TV shows, remove freecdn2 CDN check, PrimeVideo/Hotstar now work
Browse filesFiles changed (2)
971 unmodified lines9729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810599 unmodified lines1069107010711072107310741075107610771078107910801081108210831084108510861087108810893 unmodified lines1093109410951096109710981099971 unmodified linesreturn service_results, [f"{svc_name}: Search returned non-JSON"]search_results = search_data.get("searchResult", [])# Fuzzy match: exact first, then starts-with, then containsmatch = Nonetitle_lower = title.lower()for item in search_results:item_title = item.get("t", "").strip().lower()if item_title == title_lower:match = itembreakif not match:for item in search_results:item_title = item.get("t", "").strip().lower()if item_title.startswith(title_lower) or title_lower.startswith(item_title):match = itembreakif not match:for item in search_results:item_title = item.get("t", "").strip().lower()if title_lower in item_title or item_title in title_lower:match = itembreakif not match or not match.get("id"):return service_results, [f"{svc_name}: No match found"]net_id = match["id"]final_id = net_id# For TV, drill down to season/episodeif media_type == "tv":s = season or 1e = episode or 1post_resp = await client.get(f"{api_base}/post.php?id={net_id}", headers=headers)if post_resp.status_code != 200:return service_results, [f"{svc_name}: Post HTTP {post_resp.status_code}"]try:post_data = post_resp.json()except:return service_results, [f"{svc_name}: Post returned non-JSON"]seasons = post_data.get("season", [])target_term = f"Season {s}"season_entry = Nonefor se in seasons:if se.get("s", "").__str__().find(target_term) >= 0:season_entry = sebreakif not season_entry or not season_entry.get("id"):return service_results, [f"{svc_name}: Season {s} not found"]season_id = season_entry["id"]episode_id = Nonepage = 1while not episode_id and page < 10:ep_resp = await client.get(f"{api_base}/episodes.php?id={season_id}&page={page}",headers=headers)if ep_resp.status_code != 200:breaktry:ep_data = ep_resp.json()except:breakepisodes_list = ep_data.get("episodes", [])for ep in episodes_list:if str(ep.get("ep", "")) == str(e):episode_id = ep.get("id")breakif ep_data.get("nextPageShow") != "1":breakpage += 1if not episode_id:return service_results, [f"{svc_name}: S{s}E{e} not found"]final_id = episode_id# Get the actual streamplayer_resp = await client.get(f"{api_base}/player.php?id={final_id}", headers=headers)9 unmodified linesif not video_link:return service_results, [f"{svc_name}: No video link"]# Verify the m3u8 stream is actually playable# PrimeVideo/Hotstar use freecdn2.top which returns 404 on segmentsif ".m3u8" in video_link:try:verify_resp = await client.get(video_link, headers=headers)verify_text = verify_resp.textif "#EXTM3U" not in verify_text:return service_results, [f"{svc_name}: Master playlist unreachable"]# Check for broken CDN - freecdn2.top segments always return 404if "freecdn2.top" in verify_text:seg_match = re.search(r'(https?://[^\s"]+\.m3u8[^\s"]*)', verify_text)if seg_match:seg_resp = await client.get(seg_match.group(1).split('"')[0].split()[0], headers=headers)if seg_resp.status_code == 404:return service_results, [f"{svc_name}: Stream unplayable (CDN segments 404)"]except:pass3 unmodified linesif q_match:quality = q_match.group(1) + "p"lang = "Hindi" if svc_code == "hs" else "English"service_results.append({"source": f"NetMirror/{svc_name}",971 unmodified lines972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710589 unmodified lines10681069107010711072107310741075107610771078107910803 unmodified lines1084108510861087108810891090971 unmodified linesreturn service_results, [f"{svc_name}: Search returned non-JSON"]search_results = search_data.get("searchResult", [])# Collect ALL matches ranked by relevancetitle_lower = title.lower().strip()exact_matches = []starts_matches = []contains_matches = []for item in search_results:item_title = item.get("t", "").strip().lower()if item_title == title_lower:exact_matches.append(item)elif item_title.startswith(title_lower) or title_lower.startswith(item_title):starts_matches.append(item)elif title_lower in item_title or item_title in title_lower:contains_matches.append(item)# Try matches in order of relevanceall_matches = exact_matches + starts_matches + contains_matchesif not all_matches:return service_results, [f"{svc_name}: No match found"]# For TV shows, try each match until we find one with seasonsfinal_id = Noneif media_type == "tv":s = season or 1e = episode or 1for match_item in all_matches:net_id = match_item.get("id")if not net_id:continuetry:post_resp = await client.get(f"{api_base}/post.php?id={net_id}", headers=headers)if post_resp.status_code != 200:continuepost_data = post_resp.json()except:continueseasons = post_data.get("season", [])if not seasons:continue # This match has no seasons, try nexttarget_term = f"Season {s}"season_entry = Nonefor se in seasons:if target_term in se.get("s", "").__str__():season_entry = sebreakif not season_entry or not season_entry.get("id"):continue # No matching season, try next matchseason_id = season_entry["id"]episode_id = Nonepage = 1while not episode_id and page < 10:ep_resp = await client.get(f"{api_base}/episodes.php?id={season_id}&page={page}", headers=headers)try:ep_data = ep_resp.json()except:breakepisodes = ep_data.get("episodes", [])for ep_item in episodes:if str(ep_item.get("ep", "")) == str(e):episode_id = ep_item.get("id")breakif int(ep_data.get("nextPageShow", 0)) != 1:breakpage += 1if episode_id:final_id = episode_idbreak # Found a working match!if not final_id:return service_results, [f"{svc_name}: No match with Season {s} Episode {e}"]else:# For movies, just use the best matchfinal_id = all_matches[0].get("id")# Get the actual streamplayer_resp = await client.get(f"{api_base}/player.php?id={final_id}", headers=headers)9 unmodified linesif not video_link:return service_results, [f"{svc_name}: No video link"]# Verify the m3u8 stream is playable# CDN has migrated to tv.imgcdn.kim which works for all servicesif ".m3u8" in video_link:try:verify_resp = await client.get(video_link, headers=headers)if "#EXTM3U" not in verify_resp.text:return service_results, [f"{svc_name}: Master playlist unreachable"]except:pass3 unmodified linesif q_match:quality = q_match.group(1) + "p"lang = detect_language(svc_name + " " + video_link)service_results.append({"source": f"NetMirror/{svc_name}",
__pycache__/main.cpython-312.pyc
main.py+74-83