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 lines992993994995996997998999100010011002100310041005100610071008100910101011101210131014101535 unmodified lines10511052105310541055105610571058991 unmodified linesif 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:35 unmodified linesreturn 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)991 unmodified lines992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106935 unmodified lines11051106110711081109111011111112111311141115991 unmodified linesif not all_matches:return service_results, [f"{svc_name}: No match found"]# === Smart ranking: fetch metadata for top matches and score them ===# Uses TMDB year + media_type vs NetMirror year, type, IMDB ratingtmdb_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: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:continuescore = 0nm_type = post_data.get("type", "")nm_year = post_data.get("year", "")nm_rating = 0# Extract IMDB ratingfor 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 = 0break# 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 += 30elif year_diff == 1:score += 20elif year_diff <= 3:score += 10elif year_diff <= 5:score += 5except:pass# 3. IMDB rating as tiebreaker (higher = more popular)score += nm_ratingscored_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/episodefinal_id = Noneif media_type == "tv":s = season or 1e = episode or 1for scored in scored_matches:post_data = scored["post_data"]seasons = post_data.get("season", [])if not seasons:35 unmodified linesreturn service_results, [f"{svc_name}: No match with Season {s} Episode {e}"]else:# For movies, use the highest-scored matchif scored_matches:final_id = scored_matches[0]["match"].get("id")else:final_id = all_matches[0].get("id")# Get the actual streamplayer_resp = await client.get(f"{api_base}/player.php?id={final_id}", headers=headers)
main.py+72-15