weebzone commited on
Commit
11c12c6
·
1 Parent(s): 2928c2f

`V-1.4.2`

Browse files

• Added TMDB logo support in TMDB meta
• Added tmdb_id field in IMDb meta
• Improved metadata parser to handle empty/missing logos
• Fixed IMDb ↔ TMDB ID matching and normalization
• General metadata stability improvements

Backend/__init__.py CHANGED
@@ -11,4 +11,4 @@ StartTime = time()
11
  USE_DEFAULT_ID: str = None
12
  db = Database()
13
 
14
- __version__ = "1.4.1"
 
11
  USE_DEFAULT_ID: str = None
12
  db = Database()
13
 
14
+ __version__ = "1.4.2"
Backend/helper/metadata.py CHANGED
@@ -29,6 +29,17 @@ def format_tmdb_image(path: str, size="w500") -> str:
29
  return ""
30
  return f"https://image.tmdb.org/t/p/{size}{path}"
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  def format_imdb_images(imdb_id: str) -> dict:
33
  if not imdb_id:
34
  return {"poster": "", "backdrop": "", "logo": ""}
@@ -80,7 +91,7 @@ async def _tmdb_tv_details(tv_id):
80
  return TMDB_DETAILS_CACHE[tv_id]
81
  try:
82
  async with API_SEMAPHORE:
83
- details = await tmdb.tv(tv_id).details(append_to_response="external_ids,credits")
84
  TMDB_DETAILS_CACHE[tv_id] = details
85
  return details
86
  except Exception as e:
@@ -93,7 +104,7 @@ async def _tmdb_movie_details(movie_id):
93
  return TMDB_DETAILS_CACHE[movie_id]
94
  try:
95
  async with API_SEMAPHORE:
96
- details = await tmdb.movie(movie_id).details(append_to_response="external_ids,credits")
97
  TMDB_DETAILS_CACHE[movie_id] = details
98
  return details
99
  except Exception as e:
@@ -245,7 +256,7 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
245
  "description": tv_details.overview or "",
246
  "poster": format_tmdb_image(tv_details.poster_path),
247
  "backdrop": format_tmdb_image(tv_details.backdrop_path, "original"),
248
- "logo": "",
249
  "genres": [g.name for g in (tv_details.genres or [])],
250
  "media_type": "tv",
251
  "cast": cast_names,
@@ -267,7 +278,7 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
267
  images = format_imdb_images(imdb_id)
268
 
269
  return {
270
- "tmdb_id": imdb_id.replace("tt", "") if imdb_id else "",
271
  "imdb_id": imdb_id,
272
  "title": tv_details.get("title", title),
273
  "year": tv_details.get("releaseDetailed", {}).get("year", 0),
@@ -339,7 +350,7 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
339
  "description": movie_details.overview or "",
340
  "poster": format_tmdb_image(movie_details.poster_path),
341
  "backdrop": format_tmdb_image(movie_details.backdrop_path, "original"),
342
- "logo": "",
343
  "cast": cast_names,
344
  "media_type": "movie",
345
  "genres": [g.name for g in (movie_details.genres or [])],
@@ -352,7 +363,7 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
352
  images = format_imdb_images(imdb_id)
353
 
354
  return {
355
- "tmdb_id": imdb_id.replace("tt", "") if imdb_id else "",
356
  "imdb_id": imdb_id,
357
  "title": movie_details.get("title", title),
358
  "year": movie_details.get("releaseDetailed", {}).get("year", 0),
 
29
  return ""
30
  return f"https://image.tmdb.org/t/p/{size}{path}"
31
 
32
+ def get_tmdb_logo(images) -> str:
33
+ if not images or not getattr(images, "logos", None):
34
+ return ""
35
+
36
+ logos = images.logos
37
+
38
+ for logo in logos:
39
+ if getattr(logo, "iso_639_1", None) == "en":
40
+ return format_tmdb_image(logo.file_path, "original")
41
+ return format_tmdb_image(logos[0].file_path, "original") if logos else ""
42
+
43
  def format_imdb_images(imdb_id: str) -> dict:
44
  if not imdb_id:
45
  return {"poster": "", "backdrop": "", "logo": ""}
 
91
  return TMDB_DETAILS_CACHE[tv_id]
92
  try:
93
  async with API_SEMAPHORE:
94
+ details = await tmdb.tv(tv_id).details(append_to_response="external_ids,credits,images")
95
  TMDB_DETAILS_CACHE[tv_id] = details
96
  return details
97
  except Exception as e:
 
104
  return TMDB_DETAILS_CACHE[movie_id]
105
  try:
106
  async with API_SEMAPHORE:
107
+ details = await tmdb.movie(movie_id).details(append_to_response="external_ids,credits,images")
108
  TMDB_DETAILS_CACHE[movie_id] = details
109
  return details
110
  except Exception as e:
 
256
  "description": tv_details.overview or "",
257
  "poster": format_tmdb_image(tv_details.poster_path),
258
  "backdrop": format_tmdb_image(tv_details.backdrop_path, "original"),
259
+ "logo": get_tmdb_logo(getattr(tv_details, "images", None)),
260
  "genres": [g.name for g in (tv_details.genres or [])],
261
  "media_type": "tv",
262
  "cast": cast_names,
 
278
  images = format_imdb_images(imdb_id)
279
 
280
  return {
281
+ "tmdb_id": (tv_details.get("moviedb_id") or (imdb_id.replace("tt", "") if imdb_id else "")),
282
  "imdb_id": imdb_id,
283
  "title": tv_details.get("title", title),
284
  "year": tv_details.get("releaseDetailed", {}).get("year", 0),
 
350
  "description": movie_details.overview or "",
351
  "poster": format_tmdb_image(movie_details.poster_path),
352
  "backdrop": format_tmdb_image(movie_details.backdrop_path, "original"),
353
+ "logo": get_tmdb_logo(getattr(movie_details, "images", None)),
354
  "cast": cast_names,
355
  "media_type": "movie",
356
  "genres": [g.name for g in (movie_details.genres or [])],
 
363
  images = format_imdb_images(imdb_id)
364
 
365
  return {
366
+ "tmdb_id": (movie_details.get("moviedb_id") or (imdb_id.replace("tt", "") if imdb_id else "")),
367
  "imdb_id": imdb_id,
368
  "title": movie_details.get("title", title),
369
  "year": movie_details.get("releaseDetailed", {}).get("year", 0),
Backend/pyrofork/plugins/fix_metadata.py CHANGED
@@ -5,7 +5,7 @@ from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
5
 
6
  from Backend import db
7
  from Backend.helper.custom_filter import CustomFilters
8
- from Backend.helper.metadata import fetch_tv_metadata, fetch_movie_metadata, API_SEMAPHORE
9
  from Backend.logger import LOGGER
10
 
11
  CANCEL_REQUESTED = False
@@ -82,7 +82,7 @@ async def fix_metadata_handler(_, message):
82
 
83
  async with semaphore:
84
  try:
85
- if movie_doc.get("cast") and movie_doc.get("description") and movie_doc.get("genres"):
86
  DONE += 1
87
  return
88
 
@@ -102,6 +102,7 @@ async def fix_metadata_handler(_, message):
102
  await collection.update_one(
103
  {"tmdb_id": tmdb_id},
104
  {"$set": {
 
105
  "imdb_id": meta.get("imdb_id"),
106
  "cast": meta.get("cast"),
107
  "description": meta.get("description"),
@@ -134,7 +135,7 @@ async def fix_metadata_handler(_, message):
134
  year = tv_doc.get("release_year")
135
 
136
  # SHOW-LEVEL UPDATE
137
- has_meta = tv_doc.get("cast") and tv_doc.get("description") and tv_doc.get("genres")
138
  if not has_meta:
139
  meta = await fetch_tv_metadata(
140
  title=title,
@@ -150,6 +151,7 @@ async def fix_metadata_handler(_, message):
150
  await collection.update_one(
151
  {"tmdb_id": tmdb_id},
152
  {"$set": {
 
153
  "imdb_id": meta.get("imdb_id"),
154
  "cast": meta.get("cast"),
155
  "description": meta.get("description"),
 
5
 
6
  from Backend import db
7
  from Backend.helper.custom_filter import CustomFilters
8
+ from Backend.helper.metadata import fetch_tv_metadata, fetch_movie_metadata
9
  from Backend.logger import LOGGER
10
 
11
  CANCEL_REQUESTED = False
 
82
 
83
  async with semaphore:
84
  try:
85
+ if movie_doc.get("cast") and movie_doc.get("description") and movie_doc.get("genres") and movie_doc.get("logo") not in [None, ""]:
86
  DONE += 1
87
  return
88
 
 
102
  await collection.update_one(
103
  {"tmdb_id": tmdb_id},
104
  {"$set": {
105
+ "tmdb_id": meta.get("tmdb_id"),
106
  "imdb_id": meta.get("imdb_id"),
107
  "cast": meta.get("cast"),
108
  "description": meta.get("description"),
 
135
  year = tv_doc.get("release_year")
136
 
137
  # SHOW-LEVEL UPDATE
138
+ has_meta = tv_doc.get("cast") and tv_doc.get("description") and tv_doc.get("genres") and tv_doc.get("logo") not in [None, ""]
139
  if not has_meta:
140
  meta = await fetch_tv_metadata(
141
  title=title,
 
151
  await collection.update_one(
152
  {"tmdb_id": tmdb_id},
153
  {"$set": {
154
+ "tmdb_id": meta.get("tmdb_id"),
155
  "imdb_id": meta.get("imdb_id"),
156
  "cast": meta.get("cast"),
157
  "description": meta.get("description"),
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
  [project]
2
  name = "Telegram-Stremio"
3
- version = "1.4.1"
4
  description = "A powerful, self-hosted Telegram Stremio Media Server built with FastAPI, MongoDB, and PyroFork seamlessly integrated with Stremio for automated media streaming and discovery."
5
  readme = "README.md"
6
  requires-python = ">=3.11"
 
1
  [project]
2
  name = "Telegram-Stremio"
3
+ version = "1.4.2"
4
  description = "A powerful, self-hosted Telegram Stremio Media Server built with FastAPI, MongoDB, and PyroFork seamlessly integrated with Stremio for automated media streaming and discovery."
5
  readme = "README.md"
6
  requires-python = ">=3.11"
uv.lock CHANGED
@@ -901,7 +901,7 @@ wheels = [
901
 
902
  [[package]]
903
  name = "telegram-stremio"
904
- version = "1.4.0"
905
  source = { virtual = "." }
906
  dependencies = [
907
  { name = "aiofiles" },
 
901
 
902
  [[package]]
903
  name = "telegram-stremio"
904
+ version = "1.4.1"
905
  source = { virtual = "." }
906
  dependencies = [
907
  { name = "aiofiles" },