Spaces:
Running
Running
Z User commited on
Commit ·
7e9b9b2
1
Parent(s): 0db2d27
v7: Smart match ranking for NetMirror - uses year, type, IMDB rating to pick best result
Browse files991 unmodified lines992993994995995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641001100210031004100510061007100810091010101110121065106610671068106935 unmodified lines1105110611071054105511081109111011111112111311141115991 unmodified lines if not all_matches: return service_results, [f"{svc_name}: No match found"]
# For TV shows, try each match until we find one with seasons # === Smart ranking: fetch metadata for top matches and score them === # Uses TMDB year + media_type vs NetMirror year, type, IMDB rating tmdb_year = info.get("year", "") expected_type = "t" if media_type == "tv" else "m"
# Fetch post.php for top matches to get metadata (limit to top 6) scored_matches = [] for match_item in all_matches[:6]: net_id = match_item.get("id") if not net_id: continue try: post_resp = await client.get(f"{api_base}/post.php?id={net_id}", headers=headers) if post_resp.status_code != 200: continue post_data = post_resp.json() except: continue score = 0 nm_type = post_data.get("type", "") nm_year = post_data.get("year", "") nm_rating = 0 # Extract IMDB rating for detail in post_data.get("moredetails", []): if detail.get("k") == "IMDB Rating": try: nm_rating = float(detail.get("v", "0").replace("/10", "")) except: nm_rating = 0 break # 1. Media type match (most important): TV→"t", movie→"m" if nm_type == expected_type: score += 50 # 2. Year proximity (very important for disambiguation) try: if tmdb_year and nm_year: year_diff = abs(int(tmdb_year) - int(nm_year)) if year_diff == 0: score += 30 elif year_diff == 1: score += 20 elif year_diff <= 3: score += 10 elif year_diff <= 5: score += 5 except: pass # 3. IMDB rating as tiebreaker (higher = more popular) score += nm_rating scored_matches.append({ "match": match_item, "post_data": post_data, "score": score, }) # Sort by score descending (best match first) scored_matches.sort(key=lambda x: x["score"], reverse=True)
# For TV shows, try each scored match until we find one with the right season/episode final_id = None if media_type == "tv": s = season or 1 e = episode or 1 for match_item in all_matches: net_id = match_item.get("id") if not net_id: continue try: post_resp = await client.get(f"{api_base}/post.php?id={net_id}", headers=headers) if post_resp.status_code != 200: continue post_data = post_resp.json() except: continue for scored in scored_matches: post_data = scored["post_data"] seasons = post_data.get("season", []) if not seasons:35 unmodified lines return service_results, [f"{svc_name}: No match with Season {s} Episode {e}"] else: # For movies, just use the best match final_id = all_matches[0].get("id") # For movies, use the highest-scored match if scored_matches: final_id = scored_matches[0]["match"].get("id") else: final_id = all_matches[0].get("id")
# Get the actual stream player_resp = await client.get(f"{api_base}/player.php?id={final_id}", headers=headers)main.py+72-15