MyanmarSwe commited on
Commit
7bdeeeb
Β·
verified Β·
1 Parent(s): 7faef68

Update sync.py

Browse files
Files changed (1) hide show
  1. sync.py +39 -11
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": f"{res.get('runtime')} min" if m_type == "movie" else "Various",
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": res.get("first_air_date")
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
- "videos": [{"id": f"tmdb:{p['id']}", "title": f"πŸŽ₯ {p.get('title')}", "season": 1, "episode": i+1} for i, p in enumerate(col_res.get("parts", []))],
 
 
 
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: return None
 
 
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"):