Spaces:
Runtime error
Runtime error
Update sync.py
Browse files
sync.py
CHANGED
|
@@ -26,23 +26,31 @@ def get_tmdb_data(tmdb_id, m_type):
|
|
| 26 |
logo_path = en_logos[0]["file_path"] if en_logos else logos[0]["file_path"]
|
| 27 |
logo_url = f"https://image.tmdb.org/t/p/w500{logo_path}"
|
| 28 |
|
| 29 |
-
# --- Cast & Crew ---
|
| 30 |
credits = res.get("credits", {})
|
| 31 |
cast = [c["name"] for c in credits.get("cast", [])[:15]]
|
| 32 |
directors = [c["name"] for c in credits.get("crew", []) if c["job"] == "Director"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
meta = {
|
| 35 |
"_id": f"tmdb:{tmdb_id}",
|
| 36 |
"id": f"tmdb:{tmdb_id}",
|
| 37 |
"type": m_type,
|
| 38 |
"name": res.get("title") or res.get("name"),
|
| 39 |
-
"poster": f"https://image.tmdb.org/t/p/w500{res.get('poster_path')}",
|
| 40 |
-
"background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}",
|
| 41 |
"logo": logo_url,
|
| 42 |
-
"description": res.get("overview"),
|
| 43 |
"releaseInfo": (res.get("release_date") or res.get("first_air_date", "0000"))[:4],
|
| 44 |
"imdbRating": "{:.1f}".format(res.get("vote_average", 0)) if res.get("vote_average") else "N/A",
|
| 45 |
-
"runtime":
|
| 46 |
"cast": cast,
|
| 47 |
"director": directors,
|
| 48 |
"genres": [g["name"] for g in res.get("genres", [])],
|
|
@@ -55,6 +63,9 @@ def get_tmdb_data(tmdb_id, m_type):
|
|
| 55 |
# --- TV Show Episodes Fix ---
|
| 56 |
if m_type == "series":
|
| 57 |
videos = []
|
|
|
|
|
|
|
|
|
|
| 58 |
for s in res.get("seasons", []):
|
| 59 |
s_num = s.get("season_number")
|
| 60 |
if s_num == 0: continue
|
|
@@ -63,7 +74,7 @@ def get_tmdb_data(tmdb_id, m_type):
|
|
| 63 |
"id": f"tmdb:{tmdb_id}:{s_num}:{e_num}",
|
| 64 |
"title": f"S{s_num} E{e_num}",
|
| 65 |
"season": s_num, "episode": e_num,
|
| 66 |
-
"released":
|
| 67 |
})
|
| 68 |
meta["videos"] = videos
|
| 69 |
|
|
@@ -73,21 +84,38 @@ def get_tmdb_data(tmdb_id, m_type):
|
|
| 73 |
col_url = f"https://api.themoviedb.org/3/collection/{col_id}?api_key={TMDB_KEY}"
|
| 74 |
col_res = requests.get(col_url).json()
|
| 75 |
if "id" in col_res:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
col_meta = {
|
| 77 |
"_id": f"tmdb_col:{col_id}",
|
| 78 |
"id": f"tmdb_col:{col_id}",
|
| 79 |
"type": "series", # UI ααΎα¬ α‘ααα―ααΊαΈααα―ααΊααΌαααΊ series ααα―α· αααΊααΎααΊ
|
| 80 |
"name": col_res.get("name"),
|
| 81 |
-
"poster": f"https://image.tmdb.org/t/p/w500{col_res.get('poster_path')}",
|
| 82 |
-
"background": f"https://image.tmdb.org/t/p/original{col_res.get('backdrop_path')}",
|
| 83 |
-
"description": col_res.get("overview"),
|
| 84 |
-
"
|
|
|
|
|
|
|
|
|
|
| 85 |
"updated_at": datetime.utcnow()
|
| 86 |
}
|
| 87 |
metas_col.update_one({"id": col_meta["id"]}, {"$set": col_meta}, upsert=True)
|
| 88 |
|
| 89 |
return meta
|
| 90 |
-
except
|
|
|
|
|
|
|
| 91 |
|
| 92 |
def process_sync(data):
|
| 93 |
if data.get("users"):
|
|
|
|
| 26 |
logo_path = en_logos[0]["file_path"] if en_logos else logos[0]["file_path"]
|
| 27 |
logo_url = f"https://image.tmdb.org/t/p/w500{logo_path}"
|
| 28 |
|
| 29 |
+
# --- Cast & Crew Fix ---
|
| 30 |
credits = res.get("credits", {})
|
| 31 |
cast = [c["name"] for c in credits.get("cast", [])[:15]]
|
| 32 |
directors = [c["name"] for c in credits.get("crew", []) if c["job"] == "Director"]
|
| 33 |
+
|
| 34 |
+
# TV Show αα½α±α‘αα½ααΊ Director ααα«αα²α·αα»αΎααΊ Creator ααα― αα―αΆαΈαα±αΈααΌααΊαΈ
|
| 35 |
+
if m_type == "series" and not directors:
|
| 36 |
+
directors = [c["name"] for c in res.get("created_by", [])]
|
| 37 |
+
|
| 38 |
+
# Runtime Fix
|
| 39 |
+
run_t = res.get("runtime") if m_type == "movie" else (res.get("episode_run_time", [None])[0] if res.get("episode_run_time") else None)
|
| 40 |
+
runtime_str = f"{run_t} min" if run_t else "N/A"
|
| 41 |
|
| 42 |
meta = {
|
| 43 |
"_id": f"tmdb:{tmdb_id}",
|
| 44 |
"id": f"tmdb:{tmdb_id}",
|
| 45 |
"type": m_type,
|
| 46 |
"name": res.get("title") or res.get("name"),
|
| 47 |
+
"poster": f"https://image.tmdb.org/t/p/w500{res.get('poster_path')}" if res.get('poster_path') else None,
|
| 48 |
+
"background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}" if res.get('backdrop_path') else None,
|
| 49 |
"logo": logo_url,
|
| 50 |
+
"description": res.get("overview", ""),
|
| 51 |
"releaseInfo": (res.get("release_date") or res.get("first_air_date", "0000"))[:4],
|
| 52 |
"imdbRating": "{:.1f}".format(res.get("vote_average", 0)) if res.get("vote_average") else "N/A",
|
| 53 |
+
"runtime": runtime_str,
|
| 54 |
"cast": cast,
|
| 55 |
"director": directors,
|
| 56 |
"genres": [g["name"] for g in res.get("genres", [])],
|
|
|
|
| 63 |
# --- TV Show Episodes Fix ---
|
| 64 |
if m_type == "series":
|
| 65 |
videos = []
|
| 66 |
+
first_air = res.get("first_air_date")
|
| 67 |
+
rel_date = f"{first_air}T00:00:00.000Z" if first_air else "2000-01-01T00:00:00.000Z" # Stremio ISO format Fix
|
| 68 |
+
|
| 69 |
for s in res.get("seasons", []):
|
| 70 |
s_num = s.get("season_number")
|
| 71 |
if s_num == 0: continue
|
|
|
|
| 74 |
"id": f"tmdb:{tmdb_id}:{s_num}:{e_num}",
|
| 75 |
"title": f"S{s_num} E{e_num}",
|
| 76 |
"season": s_num, "episode": e_num,
|
| 77 |
+
"released": rel_date
|
| 78 |
})
|
| 79 |
meta["videos"] = videos
|
| 80 |
|
|
|
|
| 84 |
col_url = f"https://api.themoviedb.org/3/collection/{col_id}?api_key={TMDB_KEY}"
|
| 85 |
col_res = requests.get(col_url).json()
|
| 86 |
if "id" in col_res:
|
| 87 |
+
col_videos = []
|
| 88 |
+
for i, p in enumerate(col_res.get("parts", [])):
|
| 89 |
+
p_date = p.get("release_date")
|
| 90 |
+
c_rel_date = f"{p_date}T00:00:00.000Z" if p_date else "2000-01-01T00:00:00.000Z"
|
| 91 |
+
col_videos.append({
|
| 92 |
+
"id": f"tmdb:{p['id']}",
|
| 93 |
+
"title": f"π₯ {p.get('title')}",
|
| 94 |
+
"season": 1,
|
| 95 |
+
"episode": i+1,
|
| 96 |
+
"released": c_rel_date # Collection videos αα½α±α‘αα½ααΊ Date αα±α¬αΊααΌαα»ααΊααΌααΊαααΊααΌααΊαΈ
|
| 97 |
+
})
|
| 98 |
+
|
| 99 |
col_meta = {
|
| 100 |
"_id": f"tmdb_col:{col_id}",
|
| 101 |
"id": f"tmdb_col:{col_id}",
|
| 102 |
"type": "series", # UI ααΎα¬ α‘ααα―ααΊαΈααα―ααΊααΌαααΊ series ααα―α· αααΊααΎααΊ
|
| 103 |
"name": col_res.get("name"),
|
| 104 |
+
"poster": f"https://image.tmdb.org/t/p/w500{col_res.get('poster_path')}" if col_res.get('poster_path') else None,
|
| 105 |
+
"background": f"https://image.tmdb.org/t/p/original{col_res.get('backdrop_path')}" if col_res.get('backdrop_path') else None,
|
| 106 |
+
"description": col_res.get("overview", ""),
|
| 107 |
+
"cast": [], # Missing meta fields αα»α¬αΈααΌαα·αΊαα±αΈααΌααΊαΈ
|
| 108 |
+
"director": [],
|
| 109 |
+
"genres": ["Collection"],
|
| 110 |
+
"videos": col_videos,
|
| 111 |
"updated_at": datetime.utcnow()
|
| 112 |
}
|
| 113 |
metas_col.update_one({"id": col_meta["id"]}, {"$set": col_meta}, upsert=True)
|
| 114 |
|
| 115 |
return meta
|
| 116 |
+
except Exception as e:
|
| 117 |
+
print(f"Error fetching TMDB: {e}")
|
| 118 |
+
return None
|
| 119 |
|
| 120 |
def process_sync(data):
|
| 121 |
if data.get("users"):
|