weebzone commited on
Commit
36219c3
·
1 Parent(s): 522e2cd

Revert to TMDB Url format

Browse files
Backend/fastapi/routes/stremio_routes.py CHANGED
@@ -27,7 +27,7 @@ GENRES = [
27
  # --- Helper Functions ---
28
  def convert_to_stremio_meta(item: dict) -> dict:
29
  media_type = "series" if item.get("media_type") == "tv" else "movie"
30
- stremio_id = f"{item.get('imdb_id')}-{item.get('db_index')}"
31
 
32
  meta = {
33
  "id": stremio_id,
@@ -215,12 +215,12 @@ async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
215
  @router.get("/meta/{media_type}/{id}.json")
216
  async def get_meta(media_type: str, id: str):
217
  try:
218
- imdb_id_str, db_index_str = id.split("-")
219
- imdb_id, db_index = str(imdb_id_str), int(db_index_str)
220
  except (ValueError, IndexError):
221
  raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
222
 
223
- media = await db.get_media_details(imdb_id=imdb_id, db_index=db_index)
224
  if not media:
225
  return {"meta": {}}
226
 
@@ -277,14 +277,14 @@ async def get_streams(media_type: str, id: str):
277
  base_id = parts[0]
278
  season_num = int(parts[1]) if len(parts) > 1 else None
279
  episode_num = int(parts[2]) if len(parts) > 2 else None
280
- imdb_id_str, db_index_str = base_id.split("-")
281
- imdb_id, db_index = str(imdb_id_str), int(db_index_str)
282
 
283
  except (ValueError, IndexError):
284
  raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
285
 
286
  media_details = await db.get_media_details(
287
- imdb_id=imdb_id,
288
  db_index=db_index,
289
  season_number=season_num,
290
  episode_number=episode_num
 
27
  # --- Helper Functions ---
28
  def convert_to_stremio_meta(item: dict) -> dict:
29
  media_type = "series" if item.get("media_type") == "tv" else "movie"
30
+ stremio_id = f"{item.get('tmdb_id')}-{item.get('db_index')}"
31
 
32
  meta = {
33
  "id": stremio_id,
 
215
  @router.get("/meta/{media_type}/{id}.json")
216
  async def get_meta(media_type: str, id: str):
217
  try:
218
+ tmdb_id_str, db_index_str = id.split("-")
219
+ tmdb_id, db_index = int(tmdb_id_str), int(db_index_str)
220
  except (ValueError, IndexError):
221
  raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
222
 
223
+ media = await db.get_media_details(tmdb_id=tmdb_id, db_index=db_index)
224
  if not media:
225
  return {"meta": {}}
226
 
 
277
  base_id = parts[0]
278
  season_num = int(parts[1]) if len(parts) > 1 else None
279
  episode_num = int(parts[2]) if len(parts) > 2 else None
280
+ tmdb_id_str, db_index_str = base_id.split("-")
281
+ tmdb_id, db_index = int(tmdb_id_str), int(db_index_str)
282
 
283
  except (ValueError, IndexError):
284
  raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
285
 
286
  media_details = await db.get_media_details(
287
+ tmdb_id=tmdb_id,
288
  db_index=db_index,
289
  season_number=season_num,
290
  episode_number=episode_num
Backend/helper/database.py CHANGED
@@ -541,12 +541,12 @@ class Database:
541
 
542
 
543
  async def get_media_details(
544
- self, imdb_id: str, db_index: int,
545
  season_number: Optional[int] = None, episode_number: Optional[int] = None
546
  ) -> Optional[dict]:
547
  db_key = f"storage_{db_index}"
548
  if episode_number is not None and season_number is not None:
549
- tv_show = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
550
  if not tv_show:
551
  return None
552
  for season in tv_show.get("seasons", []):
@@ -555,7 +555,7 @@ class Database:
555
  if episode.get("episode_number") == episode_number:
556
  details = convert_objectid_to_str(episode)
557
  details.update({
558
- "imdb_id": imdb_id,
559
  "type": "tv",
560
  "season_number": season_number,
561
  "episode_number": episode_number,
@@ -565,14 +565,14 @@ class Database:
565
  return None
566
 
567
  elif season_number is not None:
568
- tv_show = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
569
  if not tv_show:
570
  return None
571
  for season in tv_show.get("seasons", []):
572
  if season.get("season_number") == season_number:
573
  details = convert_objectid_to_str(season)
574
  details.update({
575
- "imdb_id": imdb_id,
576
  "type": "tv",
577
  "season_number": season_number
578
  })
@@ -580,12 +580,12 @@ class Database:
580
  return None
581
 
582
  else:
583
- tv_doc = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
584
  if tv_doc:
585
  tv_doc = convert_objectid_to_str(tv_doc)
586
  tv_doc["type"] = "tv"
587
  return tv_doc
588
- movie_doc = await self.dbs[db_key]["movie"].find_one({"imdb_id": imdb_id})
589
  if movie_doc:
590
  movie_doc = convert_objectid_to_str(movie_doc)
591
  movie_doc["type"] = "movie"
 
541
 
542
 
543
  async def get_media_details(
544
+ self, tmdb_id: int, db_index: int,
545
  season_number: Optional[int] = None, episode_number: Optional[int] = None
546
  ) -> Optional[dict]:
547
  db_key = f"storage_{db_index}"
548
  if episode_number is not None and season_number is not None:
549
+ tv_show = await self.dbs[db_key]["tv"].find_one({"tmdb_id": tmdb_id})
550
  if not tv_show:
551
  return None
552
  for season in tv_show.get("seasons", []):
 
555
  if episode.get("episode_number") == episode_number:
556
  details = convert_objectid_to_str(episode)
557
  details.update({
558
+ "tmdb_id": tmdb_id,
559
  "type": "tv",
560
  "season_number": season_number,
561
  "episode_number": episode_number,
 
565
  return None
566
 
567
  elif season_number is not None:
568
+ tv_show = await self.dbs[db_key]["tv"].find_one({"tmdb_id": tmdb_id})
569
  if not tv_show:
570
  return None
571
  for season in tv_show.get("seasons", []):
572
  if season.get("season_number") == season_number:
573
  details = convert_objectid_to_str(season)
574
  details.update({
575
+ "tmdb_id": tmdb_id,
576
  "type": "tv",
577
  "season_number": season_number
578
  })
 
580
  return None
581
 
582
  else:
583
+ tv_doc = await self.dbs[db_key]["tv"].find_one({"tmdb_id": tmdb_id})
584
  if tv_doc:
585
  tv_doc = convert_objectid_to_str(tv_doc)
586
  tv_doc["type"] = "tv"
587
  return tv_doc
588
+ movie_doc = await self.dbs[db_key]["movie"].find_one({"tmdb_id": tmdb_id})
589
  if movie_doc:
590
  movie_doc = convert_objectid_to_str(movie_doc)
591
  movie_doc["type"] = "movie"