Karan Adhikari commited on
Add default field for missing
Browse files
Backend/fastapi/routes/stremio_routes.py
CHANGED
|
@@ -4,6 +4,8 @@ from urllib.parse import unquote
|
|
| 4 |
from Backend.config import Telegram
|
| 5 |
from Backend import db, __version__
|
| 6 |
import PTN
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# --- Configuration ---
|
| 9 |
BASE_URL = Telegram.BASE_URL
|
|
@@ -21,6 +23,7 @@ GENRES = [
|
|
| 21 |
"Sci-Fi", "Sport", "Thriller", "War", "Western"
|
| 22 |
]
|
| 23 |
|
|
|
|
| 24 |
# --- Helper Functions ---
|
| 25 |
def convert_to_stremio_meta(item: dict) -> dict:
|
| 26 |
media_type = "series" if item.get("media_type") == "tv" else "movie"
|
|
@@ -233,24 +236,32 @@ async def get_meta(media_type: str, id: str):
|
|
| 233 |
"imdb_id": media.get("imdb_id", "")
|
| 234 |
}
|
| 235 |
|
|
|
|
| 236 |
if media_type == "series" and "seasons" in media:
|
| 237 |
-
|
|
|
|
| 238 |
videos = []
|
|
|
|
| 239 |
for season in sorted(media.get("seasons", []), key=lambda s: s.get("season_number")):
|
| 240 |
for episode in sorted(season.get("episodes", []), key=lambda e: e.get("episode_number")):
|
| 241 |
-
|
|
|
|
|
|
|
| 242 |
videos.append({
|
| 243 |
"id": episode_id,
|
| 244 |
"title": episode.get("title", f"Episode {episode['episode_number']}"),
|
| 245 |
"season": season.get("season_number"),
|
| 246 |
"episode": episode.get("episode_number"),
|
| 247 |
-
"overview": episode.get("overview"
|
| 248 |
-
"released": episode.get("released"
|
| 249 |
-
"thumbnail": episode.get("episode_backdrop") or
|
|
|
|
| 250 |
"imdb_id": episode.get("imdb_id") or media.get("imdb_id"),
|
| 251 |
})
|
|
|
|
| 252 |
meta_obj["videos"] = videos
|
| 253 |
|
|
|
|
| 254 |
cast_list = media.get("cast") or []
|
| 255 |
if cast_list:
|
| 256 |
meta_obj["cast"] = cast_list[:10]
|
|
|
|
| 4 |
from Backend.config import Telegram
|
| 5 |
from Backend import db, __version__
|
| 6 |
import PTN
|
| 7 |
+
from datetime import datetime, timezone
|
| 8 |
+
|
| 9 |
|
| 10 |
# --- Configuration ---
|
| 11 |
BASE_URL = Telegram.BASE_URL
|
|
|
|
| 23 |
"Sci-Fi", "Sport", "Thriller", "War", "Western"
|
| 24 |
]
|
| 25 |
|
| 26 |
+
|
| 27 |
# --- Helper Functions ---
|
| 28 |
def convert_to_stremio_meta(item: dict) -> dict:
|
| 29 |
media_type = "series" if item.get("media_type") == "tv" else "movie"
|
|
|
|
| 236 |
"imdb_id": media.get("imdb_id", "")
|
| 237 |
}
|
| 238 |
|
| 239 |
+
# --- Add Episodes ---
|
| 240 |
if media_type == "series" and "seasons" in media:
|
| 241 |
+
|
| 242 |
+
current_release = datetime.now(timezone.utc).isoformat()
|
| 243 |
videos = []
|
| 244 |
+
|
| 245 |
for season in sorted(media.get("seasons", []), key=lambda s: s.get("season_number")):
|
| 246 |
for episode in sorted(season.get("episodes", []), key=lambda e: e.get("episode_number")):
|
| 247 |
+
|
| 248 |
+
episode_id = f"{id}:{season['season_number']}:{episode['episode_number']}"
|
| 249 |
+
|
| 250 |
videos.append({
|
| 251 |
"id": episode_id,
|
| 252 |
"title": episode.get("title", f"Episode {episode['episode_number']}"),
|
| 253 |
"season": season.get("season_number"),
|
| 254 |
"episode": episode.get("episode_number"),
|
| 255 |
+
"overview": episode.get("overview") or "No description available for this episode yet.",
|
| 256 |
+
"released": episode.get("released") or current_release,
|
| 257 |
+
"thumbnail": episode.get("episode_backdrop") or
|
| 258 |
+
"https://via.placeholder.com/1280x720/1a1a2e/eaeaea?text=No+Image",
|
| 259 |
"imdb_id": episode.get("imdb_id") or media.get("imdb_id"),
|
| 260 |
})
|
| 261 |
+
|
| 262 |
meta_obj["videos"] = videos
|
| 263 |
|
| 264 |
+
# --- Add cast ---
|
| 265 |
cast_list = media.get("cast") or []
|
| 266 |
if cast_list:
|
| 267 |
meta_obj["cast"] = cast_list[:10]
|