Spaces:
Sleeping
Sleeping
Update sync.py
Browse files
sync.py
CHANGED
|
@@ -9,26 +9,29 @@ 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 |
-
#
|
| 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
|
| 19 |
logo = None
|
| 20 |
logos = res.get("images", {}).get("logos", [])
|
| 21 |
if logos:
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
|
|
|
| 26 |
cast = [c["name"] for c in res.get("credits", {}).get("cast", [])[:15]]
|
| 27 |
|
| 28 |
director = []
|
| 29 |
if m_type == "movie":
|
| 30 |
director = [c["name"] for c in res.get("credits", {}).get("crew", []) if c.get("job") == "Director"]
|
| 31 |
else:
|
|
|
|
| 32 |
director = [c["name"] for c in res.get("created_by", [])]
|
| 33 |
|
| 34 |
genres = [g["name"] for g in res.get("genres", [])]
|
|
@@ -49,7 +52,7 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 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,
|
| 53 |
"description": res.get("overview"),
|
| 54 |
"cast": cast,
|
| 55 |
"director": director,
|
|
@@ -66,18 +69,12 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 66 |
s_num = s.get("season_number")
|
| 67 |
if s_num == 0: continue
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
except:
|
| 74 |
-
episodes = []
|
| 75 |
-
|
| 76 |
-
for ep in episodes:
|
| 77 |
e_num = ep.get("episode_number")
|
| 78 |
-
|
| 79 |
-
thumbnail = f"https://image.tmdb.org/t/p/w500{still_path}" if still_path else f"https://image.tmdb.org/t/p/w500{s.get('poster_path') or res.get('poster_path')}"
|
| 80 |
-
|
| 81 |
videos.append({
|
| 82 |
"id": f"tmdb:{tmdb_id}:{s_num}:{e_num}",
|
| 83 |
"title": ep.get("name") or f"S{s_num} E{e_num}",
|
|
@@ -89,7 +86,7 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 89 |
|
| 90 |
return meta
|
| 91 |
except Exception as e:
|
| 92 |
-
print(f"Sync Error: {e}")
|
| 93 |
return None
|
| 94 |
|
| 95 |
def process_sync(data):
|
|
@@ -100,20 +97,18 @@ def process_sync(data):
|
|
| 100 |
processed_metas = {}
|
| 101 |
|
| 102 |
for item in data.get("movies_series", []):
|
| 103 |
-
tmdb_id = item['tmdb_id']
|
| 104 |
m_type = item['type']
|
| 105 |
meta_id = f"tmdb:{tmdb_id}"
|
| 106 |
|
| 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 ααα―
|
| 111 |
-
|
| 112 |
-
if
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
new_meta['is_custom_overview'] = True
|
| 116 |
-
|
| 117 |
processed_metas[meta_id] = new_meta
|
| 118 |
|
| 119 |
meta = processed_metas.get(meta_id)
|
|
@@ -122,7 +117,7 @@ def process_sync(data):
|
|
| 122 |
meta['description'] = item['custom_overview']
|
| 123 |
meta['is_custom_overview'] = True
|
| 124 |
|
| 125 |
-
s_query = {"tmdb_id":
|
| 126 |
streams_col.update_one(s_query, {"$set": {**s_query, "url": item['stream_url']}}, upsert=True)
|
| 127 |
|
| 128 |
for meta_id, meta in processed_metas.items():
|
|
|
|
| 9 |
|
| 10 |
def get_tmdb_meta(tmdb_id, m_type):
|
| 11 |
tmdb_type = "movie" if m_type == "movie" else "tv"
|
| 12 |
+
# Cast, Director ααΎααΊα· Logo α‘αα½ααΊ images,credits ααα―αα« αα±α«αΊαα°αααΊ
|
| 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 Logic
|
| 19 |
logo = None
|
| 20 |
logos = res.get("images", {}).get("logos", [])
|
| 21 |
if logos:
|
| 22 |
+
# English logo ααα― α‘αααΊααΎα¬αααΊ
|
| 23 |
+
en_logos = [l for l in logos if l.get("iso_639_1") == "en"]
|
| 24 |
+
target_logo = en_logos[0] if en_logos else logos[0]
|
| 25 |
+
logo = f"https://image.tmdb.org/t/p/w500{target_logo['file_path']}"
|
| 26 |
|
| 27 |
+
# Cast & Director Logic
|
| 28 |
cast = [c["name"] for c in res.get("credits", {}).get("cast", [])[:15]]
|
| 29 |
|
| 30 |
director = []
|
| 31 |
if m_type == "movie":
|
| 32 |
director = [c["name"] for c in res.get("credits", {}).get("crew", []) if c.get("job") == "Director"]
|
| 33 |
else:
|
| 34 |
+
# TV Show αα»α¬αΈα‘αα½ααΊ Creator ααα― Director α‘ααΌα
αΊααΌααααΊ
|
| 35 |
director = [c["name"] for c in res.get("created_by", [])]
|
| 36 |
|
| 37 |
genres = [g["name"] for g in res.get("genres", [])]
|
|
|
|
| 52 |
"name": res.get("title") or res.get("name"),
|
| 53 |
"poster": f"https://image.tmdb.org/t/p/w500{res.get('poster_path')}",
|
| 54 |
"background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}",
|
| 55 |
+
"logo": logo,
|
| 56 |
"description": res.get("overview"),
|
| 57 |
"cast": cast,
|
| 58 |
"director": director,
|
|
|
|
| 69 |
s_num = s.get("season_number")
|
| 70 |
if s_num == 0: continue
|
| 71 |
|
| 72 |
+
s_url = f"https://api.themoviedb.org/3/tv/{tmdb_id}/season/{s_num}?api_key={TMDB_KEY}"
|
| 73 |
+
s_res = requests.get(s_url).json()
|
| 74 |
+
|
| 75 |
+
for ep in s_res.get("episodes", []):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
e_num = ep.get("episode_number")
|
| 77 |
+
thumbnail = f"https://image.tmdb.org/t/p/w500{ep.get('still_path')}" if ep.get('still_path') else meta["poster"]
|
|
|
|
|
|
|
| 78 |
videos.append({
|
| 79 |
"id": f"tmdb:{tmdb_id}:{s_num}:{e_num}",
|
| 80 |
"title": ep.get("name") or f"S{s_num} E{e_num}",
|
|
|
|
| 86 |
|
| 87 |
return meta
|
| 88 |
except Exception as e:
|
| 89 |
+
print(f"TMDB Sync Error: {e}")
|
| 90 |
return None
|
| 91 |
|
| 92 |
def process_sync(data):
|
|
|
|
| 97 |
processed_metas = {}
|
| 98 |
|
| 99 |
for item in data.get("movies_series", []):
|
| 100 |
+
tmdb_id = str(item['tmdb_id'])
|
| 101 |
m_type = item['type']
|
| 102 |
meta_id = f"tmdb:{tmdb_id}"
|
| 103 |
|
| 104 |
if meta_id not in processed_metas:
|
| 105 |
new_meta = get_tmdb_meta(tmdb_id, m_type)
|
| 106 |
if new_meta:
|
| 107 |
+
# Custom overview ααα― ααααΊαΈααααΊαΈααΌααΊαΈ
|
| 108 |
+
existing = metas_col.find_one({"id": meta_id})
|
| 109 |
+
if existing and existing.get('is_custom_overview'):
|
| 110 |
+
new_meta['description'] = existing['description']
|
| 111 |
+
new_meta['is_custom_overview'] = True
|
|
|
|
|
|
|
| 112 |
processed_metas[meta_id] = new_meta
|
| 113 |
|
| 114 |
meta = processed_metas.get(meta_id)
|
|
|
|
| 117 |
meta['description'] = item['custom_overview']
|
| 118 |
meta['is_custom_overview'] = True
|
| 119 |
|
| 120 |
+
s_query = {"tmdb_id": tmdb_id, "season": item.get('season'), "episode": item.get('episode')}
|
| 121 |
streams_col.update_one(s_query, {"$set": {**s_query, "url": item['stream_url']}}, upsert=True)
|
| 122 |
|
| 123 |
for meta_id, meta in processed_metas.items():
|