Spaces:
Sleeping
Sleeping
Update sync.py
Browse files
sync.py
CHANGED
|
@@ -9,6 +9,7 @@ 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,images"
|
| 13 |
|
| 14 |
try:
|
|
@@ -22,7 +23,7 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 22 |
target_logo = en_logos[0] if en_logos else logos[0]
|
| 23 |
logo = f"https://image.tmdb.org/t/p/w500{target_logo['file_path']}"
|
| 24 |
|
| 25 |
-
# Cast ααΎαα·αΊ Director ααα°ααΌααΊαΈ
|
| 26 |
credits = res.get("credits", {})
|
| 27 |
cast = [c["name"] for c in credits.get("cast", [])[:15]]
|
| 28 |
|
|
@@ -31,14 +32,8 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 31 |
director = [c["name"] for c in credits.get("crew", []) if c.get("job") == "Director"]
|
| 32 |
else:
|
| 33 |
director = [c["name"] for c in res.get("created_by", [])]
|
| 34 |
-
if not director:
|
| 35 |
director = [c["name"] for c in credits.get("crew", []) if c.get("job") == "Executive Producer"][:2]
|
| 36 |
-
|
| 37 |
-
# Cast/Director αααΎααααΊ α‘αααΊαΈαα―αΆαΈ α‘αα»ααΊα‘αααΊαα
αΊαα―αα―ααα·αΊαα±αΈααΌααΊαΈ
|
| 38 |
-
if not cast:
|
| 39 |
-
cast = ["Information not available"]
|
| 40 |
-
if not director:
|
| 41 |
-
director = ["Information not available"]
|
| 42 |
|
| 43 |
genres = [g["name"] for g in res.get("genres", [])]
|
| 44 |
vote_avg = res.get("vote_average")
|
|
@@ -51,8 +46,8 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 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,
|
| 56 |
"genres": genres,
|
| 57 |
"releaseInfo": str(res.get("release_date") or res.get("first_air_date") or "0000")[:4],
|
| 58 |
"imdbRating": str(round(vote_avg, 1)) if vote_avg else None,
|
|
@@ -60,7 +55,6 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 60 |
"updated_at": datetime.utcnow()
|
| 61 |
}
|
| 62 |
|
| 63 |
-
# TV Series α‘ααα―ααΊαΈαα»α¬αΈ
|
| 64 |
if m_type == "series":
|
| 65 |
videos = []
|
| 66 |
for s in res.get("seasons", []):
|
|
@@ -83,7 +77,7 @@ def get_tmdb_meta(tmdb_id, m_type):
|
|
| 83 |
|
| 84 |
return meta
|
| 85 |
except Exception as e:
|
| 86 |
-
print(f"TMDB Fetch Error
|
| 87 |
return None
|
| 88 |
|
| 89 |
def process_sync(data):
|
|
@@ -98,47 +92,35 @@ def process_sync(data):
|
|
| 98 |
m_type = item['type']
|
| 99 |
meta_id = f"tmdb:{t_id}"
|
| 100 |
|
| 101 |
-
#
|
| 102 |
-
existing_meta = metas_col.find_one({"id": meta_id})
|
| 103 |
-
has_custom_overview = False
|
| 104 |
-
custom_desc = None
|
| 105 |
-
|
| 106 |
-
if existing_meta:
|
| 107 |
-
# Check if existing meta has custom overview flag
|
| 108 |
-
if existing_meta.get('is_custom_overview') == True:
|
| 109 |
-
has_custom_overview = True
|
| 110 |
-
custom_desc = existing_meta.get('description')
|
| 111 |
-
|
| 112 |
if meta_id not in processed_metas:
|
| 113 |
new_meta = get_tmdb_meta(t_id, m_type)
|
| 114 |
if new_meta:
|
| 115 |
-
#
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
# New custom overview from current sync
|
| 121 |
-
new_meta['description'] = item['custom_overview']
|
| 122 |
new_meta['is_custom_overview'] = True
|
| 123 |
else:
|
| 124 |
new_meta['is_custom_overview'] = False
|
| 125 |
-
|
| 126 |
processed_metas[meta_id] = new_meta
|
| 127 |
|
| 128 |
-
# Stream link
|
| 129 |
s_query = {"tmdb_id": t_id}
|
| 130 |
-
if
|
| 131 |
-
s_query["season"] = item
|
| 132 |
-
s_query["episode"] = item
|
| 133 |
-
|
| 134 |
streams_col.update_one(
|
| 135 |
s_query,
|
| 136 |
-
{"$set": {**s_query, "url": item['stream_url']}},
|
| 137 |
upsert=True
|
| 138 |
)
|
| 139 |
|
| 140 |
-
# Meta data α‘α¬αΈαα―αΆαΈααα―
|
| 141 |
for m_id, m_data in processed_metas.items():
|
| 142 |
metas_col.update_one({"id": m_id}, {"$set": m_data}, upsert=True)
|
| 143 |
|
| 144 |
-
return {"status": "success"
|
|
|
|
| 9 |
|
| 10 |
def get_tmdb_meta(tmdb_id, m_type):
|
| 11 |
tmdb_type = "movie" if m_type == "movie" else "tv"
|
| 12 |
+
# credits ααΎαα·αΊ images ααα― append_to_response ααΌαα·αΊ αα
αΊαα«αααΊαΈ αα°αααΊ
|
| 13 |
url = f"https://api.themoviedb.org/3/{tmdb_type}/{tmdb_id}?api_key={TMDB_KEY}&append_to_response=credits,images"
|
| 14 |
|
| 15 |
try:
|
|
|
|
| 23 |
target_logo = en_logos[0] if en_logos else logos[0]
|
| 24 |
logo = f"https://image.tmdb.org/t/p/w500{target_logo['file_path']}"
|
| 25 |
|
| 26 |
+
# Cast ααΎαα·αΊ Director ααα°ααΌααΊαΈ
|
| 27 |
credits = res.get("credits", {})
|
| 28 |
cast = [c["name"] for c in credits.get("cast", [])[:15]]
|
| 29 |
|
|
|
|
| 32 |
director = [c["name"] for c in credits.get("crew", []) if c.get("job") == "Director"]
|
| 33 |
else:
|
| 34 |
director = [c["name"] for c in res.get("created_by", [])]
|
| 35 |
+
if not director:
|
| 36 |
director = [c["name"] for c in credits.get("crew", []) if c.get("job") == "Executive Producer"][:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
genres = [g["name"] for g in res.get("genres", [])]
|
| 39 |
vote_avg = res.get("vote_average")
|
|
|
|
| 46 |
"background": f"https://image.tmdb.org/t/p/original{res.get('backdrop_path')}",
|
| 47 |
"logo": logo,
|
| 48 |
"description": res.get("overview"),
|
| 49 |
+
"cast": cast,
|
| 50 |
+
"director": director,
|
| 51 |
"genres": genres,
|
| 52 |
"releaseInfo": str(res.get("release_date") or res.get("first_air_date") or "0000")[:4],
|
| 53 |
"imdbRating": str(round(vote_avg, 1)) if vote_avg else None,
|
|
|
|
| 55 |
"updated_at": datetime.utcnow()
|
| 56 |
}
|
| 57 |
|
|
|
|
| 58 |
if m_type == "series":
|
| 59 |
videos = []
|
| 60 |
for s in res.get("seasons", []):
|
|
|
|
| 77 |
|
| 78 |
return meta
|
| 79 |
except Exception as e:
|
| 80 |
+
print(f"TMDB Fetch Error: {e}")
|
| 81 |
return None
|
| 82 |
|
| 83 |
def process_sync(data):
|
|
|
|
| 92 |
m_type = item['type']
|
| 93 |
meta_id = f"tmdb:{t_id}"
|
| 94 |
|
| 95 |
+
# Meta α‘αα»ααΊα‘αααΊααα― TMDB ααΎ αα½α²αα°αααΊ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if meta_id not in processed_metas:
|
| 97 |
new_meta = get_tmdb_meta(t_id, m_type)
|
| 98 |
if new_meta:
|
| 99 |
+
# Custom Overview α
α
αΊαα±αΈααΌααΊαΈ
|
| 100 |
+
# Spreadsheet ααΎ custom_overview αα«αα¬αα»αΎααΊ TMDB description α‘α
α¬αΈ αααΊαΈααα― αα―αΆαΈαααΊ
|
| 101 |
+
custom_ov = item.get('custom_overview')
|
| 102 |
+
if custom_ov and str(custom_ov).strip():
|
| 103 |
+
new_meta['description'] = str(custom_ov).strip()
|
|
|
|
|
|
|
| 104 |
new_meta['is_custom_overview'] = True
|
| 105 |
else:
|
| 106 |
new_meta['is_custom_overview'] = False
|
| 107 |
+
|
| 108 |
processed_metas[meta_id] = new_meta
|
| 109 |
|
| 110 |
+
# Stream link ααα― α‘ααΌα² update αα―ααΊαααΊ
|
| 111 |
s_query = {"tmdb_id": t_id}
|
| 112 |
+
if m_type == "series":
|
| 113 |
+
s_query["season"] = int(item.get('season', 1))
|
| 114 |
+
s_query["episode"] = int(item.get('episode', 1))
|
| 115 |
+
|
| 116 |
streams_col.update_one(
|
| 117 |
s_query,
|
| 118 |
+
{"$set": {**s_query, "url": item['stream_url'], "updated_at": datetime.utcnow()}},
|
| 119 |
upsert=True
|
| 120 |
)
|
| 121 |
|
| 122 |
+
# Meta data α‘α¬αΈαα―αΆαΈααα― MongoDB αα½ααΊ ααααΊαΈαααΊαΈαααΊ
|
| 123 |
for m_id, m_data in processed_metas.items():
|
| 124 |
metas_col.update_one({"id": m_id}, {"$set": m_data}, upsert=True)
|
| 125 |
|
| 126 |
+
return {"status": "success"}
|