MyanmarSwe commited on
Commit
334e816
Β·
verified Β·
1 Parent(s): 550ffb6

Update sync.py

Browse files
Files changed (1) hide show
  1. sync.py +17 -44
sync.py CHANGED
@@ -9,10 +9,20 @@ metas_col, streams_col, users_col = db['metas'], db['streams'], db['users']
9
 
10
  def get_tmdb_meta(tmdb_id, m_type):
11
  tmdb_type = "movie" if m_type == "movie" else "tv"
12
- url = f"https://api.themoviedb.org/3/{tmdb_type}/{tmdb_id}?api_key={TMDB_KEY}&append_to_response=credits"
 
13
 
14
  try:
15
  res = requests.get(url).json()
 
 
 
 
 
 
 
 
 
16
  cast = [c["name"] for c in res.get("credits", {}).get("cast", [])[:15]]
17
 
18
  director = []
@@ -39,6 +49,7 @@ def get_tmdb_meta(tmdb_id, m_type):
39
  "name": res.get("title") or res.get("name"),
40
  "poster": f"https://image.tmdb.org/t/p/w500{res.get('poster_path')}",
41
  "background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}",
 
42
  "description": res.get("overview"),
43
  "cast": cast,
44
  "director": director,
@@ -62,10 +73,6 @@ def get_tmdb_meta(tmdb_id, m_type):
62
  except:
63
  episodes = []
64
 
65
- episode_count = s.get("episode_count", 0)
66
- if not episodes and episode_count > 0:
67
- episodes = [{"episode_number": i} for i in range(1, episode_count + 1)]
68
-
69
  for ep in episodes:
70
  e_num = ep.get("episode_number")
71
  still_path = ep.get("still_path")
@@ -80,32 +87,9 @@ def get_tmdb_meta(tmdb_id, m_type):
80
  })
81
  meta["videos"] = videos
82
 
83
- if res.get("belongs_to_collection"):
84
- col_id = res["belongs_to_collection"]["id"]
85
- col_res = requests.get(f"https://api.themoviedb.org/3/collection/{col_id}?api_key={TMDB_KEY}").json()
86
- sorted_parts = sorted(col_res.get("parts", []), key=lambda x: x.get("release_date", "9999"))
87
-
88
- col_videos = []
89
- for i, p in enumerate(sorted_parts):
90
- col_videos.append({
91
- "id": f"tmdb_col:{col_id}:1:{i+1}",
92
- "movie_id": str(p['id']),
93
- "title": f"{p.get('title')} ({p.get('release_date', '')[:4]})",
94
- "season": 1, "episode": i+1,
95
- "thumbnail": f"https://image.tmdb.org/t/p/w500{p.get('backdrop_path') or p.get('poster_path')}"
96
- })
97
-
98
- col_meta = {
99
- "id": f"tmdb_col:{col_id}", "type": "series", "name": col_res.get("name"),
100
- "poster": f"https://image.tmdb.org/t/p/w500{col_res.get('poster_path')}",
101
- "background": f"https://image.tmdb.org/t/p/original{col_res.get('backdrop_path')}",
102
- "description": col_res.get("overview"), "videos": col_videos, "updated_at": datetime.utcnow()
103
- }
104
- metas_col.update_one({"id": col_meta["id"]}, {"$set": col_meta}, upsert=True)
105
-
106
  return meta
107
  except Exception as e:
108
- print(f"Error fetching meta: {e}")
109
  return None
110
 
111
  def process_sync(data):
@@ -123,31 +107,20 @@ def process_sync(data):
123
  if meta_id not in processed_metas:
124
  new_meta = get_tmdb_meta(tmdb_id, m_type)
125
  if new_meta:
 
126
  existing_meta = metas_col.find_one({"id": meta_id})
127
  if existing_meta:
128
  if existing_meta.get('is_custom_overview'):
129
  new_meta['description'] = existing_meta['description']
130
  new_meta['is_custom_overview'] = True
131
-
132
- if m_type == 'series' and 'videos' in existing_meta:
133
- ep_overviews = {f"{v['season']}_{v['episode']}": v.get('overview') for v in existing_meta['videos'] if v.get('overview')}
134
- for v in new_meta.get('videos', []):
135
- key = f"{v['season']}_{v['episode']}"
136
- if key in ep_overviews:
137
- v['overview'] = ep_overviews[key]
138
  processed_metas[meta_id] = new_meta
139
 
140
  meta = processed_metas.get(meta_id)
141
  if meta:
142
  if item.get('custom_overview'):
143
- if m_type == 'series' and item.get('season') and item.get('episode'):
144
- for v in meta.get('videos', []):
145
- if v['season'] == item['season'] and v['episode'] == item['episode']:
146
- v['overview'] = item['custom_overview']
147
- break
148
- else:
149
- meta['description'] = item['custom_overview']
150
- meta['is_custom_overview'] = True
151
 
152
  s_query = {"tmdb_id": str(tmdb_id), "season": item.get('season'), "episode": item.get('episode')}
153
  streams_col.update_one(s_query, {"$set": {**s_query, "url": item['stream_url']}}, upsert=True)
 
9
 
10
  def get_tmdb_meta(tmdb_id, m_type):
11
  tmdb_type = "movie" if m_type == "movie" else "tv"
12
+ # append_to_response မှာ images α€•α€«α€‘α€Šα€·α€Ία€šα€°α€•α€«α€™α€šα€Ί (Logo ထတွက်)
13
+ url = f"https://api.themoviedb.org/3/{tmdb_type}/{tmdb_id}?api_key={TMDB_KEY}&append_to_response=credits,images"
14
 
15
  try:
16
  res = requests.get(url).json()
17
+
18
+ # Logo α€›α€šα€°α€α€Όα€„α€Ία€Έ (English Logo α€€α€­α€― α€¦α€Έα€…α€¬α€Έα€•α€±α€Έα€šα€°α€•α€«α€™α€Šα€Ί)
19
+ logo = None
20
+ logos = res.get("images", {}).get("logos", [])
21
+ if logos:
22
+ # Language 'en' α€›α€Ύα€­α€žα€±α€¬ logo α€€α€­α€―α€›α€Ύα€¬α€žα€Šα€ΊαŠ α€™α€›α€Ύα€­α€œα€»α€Ύα€„α€Ί α€•α€‘α€™α€†α€―α€Άα€Έα€α€…α€Ία€α€―α€šα€°α€žα€Šα€Ί
23
+ eng_logo = next((l for l in logos if l.get("iso_639_1") == "en"), logos[0])
24
+ logo = f"https://image.tmdb.org/t/p/w500{eng_logo['file_path']}"
25
+
26
  cast = [c["name"] for c in res.get("credits", {}).get("cast", [])[:15]]
27
 
28
  director = []
 
49
  "name": res.get("title") or res.get("name"),
50
  "poster": f"https://image.tmdb.org/t/p/w500{res.get('poster_path')}",
51
  "background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}",
52
+ "logo": logo, # Logo α€‘α€žα€…α€Ία€‘α€Šα€·α€Ία€žα€½α€„α€Ία€Έα€α€Όα€„α€Ία€Έ
53
  "description": res.get("overview"),
54
  "cast": cast,
55
  "director": director,
 
73
  except:
74
  episodes = []
75
 
 
 
 
 
76
  for ep in episodes:
77
  e_num = ep.get("episode_number")
78
  still_path = ep.get("still_path")
 
87
  })
88
  meta["videos"] = videos
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  return meta
91
  except Exception as e:
92
+ print(f"Sync Error: {e}")
93
  return None
94
 
95
  def process_sync(data):
 
107
  if meta_id not in processed_metas:
108
  new_meta = get_tmdb_meta(tmdb_id, m_type)
109
  if new_meta:
110
+ # Custom overview α€€α€­α€― overwrite မဖြစ်ထောင် α€‘α€­α€”α€Ία€Έα€žα€­α€™α€Ία€Έα€α€Όα€„α€Ία€Έ
111
  existing_meta = metas_col.find_one({"id": meta_id})
112
  if existing_meta:
113
  if existing_meta.get('is_custom_overview'):
114
  new_meta['description'] = existing_meta['description']
115
  new_meta['is_custom_overview'] = True
116
+
 
 
 
 
 
 
117
  processed_metas[meta_id] = new_meta
118
 
119
  meta = processed_metas.get(meta_id)
120
  if meta:
121
  if item.get('custom_overview'):
122
+ meta['description'] = item['custom_overview']
123
+ meta['is_custom_overview'] = True
 
 
 
 
 
 
124
 
125
  s_query = {"tmdb_id": str(tmdb_id), "season": item.get('season'), "episode": item.get('episode')}
126
  streams_col.update_one(s_query, {"$set": {**s_query, "url": item['stream_url']}}, upsert=True)