weebzone commited on
Commit ·
fcc3ca3
1
Parent(s): 56a4829
`**v1.4.0 Release**`
Browse files* Added missing metadata: **cast**, **episode overview**, **episode release date**
* Improved Stremio stream filenames with detailed info
* Added `/fixmetadata` command to auto-repair empty metadata fields
* Minor bug fixes
- Backend/__init__.py +1 -1
- Backend/fastapi/routes/stremio_routes.py +103 -57
- Backend/helper/database.py +4 -0
- Backend/helper/metadata.py +27 -2
- Backend/helper/modal.py +4 -0
- Backend/helper/pyro.py +1 -0
- Backend/pyrofork/plugins/fix_metadata.py +243 -0
- pyproject.toml +1 -1
- uv.lock +1 -1
Backend/__init__.py
CHANGED
|
@@ -11,4 +11,4 @@ StartTime = time()
|
|
| 11 |
USE_DEFAULT_ID: str = None
|
| 12 |
db = Database()
|
| 13 |
|
| 14 |
-
__version__ = "1.
|
|
|
|
| 11 |
USE_DEFAULT_ID: str = None
|
| 12 |
db = Database()
|
| 13 |
|
| 14 |
+
__version__ = "1.4.0"
|
Backend/fastapi/routes/stremio_routes.py
CHANGED
|
@@ -3,6 +3,7 @@ from typing import Optional
|
|
| 3 |
from urllib.parse import unquote
|
| 4 |
from Backend.config import Telegram
|
| 5 |
from Backend import db, __version__
|
|
|
|
| 6 |
|
| 7 |
# --- Configuration ---
|
| 8 |
BASE_URL = Telegram.BASE_URL
|
|
@@ -14,9 +15,9 @@ router = APIRouter(prefix="/stremio", tags=["Stremio Addon"])
|
|
| 14 |
|
| 15 |
# Define available genres
|
| 16 |
GENRES = [
|
| 17 |
-
"Action", "Adventure", "Animation", "Biography", "Comedy",
|
| 18 |
-
"Crime", "Documentary", "Drama", "Family", "Fantasy",
|
| 19 |
-
"History", "Horror", "Music", "Mystery", "Romance",
|
| 20 |
"Sci-Fi", "Sport", "Thriller", "War", "Western"
|
| 21 |
]
|
| 22 |
|
|
@@ -25,7 +26,7 @@ def convert_to_stremio_meta(item: dict) -> dict:
|
|
| 25 |
media_type = "series" if item.get("media_type") == "tv" else "movie"
|
| 26 |
stremio_id = f"{item.get('tmdb_id')}-{item.get('db_index')}"
|
| 27 |
|
| 28 |
-
|
| 29 |
"id": stremio_id,
|
| 30 |
"type": media_type,
|
| 31 |
"name": item.get("title"),
|
|
@@ -38,7 +39,60 @@ def convert_to_stremio_meta(item: dict) -> dict:
|
|
| 38 |
"description": item.get("description") or "",
|
| 39 |
}
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
@router.get("/manifest.json")
|
| 43 |
async def get_manifest():
|
| 44 |
return {
|
|
@@ -50,17 +104,12 @@ async def get_manifest():
|
|
| 50 |
"types": ["movie", "series"],
|
| 51 |
"resources": ["catalog", "meta", "stream"],
|
| 52 |
"catalogs": [
|
| 53 |
-
# Movie Catalogs
|
| 54 |
{
|
| 55 |
"type": "movie",
|
| 56 |
"id": "latest_movies",
|
| 57 |
"name": "Latest",
|
| 58 |
"extra": [
|
| 59 |
-
{
|
| 60 |
-
"name": "genre",
|
| 61 |
-
"isRequired": False,
|
| 62 |
-
"options": GENRES
|
| 63 |
-
},
|
| 64 |
{"name": "skip"}
|
| 65 |
],
|
| 66 |
"extraSupported": ["genre", "skip"]
|
|
@@ -70,27 +119,18 @@ async def get_manifest():
|
|
| 70 |
"id": "top_movies",
|
| 71 |
"name": "Popular",
|
| 72 |
"extra": [
|
| 73 |
-
{
|
| 74 |
-
"name": "genre",
|
| 75 |
-
"isRequired": False,
|
| 76 |
-
"options": GENRES
|
| 77 |
-
},
|
| 78 |
{"name": "skip"},
|
| 79 |
{"name": "search", "isRequired": False}
|
| 80 |
],
|
| 81 |
"extraSupported": ["genre", "skip", "search"]
|
| 82 |
},
|
| 83 |
-
# Series Catalogs
|
| 84 |
{
|
| 85 |
"type": "series",
|
| 86 |
"id": "latest_series",
|
| 87 |
"name": "Latest",
|
| 88 |
"extra": [
|
| 89 |
-
{
|
| 90 |
-
"name": "genre",
|
| 91 |
-
"isRequired": False,
|
| 92 |
-
"options": GENRES
|
| 93 |
-
},
|
| 94 |
{"name": "skip"}
|
| 95 |
],
|
| 96 |
"extraSupported": ["genre", "skip"]
|
|
@@ -100,11 +140,7 @@ async def get_manifest():
|
|
| 100 |
"id": "top_series",
|
| 101 |
"name": "Popular",
|
| 102 |
"extra": [
|
| 103 |
-
{
|
| 104 |
-
"name": "genre",
|
| 105 |
-
"isRequired": False,
|
| 106 |
-
"options": GENRES
|
| 107 |
-
},
|
| 108 |
{"name": "skip"},
|
| 109 |
{"name": "search", "isRequired": False}
|
| 110 |
],
|
|
@@ -116,18 +152,19 @@ async def get_manifest():
|
|
| 116 |
"configurable": False,
|
| 117 |
"configurationRequired": False
|
| 118 |
}
|
| 119 |
-
|
| 120 |
-
|
|
|
|
| 121 |
@router.get("/catalog/{media_type}/{id}/{extra:path}.json")
|
| 122 |
@router.get("/catalog/{media_type}/{id}.json")
|
| 123 |
async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
| 124 |
if media_type not in ["movie", "series"]:
|
| 125 |
raise HTTPException(status_code=404, detail="Invalid catalog type")
|
| 126 |
-
|
| 127 |
genre_filter = None
|
| 128 |
search_query = None
|
| 129 |
stremio_skip = 0
|
| 130 |
-
|
| 131 |
if extra:
|
| 132 |
params = extra.replace("&", "/").split("/")
|
| 133 |
for param in params:
|
|
@@ -140,9 +177,9 @@ async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
|
| 140 |
stremio_skip = int(param.removeprefix("skip="))
|
| 141 |
except ValueError:
|
| 142 |
stremio_skip = 0
|
| 143 |
-
|
| 144 |
page = (stremio_skip // PAGE_SIZE) + 1
|
| 145 |
-
|
| 146 |
try:
|
| 147 |
if search_query:
|
| 148 |
search_results = await db.search_documents(query=search_query, page=page, page_size=PAGE_SIZE)
|
|
@@ -156,21 +193,20 @@ async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
|
| 156 |
sort_params = [("rating", "desc")]
|
| 157 |
else:
|
| 158 |
sort_params = [("updated_on", "desc")]
|
| 159 |
-
|
| 160 |
if media_type == "movie":
|
| 161 |
data = await db.sort_movies(sort_params, page, PAGE_SIZE, genre_filter=genre_filter)
|
| 162 |
items = data.get("movies", [])
|
| 163 |
else:
|
| 164 |
data = await db.sort_tv_shows(sort_params, page, PAGE_SIZE, genre_filter=genre_filter)
|
| 165 |
items = data.get("tv_shows", [])
|
| 166 |
-
|
| 167 |
except Exception as e:
|
| 168 |
-
print(f"Error fetching catalog data: {e}")
|
| 169 |
return {"metas": []}
|
| 170 |
-
|
| 171 |
metas = [convert_to_stremio_meta(item) for item in items]
|
| 172 |
return {"metas": metas}
|
| 173 |
|
|
|
|
| 174 |
@router.get("/meta/{media_type}/{id}.json")
|
| 175 |
async def get_meta(media_type: str, id: str):
|
| 176 |
try:
|
|
@@ -178,12 +214,11 @@ async def get_meta(media_type: str, id: str):
|
|
| 178 |
tmdb_id, db_index = int(tmdb_id_str), int(db_index_str)
|
| 179 |
except (ValueError, IndexError):
|
| 180 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 181 |
-
|
| 182 |
media = await db.get_media_details(tmdb_id=tmdb_id, db_index=db_index)
|
| 183 |
-
|
| 184 |
if not media:
|
| 185 |
return {"meta": {}}
|
| 186 |
-
|
| 187 |
meta_obj = {
|
| 188 |
"id": id,
|
| 189 |
"type": "series" if media.get("media_type") == "tv" else "movie",
|
|
@@ -197,11 +232,10 @@ async def get_meta(media_type: str, id: str):
|
|
| 197 |
"background": media.get("backdrop", ""),
|
| 198 |
"imdb_id": media.get("imdb_id", "")
|
| 199 |
}
|
| 200 |
-
|
| 201 |
if media_type == "series" and "seasons" in media:
|
| 202 |
series_base_id = id
|
| 203 |
videos = []
|
| 204 |
-
|
| 205 |
for season in sorted(media.get("seasons", []), key=lambda s: s.get("season_number")):
|
| 206 |
for episode in sorted(season.get("episodes", []), key=lambda e: e.get("episode_number")):
|
| 207 |
episode_id = f"{series_base_id}:{season['season_number']}:{episode['episode_number']}"
|
|
@@ -210,14 +244,20 @@ async def get_meta(media_type: str, id: str):
|
|
| 210 |
"title": episode.get("title", f"Episode {episode['episode_number']}"),
|
| 211 |
"season": season.get("season_number"),
|
| 212 |
"episode": episode.get("episode_number"),
|
|
|
|
|
|
|
| 213 |
"thumbnail": episode.get("episode_backdrop") or "https://via.placeholder.com/1280x720/1a1a2e/eaeaea?text=No+Image",
|
| 214 |
"imdb_id": episode.get("imdb_id") or media.get("imdb_id"),
|
| 215 |
})
|
| 216 |
-
|
| 217 |
meta_obj["videos"] = videos
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
return {"meta": meta_obj}
|
| 220 |
|
|
|
|
| 221 |
@router.get("/stream/{media_type}/{id}.json")
|
| 222 |
async def get_streams(media_type: str, id: str):
|
| 223 |
try:
|
|
@@ -228,25 +268,31 @@ async def get_streams(media_type: str, id: str):
|
|
| 228 |
tmdb_id, db_index = map(int, base_id.split("-"))
|
| 229 |
except (ValueError, IndexError):
|
| 230 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 231 |
-
|
| 232 |
media_details = await db.get_media_details(
|
| 233 |
tmdb_id=tmdb_id,
|
| 234 |
db_index=db_index,
|
| 235 |
season_number=season_num,
|
| 236 |
episode_number=episode_num
|
| 237 |
)
|
| 238 |
-
|
| 239 |
if not media_details or "telegram" not in media_details:
|
| 240 |
return {"streams": []}
|
| 241 |
-
|
| 242 |
-
streams = [
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
return {"streams": streams}
|
|
|
|
| 3 |
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
|
|
|
|
| 15 |
|
| 16 |
# Define available genres
|
| 17 |
GENRES = [
|
| 18 |
+
"Action", "Adventure", "Animation", "Biography", "Comedy",
|
| 19 |
+
"Crime", "Documentary", "Drama", "Family", "Fantasy",
|
| 20 |
+
"History", "Horror", "Music", "Mystery", "Romance",
|
| 21 |
"Sci-Fi", "Sport", "Thriller", "War", "Western"
|
| 22 |
]
|
| 23 |
|
|
|
|
| 26 |
media_type = "series" if item.get("media_type") == "tv" else "movie"
|
| 27 |
stremio_id = f"{item.get('tmdb_id')}-{item.get('db_index')}"
|
| 28 |
|
| 29 |
+
meta = {
|
| 30 |
"id": stremio_id,
|
| 31 |
"type": media_type,
|
| 32 |
"name": item.get("title"),
|
|
|
|
| 39 |
"description": item.get("description") or "",
|
| 40 |
}
|
| 41 |
|
| 42 |
+
cast_list = item.get("cast") or []
|
| 43 |
+
if cast_list:
|
| 44 |
+
meta["cast"] = cast_list[:5]
|
| 45 |
+
return meta
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def format_stream_details(filename: str, quality: str, size: str) -> tuple[str, str]:
|
| 49 |
+
try:
|
| 50 |
+
parsed = PTN.parse(filename)
|
| 51 |
+
except Exception:
|
| 52 |
+
return (f"Telegram {quality}", f"📁 {filename}\n💾 {size}")
|
| 53 |
+
|
| 54 |
+
codec_parts = []
|
| 55 |
+
if parsed.get("codec"):
|
| 56 |
+
codec_parts.append(f"🎥 {parsed.get('codec')}")
|
| 57 |
+
if parsed.get("bitDepth"):
|
| 58 |
+
codec_parts.append(f"🌈 {parsed.get('bitDepth')}bit")
|
| 59 |
+
if parsed.get("audio"):
|
| 60 |
+
codec_parts.append(f"🔊 {parsed.get('audio')}")
|
| 61 |
+
if parsed.get("encoder"):
|
| 62 |
+
codec_parts.append(f"👤 {parsed.get('encoder')}")
|
| 63 |
+
|
| 64 |
+
codec_info = " ".join(codec_parts) if codec_parts else ""
|
| 65 |
+
|
| 66 |
+
resolution = parsed.get("resolution", quality)
|
| 67 |
+
quality_type = parsed.get("quality", "")
|
| 68 |
+
stream_name = f"Telegram {resolution} {quality_type}".strip()
|
| 69 |
+
|
| 70 |
+
stream_title_parts = [
|
| 71 |
+
f"📁 {filename}",
|
| 72 |
+
f"💾 {size}",
|
| 73 |
+
]
|
| 74 |
+
if codec_info:
|
| 75 |
+
stream_title_parts.append(codec_info)
|
| 76 |
+
|
| 77 |
+
stream_title = "\n".join(stream_title_parts)
|
| 78 |
+
return (stream_name, stream_title)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def get_resolution_priority(stream_name: str) -> int:
|
| 82 |
+
resolution_map = {
|
| 83 |
+
"2160p": 2160, "4k": 2160, "uhd": 2160,
|
| 84 |
+
"1080p": 1080, "fhd": 1080,
|
| 85 |
+
"720p": 720, "hd": 720,
|
| 86 |
+
"480p": 480, "sd": 480,
|
| 87 |
+
"360p": 360,
|
| 88 |
+
}
|
| 89 |
+
for res_key, res_value in resolution_map.items():
|
| 90 |
+
if res_key in stream_name.lower():
|
| 91 |
+
return res_value
|
| 92 |
+
return 1
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# --- Routes ---
|
| 96 |
@router.get("/manifest.json")
|
| 97 |
async def get_manifest():
|
| 98 |
return {
|
|
|
|
| 104 |
"types": ["movie", "series"],
|
| 105 |
"resources": ["catalog", "meta", "stream"],
|
| 106 |
"catalogs": [
|
|
|
|
| 107 |
{
|
| 108 |
"type": "movie",
|
| 109 |
"id": "latest_movies",
|
| 110 |
"name": "Latest",
|
| 111 |
"extra": [
|
| 112 |
+
{"name": "genre", "isRequired": False, "options": GENRES},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
{"name": "skip"}
|
| 114 |
],
|
| 115 |
"extraSupported": ["genre", "skip"]
|
|
|
|
| 119 |
"id": "top_movies",
|
| 120 |
"name": "Popular",
|
| 121 |
"extra": [
|
| 122 |
+
{"name": "genre", "isRequired": False, "options": GENRES},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
{"name": "skip"},
|
| 124 |
{"name": "search", "isRequired": False}
|
| 125 |
],
|
| 126 |
"extraSupported": ["genre", "skip", "search"]
|
| 127 |
},
|
|
|
|
| 128 |
{
|
| 129 |
"type": "series",
|
| 130 |
"id": "latest_series",
|
| 131 |
"name": "Latest",
|
| 132 |
"extra": [
|
| 133 |
+
{"name": "genre", "isRequired": False, "options": GENRES},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
{"name": "skip"}
|
| 135 |
],
|
| 136 |
"extraSupported": ["genre", "skip"]
|
|
|
|
| 140 |
"id": "top_series",
|
| 141 |
"name": "Popular",
|
| 142 |
"extra": [
|
| 143 |
+
{"name": "genre", "isRequired": False, "options": GENRES},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
{"name": "skip"},
|
| 145 |
{"name": "search", "isRequired": False}
|
| 146 |
],
|
|
|
|
| 152 |
"configurable": False,
|
| 153 |
"configurationRequired": False
|
| 154 |
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
|
| 158 |
@router.get("/catalog/{media_type}/{id}/{extra:path}.json")
|
| 159 |
@router.get("/catalog/{media_type}/{id}.json")
|
| 160 |
async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
| 161 |
if media_type not in ["movie", "series"]:
|
| 162 |
raise HTTPException(status_code=404, detail="Invalid catalog type")
|
| 163 |
+
|
| 164 |
genre_filter = None
|
| 165 |
search_query = None
|
| 166 |
stremio_skip = 0
|
| 167 |
+
|
| 168 |
if extra:
|
| 169 |
params = extra.replace("&", "/").split("/")
|
| 170 |
for param in params:
|
|
|
|
| 177 |
stremio_skip = int(param.removeprefix("skip="))
|
| 178 |
except ValueError:
|
| 179 |
stremio_skip = 0
|
| 180 |
+
|
| 181 |
page = (stremio_skip // PAGE_SIZE) + 1
|
| 182 |
+
|
| 183 |
try:
|
| 184 |
if search_query:
|
| 185 |
search_results = await db.search_documents(query=search_query, page=page, page_size=PAGE_SIZE)
|
|
|
|
| 193 |
sort_params = [("rating", "desc")]
|
| 194 |
else:
|
| 195 |
sort_params = [("updated_on", "desc")]
|
| 196 |
+
|
| 197 |
if media_type == "movie":
|
| 198 |
data = await db.sort_movies(sort_params, page, PAGE_SIZE, genre_filter=genre_filter)
|
| 199 |
items = data.get("movies", [])
|
| 200 |
else:
|
| 201 |
data = await db.sort_tv_shows(sort_params, page, PAGE_SIZE, genre_filter=genre_filter)
|
| 202 |
items = data.get("tv_shows", [])
|
|
|
|
| 203 |
except Exception as e:
|
|
|
|
| 204 |
return {"metas": []}
|
| 205 |
+
|
| 206 |
metas = [convert_to_stremio_meta(item) for item in items]
|
| 207 |
return {"metas": metas}
|
| 208 |
|
| 209 |
+
|
| 210 |
@router.get("/meta/{media_type}/{id}.json")
|
| 211 |
async def get_meta(media_type: str, id: str):
|
| 212 |
try:
|
|
|
|
| 214 |
tmdb_id, db_index = int(tmdb_id_str), int(db_index_str)
|
| 215 |
except (ValueError, IndexError):
|
| 216 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 217 |
+
|
| 218 |
media = await db.get_media_details(tmdb_id=tmdb_id, db_index=db_index)
|
|
|
|
| 219 |
if not media:
|
| 220 |
return {"meta": {}}
|
| 221 |
+
|
| 222 |
meta_obj = {
|
| 223 |
"id": id,
|
| 224 |
"type": "series" if media.get("media_type") == "tv" else "movie",
|
|
|
|
| 232 |
"background": media.get("backdrop", ""),
|
| 233 |
"imdb_id": media.get("imdb_id", "")
|
| 234 |
}
|
| 235 |
+
|
| 236 |
if media_type == "series" and "seasons" in media:
|
| 237 |
series_base_id = id
|
| 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 |
episode_id = f"{series_base_id}:{season['season_number']}:{episode['episode_number']}"
|
|
|
|
| 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 "https://via.placeholder.com/1280x720/1a1a2e/eaeaea?text=No+Image",
|
| 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]
|
| 257 |
+
|
| 258 |
return {"meta": meta_obj}
|
| 259 |
|
| 260 |
+
|
| 261 |
@router.get("/stream/{media_type}/{id}.json")
|
| 262 |
async def get_streams(media_type: str, id: str):
|
| 263 |
try:
|
|
|
|
| 268 |
tmdb_id, db_index = map(int, base_id.split("-"))
|
| 269 |
except (ValueError, IndexError):
|
| 270 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 271 |
+
|
| 272 |
media_details = await db.get_media_details(
|
| 273 |
tmdb_id=tmdb_id,
|
| 274 |
db_index=db_index,
|
| 275 |
season_number=season_num,
|
| 276 |
episode_number=episode_num
|
| 277 |
)
|
| 278 |
+
|
| 279 |
if not media_details or "telegram" not in media_details:
|
| 280 |
return {"streams": []}
|
| 281 |
+
|
| 282 |
+
streams = []
|
| 283 |
+
for quality in media_details.get("telegram", []):
|
| 284 |
+
if quality.get("id"):
|
| 285 |
+
filename = quality.get('name', '')
|
| 286 |
+
quality_str = quality.get('quality', 'HD')
|
| 287 |
+
size = quality.get('size', '')
|
| 288 |
+
|
| 289 |
+
stream_name, stream_title = format_stream_details(filename, quality_str, size)
|
| 290 |
+
|
| 291 |
+
streams.append({
|
| 292 |
+
"name": stream_name,
|
| 293 |
+
"title": stream_title,
|
| 294 |
+
"url": f"{BASE_URL}/dl/{quality.get('id')}/video.mkv"
|
| 295 |
+
})
|
| 296 |
+
|
| 297 |
+
streams.sort(key=lambda s: get_resolution_priority(s.get("name", "")), reverse=True)
|
| 298 |
return {"streams": streams}
|
Backend/helper/database.py
CHANGED
|
@@ -189,6 +189,7 @@ class Database:
|
|
| 189 |
poster=metadata_info['poster'],
|
| 190 |
backdrop=metadata_info['backdrop'],
|
| 191 |
logo=metadata_info['logo'],
|
|
|
|
| 192 |
media_type=metadata_info['media_type'],
|
| 193 |
telegram=[QualityDetail(
|
| 194 |
quality=metadata_info['quality'],
|
|
@@ -211,6 +212,7 @@ class Database:
|
|
| 211 |
poster=metadata_info['poster'],
|
| 212 |
backdrop=metadata_info['backdrop'],
|
| 213 |
logo=metadata_info['logo'],
|
|
|
|
| 214 |
media_type=metadata_info['media_type'],
|
| 215 |
seasons=[Season(
|
| 216 |
season_number=metadata_info['season_number'],
|
|
@@ -218,6 +220,8 @@ class Database:
|
|
| 218 |
episode_number=metadata_info['episode_number'],
|
| 219 |
title=metadata_info['episode_title'],
|
| 220 |
episode_backdrop=metadata_info['episode_backdrop'],
|
|
|
|
|
|
|
| 221 |
telegram=[QualityDetail(
|
| 222 |
quality=metadata_info['quality'],
|
| 223 |
id=metadata_info['encoded_string'],
|
|
|
|
| 189 |
poster=metadata_info['poster'],
|
| 190 |
backdrop=metadata_info['backdrop'],
|
| 191 |
logo=metadata_info['logo'],
|
| 192 |
+
cast=metadata_info['cast'],
|
| 193 |
media_type=metadata_info['media_type'],
|
| 194 |
telegram=[QualityDetail(
|
| 195 |
quality=metadata_info['quality'],
|
|
|
|
| 212 |
poster=metadata_info['poster'],
|
| 213 |
backdrop=metadata_info['backdrop'],
|
| 214 |
logo=metadata_info['logo'],
|
| 215 |
+
cast=metadata_info['cast'],
|
| 216 |
media_type=metadata_info['media_type'],
|
| 217 |
seasons=[Season(
|
| 218 |
season_number=metadata_info['season_number'],
|
|
|
|
| 220 |
episode_number=metadata_info['episode_number'],
|
| 221 |
title=metadata_info['episode_title'],
|
| 222 |
episode_backdrop=metadata_info['episode_backdrop'],
|
| 223 |
+
overview=metadata_info['episode_overview'],
|
| 224 |
+
released=metadata_info['episode_released'],
|
| 225 |
telegram=[QualityDetail(
|
| 226 |
quality=metadata_info['quality'],
|
| 227 |
id=metadata_info['encoded_string'],
|
Backend/helper/metadata.py
CHANGED
|
@@ -142,7 +142,7 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
|
|
| 142 |
|
| 143 |
tv_id = tmdb_result.id
|
| 144 |
try:
|
| 145 |
-
tv_details = await tmdb.tv(tv_id).details(append_to_response="external_ids")
|
| 146 |
except Exception as e:
|
| 147 |
LOGGER.warning(f"TMDb TV details failed for {title}: {e}")
|
| 148 |
return None
|
|
@@ -156,6 +156,15 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
|
|
| 156 |
|
| 157 |
# Return TMDb-based data
|
| 158 |
if use_tmdb and tv_details:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
return {
|
| 160 |
"tmdb_id": tv_details.id,
|
| 161 |
"imdb_id": tv_details.external_ids.imdb_id,
|
|
@@ -168,10 +177,13 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
|
|
| 168 |
"logo": "",
|
| 169 |
"genres": [g.name for g in (tv_details.genres or [])],
|
| 170 |
"media_type": "tv",
|
|
|
|
| 171 |
"season_number": season,
|
| 172 |
"episode_number": episode,
|
| 173 |
"episode_title": getattr(ep_details, "name", f"S{season}E{episode}") if ep_details else f"{tv_details.name} S{season}E{episode}",
|
| 174 |
"episode_backdrop": format_tmdb_image(getattr(ep_details, "still_path", None), "original") if ep_details else "",
|
|
|
|
|
|
|
| 175 |
"quality": quality,
|
| 176 |
"encoded_string": encoded_string,
|
| 177 |
}
|
|
@@ -194,12 +206,15 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
|
|
| 194 |
"poster": images["poster"],
|
| 195 |
"backdrop": images["backdrop"],
|
| 196 |
"logo": images["logo"],
|
|
|
|
| 197 |
"genres": tv_details.get("genre", []),
|
| 198 |
"media_type": "tv",
|
| 199 |
"season_number": season,
|
| 200 |
"episode_number": episode,
|
| 201 |
"episode_title": ep_details.get("title", f"S{season}E{episode}") if ep_details else f"{tv_details.get('title', title)} S{season}E{episode}",
|
| 202 |
"episode_backdrop": ep_details.get("image", "") if ep_details else "",
|
|
|
|
|
|
|
| 203 |
"quality": quality,
|
| 204 |
"encoded_string": encoded_string,
|
| 205 |
}
|
|
@@ -225,13 +240,21 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 225 |
return None
|
| 226 |
|
| 227 |
try:
|
| 228 |
-
movie_details = await tmdb.movie(tmdb_result.id).details(append_to_response="external_ids")
|
| 229 |
except Exception as e:
|
| 230 |
LOGGER.warning(f"TMDb movie details failed for {title}: {e}")
|
| 231 |
return None
|
| 232 |
|
| 233 |
# TMDb result
|
| 234 |
if use_tmdb and movie_details:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
return {
|
| 236 |
"tmdb_id": movie_details.id,
|
| 237 |
"imdb_id": movie_details.external_ids.imdb_id,
|
|
@@ -242,6 +265,7 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 242 |
"poster": format_tmdb_image(movie_details.poster_path),
|
| 243 |
"backdrop": format_tmdb_image(movie_details.backdrop_path, "original"),
|
| 244 |
"logo": "",
|
|
|
|
| 245 |
"media_type": "movie",
|
| 246 |
"genres": [g.name for g in (movie_details.genres or [])],
|
| 247 |
"quality": quality,
|
|
@@ -262,6 +286,7 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 262 |
"poster": images["poster"],
|
| 263 |
"backdrop": images["backdrop"],
|
| 264 |
"logo": images["logo"],
|
|
|
|
| 265 |
"media_type": "movie",
|
| 266 |
"genres": movie_details.get("genre", []),
|
| 267 |
"quality": quality,
|
|
|
|
| 142 |
|
| 143 |
tv_id = tmdb_result.id
|
| 144 |
try:
|
| 145 |
+
tv_details = await tmdb.tv(tv_id).details(append_to_response="external_ids,credits")
|
| 146 |
except Exception as e:
|
| 147 |
LOGGER.warning(f"TMDb TV details failed for {title}: {e}")
|
| 148 |
return None
|
|
|
|
| 156 |
|
| 157 |
# Return TMDb-based data
|
| 158 |
if use_tmdb and tv_details:
|
| 159 |
+
credits = getattr(tv_details, "credits", None) or {}
|
| 160 |
+
cast_names = []
|
| 161 |
+
if credits:
|
| 162 |
+
cast_list = getattr(credits, "cast", []) or []
|
| 163 |
+
for member in cast_list:
|
| 164 |
+
name = getattr(member, "name", None) or getattr(member, "original_name", None)
|
| 165 |
+
if name:
|
| 166 |
+
cast_names.append(name)
|
| 167 |
+
|
| 168 |
return {
|
| 169 |
"tmdb_id": tv_details.id,
|
| 170 |
"imdb_id": tv_details.external_ids.imdb_id,
|
|
|
|
| 177 |
"logo": "",
|
| 178 |
"genres": [g.name for g in (tv_details.genres or [])],
|
| 179 |
"media_type": "tv",
|
| 180 |
+
"cast": cast_names,
|
| 181 |
"season_number": season,
|
| 182 |
"episode_number": episode,
|
| 183 |
"episode_title": getattr(ep_details, "name", f"S{season}E{episode}") if ep_details else f"{tv_details.name} S{season}E{episode}",
|
| 184 |
"episode_backdrop": format_tmdb_image(getattr(ep_details, "still_path", None), "original") if ep_details else "",
|
| 185 |
+
"episode_overview": getattr(ep_details, "overview", "") if ep_details else "",
|
| 186 |
+
"episode_released": (str(ep_details.air_date.strftime("%Y-%m-%dT05:00:00.000Z")) if getattr(ep_details, "air_date", None) else ""),
|
| 187 |
"quality": quality,
|
| 188 |
"encoded_string": encoded_string,
|
| 189 |
}
|
|
|
|
| 206 |
"poster": images["poster"],
|
| 207 |
"backdrop": images["backdrop"],
|
| 208 |
"logo": images["logo"],
|
| 209 |
+
"cast": tv_details.get("cast", []),
|
| 210 |
"genres": tv_details.get("genre", []),
|
| 211 |
"media_type": "tv",
|
| 212 |
"season_number": season,
|
| 213 |
"episode_number": episode,
|
| 214 |
"episode_title": ep_details.get("title", f"S{season}E{episode}") if ep_details else f"{tv_details.get('title', title)} S{season}E{episode}",
|
| 215 |
"episode_backdrop": ep_details.get("image", "") if ep_details else "",
|
| 216 |
+
"episode_overview": ep_details.get("plot", "") if ep_details else "",
|
| 217 |
+
"episode_released": str(ep_details.get("released", "")) if ep_details else "",
|
| 218 |
"quality": quality,
|
| 219 |
"encoded_string": encoded_string,
|
| 220 |
}
|
|
|
|
| 240 |
return None
|
| 241 |
|
| 242 |
try:
|
| 243 |
+
movie_details = await tmdb.movie(tmdb_result.id).details(append_to_response="external_ids,credits")
|
| 244 |
except Exception as e:
|
| 245 |
LOGGER.warning(f"TMDb movie details failed for {title}: {e}")
|
| 246 |
return None
|
| 247 |
|
| 248 |
# TMDb result
|
| 249 |
if use_tmdb and movie_details:
|
| 250 |
+
credits = getattr(movie_details, "credits", None) or {}
|
| 251 |
+
cast_names = []
|
| 252 |
+
if credits:
|
| 253 |
+
cast_list = getattr(credits, "cast", []) or []
|
| 254 |
+
for member in cast_list:
|
| 255 |
+
name = getattr(member, "name", None) or getattr(member, "original_name", None)
|
| 256 |
+
if name:
|
| 257 |
+
cast_names.append(name)
|
| 258 |
return {
|
| 259 |
"tmdb_id": movie_details.id,
|
| 260 |
"imdb_id": movie_details.external_ids.imdb_id,
|
|
|
|
| 265 |
"poster": format_tmdb_image(movie_details.poster_path),
|
| 266 |
"backdrop": format_tmdb_image(movie_details.backdrop_path, "original"),
|
| 267 |
"logo": "",
|
| 268 |
+
"cast": cast_names,
|
| 269 |
"media_type": "movie",
|
| 270 |
"genres": [g.name for g in (movie_details.genres or [])],
|
| 271 |
"quality": quality,
|
|
|
|
| 286 |
"poster": images["poster"],
|
| 287 |
"backdrop": images["backdrop"],
|
| 288 |
"logo": images["logo"],
|
| 289 |
+
"cast": movie_details.get("cast", []),
|
| 290 |
"media_type": "movie",
|
| 291 |
"genres": movie_details.get("genre", []),
|
| 292 |
"quality": quality,
|
Backend/helper/modal.py
CHANGED
|
@@ -12,6 +12,8 @@ class Episode(BaseModel):
|
|
| 12 |
episode_number: int
|
| 13 |
title: str
|
| 14 |
episode_backdrop: Optional[str] = None
|
|
|
|
|
|
|
| 15 |
telegram: Optional[List[QualityDetail]]
|
| 16 |
|
| 17 |
class Season(BaseModel):
|
|
@@ -30,6 +32,7 @@ class TVShowSchema(BaseModel):
|
|
| 30 |
poster: Optional[str] = None
|
| 31 |
backdrop: Optional[str] = None
|
| 32 |
logo: Optional[str] = None
|
|
|
|
| 33 |
media_type: str
|
| 34 |
updated_on: datetime = Field(default_factory=datetime.utcnow)
|
| 35 |
seasons: List[Season]
|
|
@@ -46,6 +49,7 @@ class MovieSchema(BaseModel):
|
|
| 46 |
poster: Optional[str] = None
|
| 47 |
backdrop: Optional[str] = None
|
| 48 |
logo: Optional[str] = None
|
|
|
|
| 49 |
media_type: str
|
| 50 |
updated_on: datetime = Field(default_factory=datetime.utcnow)
|
| 51 |
telegram: Optional[List[QualityDetail]]
|
|
|
|
| 12 |
episode_number: int
|
| 13 |
title: str
|
| 14 |
episode_backdrop: Optional[str] = None
|
| 15 |
+
overview: Optional[str] = None
|
| 16 |
+
released: Optional[str] = None
|
| 17 |
telegram: Optional[List[QualityDetail]]
|
| 18 |
|
| 19 |
class Season(BaseModel):
|
|
|
|
| 32 |
poster: Optional[str] = None
|
| 33 |
backdrop: Optional[str] = None
|
| 34 |
logo: Optional[str] = None
|
| 35 |
+
cast: Optional[List[str]] = None
|
| 36 |
media_type: str
|
| 37 |
updated_on: datetime = Field(default_factory=datetime.utcnow)
|
| 38 |
seasons: List[Season]
|
|
|
|
| 49 |
poster: Optional[str] = None
|
| 50 |
backdrop: Optional[str] = None
|
| 51 |
logo: Optional[str] = None
|
| 52 |
+
cast: Optional[List[str]] = None
|
| 53 |
media_type: str
|
| 54 |
updated_on: datetime = Field(default_factory=datetime.utcnow)
|
| 55 |
telegram: Optional[List[QualityDetail]]
|
Backend/helper/pyro.py
CHANGED
|
@@ -153,6 +153,7 @@ async def restart_notification():
|
|
| 153 |
commands = [
|
| 154 |
BotCommand("start", "🚀 Start the bot"),
|
| 155 |
BotCommand("set", "🎬 Manually add IMDb metadata"),
|
|
|
|
| 156 |
BotCommand("log", "📄 Send the log file"),
|
| 157 |
BotCommand("restart", "♻️ Restart the bot"),
|
| 158 |
]
|
|
|
|
| 153 |
commands = [
|
| 154 |
BotCommand("start", "🚀 Start the bot"),
|
| 155 |
BotCommand("set", "🎬 Manually add IMDb metadata"),
|
| 156 |
+
BotCommand("fixmetadata", "⚙️ Fix empty fields of Metadata"),
|
| 157 |
BotCommand("log", "📄 Send the log file"),
|
| 158 |
BotCommand("restart", "♻️ Restart the bot"),
|
| 159 |
]
|
Backend/pyrofork/plugins/fix_metadata.py
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
from pyrogram import Client, filters
|
| 3 |
+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
| 4 |
+
|
| 5 |
+
from Backend import db
|
| 6 |
+
from Backend.helper.custom_filter import CustomFilters
|
| 7 |
+
from Backend.helper.metadata import fetch_tv_metadata, fetch_movie_metadata
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
CANCEL_REQUESTED = False
|
| 11 |
+
|
| 12 |
+
# -------------------------------
|
| 13 |
+
# Progress Bar Helper
|
| 14 |
+
# -------------------------------
|
| 15 |
+
def progress_bar(done, total, length=20):
|
| 16 |
+
filled = int(length * (done / total))
|
| 17 |
+
return f"[{'█' * filled}{'░' * (length - filled)}] {done}/{total}"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# -------------------------------
|
| 21 |
+
# ETA Helper
|
| 22 |
+
# -------------------------------
|
| 23 |
+
def format_eta(seconds):
|
| 24 |
+
minutes, sec = divmod(int(seconds), 60)
|
| 25 |
+
hours, minutes = divmod(minutes, 60)
|
| 26 |
+
|
| 27 |
+
if hours > 0:
|
| 28 |
+
return f"{hours}h {minutes}m {sec}s"
|
| 29 |
+
if minutes > 0:
|
| 30 |
+
return f"{minutes}m {sec}s"
|
| 31 |
+
return f"{sec}s"
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# -------------------------------
|
| 35 |
+
# CANCEL BUTTON HANDLER
|
| 36 |
+
# -------------------------------
|
| 37 |
+
@Client.on_callback_query(filters.regex("cancel_fix"))
|
| 38 |
+
async def cancel_fix(_, query):
|
| 39 |
+
global CANCEL_REQUESTED
|
| 40 |
+
CANCEL_REQUESTED = True
|
| 41 |
+
await query.message.edit_text("❌ Metadata fixing has been cancelled by the user.")
|
| 42 |
+
await query.answer("Cancelled")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# -------------------------------
|
| 46 |
+
# MAIN COMMAND
|
| 47 |
+
# -------------------------------
|
| 48 |
+
@Client.on_message(filters.command("fixmetadata") & filters.private & CustomFilters.owner, group=10)
|
| 49 |
+
async def fix_metadata_handler(_, message):
|
| 50 |
+
global CANCEL_REQUESTED
|
| 51 |
+
CANCEL_REQUESTED = False
|
| 52 |
+
|
| 53 |
+
# Count total items
|
| 54 |
+
total_movies = 0
|
| 55 |
+
total_tv = 0
|
| 56 |
+
|
| 57 |
+
for i in range(1, db.current_db_index + 1):
|
| 58 |
+
key = f"storage_{i}"
|
| 59 |
+
total_movies += await db.dbs[key]["movie"].count_documents({})
|
| 60 |
+
total_tv += await db.dbs[key]["tv"].count_documents({})
|
| 61 |
+
|
| 62 |
+
TOTAL = total_movies + total_tv
|
| 63 |
+
DONE = 0
|
| 64 |
+
start_time = time.time()
|
| 65 |
+
|
| 66 |
+
status = await message.reply_text(
|
| 67 |
+
"⏳ Initializing metadata fixing...",
|
| 68 |
+
reply_markup=InlineKeyboardMarkup([
|
| 69 |
+
[InlineKeyboardButton("❌ Cancel", callback_data="cancel_fix")]
|
| 70 |
+
])
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
# -------------------------
|
| 74 |
+
# UPDATE MOVIES
|
| 75 |
+
# -------------------------
|
| 76 |
+
async def update_movies():
|
| 77 |
+
nonlocal DONE
|
| 78 |
+
for i in range(1, db.current_db_index + 1):
|
| 79 |
+
if CANCEL_REQUESTED:
|
| 80 |
+
return
|
| 81 |
+
|
| 82 |
+
key = f"storage_{i}"
|
| 83 |
+
collection = db.dbs[key]["movie"]
|
| 84 |
+
|
| 85 |
+
cursor = collection.find({})
|
| 86 |
+
async for movie in cursor:
|
| 87 |
+
if CANCEL_REQUESTED:
|
| 88 |
+
return
|
| 89 |
+
|
| 90 |
+
tmdb_id = movie["tmdb_id"]
|
| 91 |
+
title = movie["title"]
|
| 92 |
+
year = movie.get("release_year")
|
| 93 |
+
|
| 94 |
+
meta = await fetch_movie_metadata(
|
| 95 |
+
title=title,
|
| 96 |
+
encoded_string=None,
|
| 97 |
+
year=year,
|
| 98 |
+
quality=None,
|
| 99 |
+
default_id=None
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
if meta:
|
| 103 |
+
await collection.update_one(
|
| 104 |
+
{"tmdb_id": tmdb_id},
|
| 105 |
+
{"$set": {
|
| 106 |
+
"imdb_id": meta.get("imdb_id"),
|
| 107 |
+
"cast": meta.get("cast"),
|
| 108 |
+
"description": meta.get("description"),
|
| 109 |
+
"genres": meta.get("genres"),
|
| 110 |
+
"poster": meta.get("poster"),
|
| 111 |
+
"backdrop": meta.get("backdrop"),
|
| 112 |
+
"logo": meta.get("logo"),
|
| 113 |
+
"rating": meta.get("rate"),
|
| 114 |
+
}}
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
DONE += 1
|
| 118 |
+
|
| 119 |
+
# Update progress every 5 items
|
| 120 |
+
if DONE % 5 == 0:
|
| 121 |
+
elapsed = time.time() - start_time
|
| 122 |
+
avg_time = elapsed / DONE
|
| 123 |
+
eta = avg_time * (TOTAL - DONE)
|
| 124 |
+
|
| 125 |
+
await status.edit_text(
|
| 126 |
+
f"🎬 Updating Movies…\n"
|
| 127 |
+
f"{progress_bar(DONE, TOTAL)}\n"
|
| 128 |
+
f"⏱ ETA: {format_eta(eta)}",
|
| 129 |
+
reply_markup=InlineKeyboardMarkup([
|
| 130 |
+
[InlineKeyboardButton("❌ Cancel", callback_data="cancel_fix")]
|
| 131 |
+
])
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# -------------------------
|
| 135 |
+
# UPDATE TV SHOWS + EPISODES
|
| 136 |
+
# -------------------------
|
| 137 |
+
async def update_tv():
|
| 138 |
+
nonlocal DONE
|
| 139 |
+
for i in range(1, db.current_db_index + 1):
|
| 140 |
+
if CANCEL_REQUESTED:
|
| 141 |
+
return
|
| 142 |
+
|
| 143 |
+
key = f"storage_{i}"
|
| 144 |
+
collection = db.dbs[key]["tv"]
|
| 145 |
+
|
| 146 |
+
cursor = collection.find({})
|
| 147 |
+
async for tv in cursor:
|
| 148 |
+
if CANCEL_REQUESTED:
|
| 149 |
+
return
|
| 150 |
+
|
| 151 |
+
tmdb_id = tv["tmdb_id"]
|
| 152 |
+
title = tv["title"]
|
| 153 |
+
year = tv.get("release_year")
|
| 154 |
+
|
| 155 |
+
# Show-level update
|
| 156 |
+
meta = await fetch_tv_metadata(
|
| 157 |
+
title=title,
|
| 158 |
+
season=1,
|
| 159 |
+
episode=1,
|
| 160 |
+
encoded_string=None,
|
| 161 |
+
year=year,
|
| 162 |
+
quality=None,
|
| 163 |
+
default_id=None
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
if meta:
|
| 167 |
+
await collection.update_one(
|
| 168 |
+
{"tmdb_id": tmdb_id},
|
| 169 |
+
{"$set": {
|
| 170 |
+
"imdb_id": meta.get("imdb_id"),
|
| 171 |
+
"cast": meta.get("cast"),
|
| 172 |
+
"description": meta.get("description"),
|
| 173 |
+
"genres": meta.get("genres"),
|
| 174 |
+
"poster": meta.get("poster"),
|
| 175 |
+
"backdrop": meta.get("backdrop"),
|
| 176 |
+
"logo": meta.get("logo"),
|
| 177 |
+
"rating": meta.get("rate"),
|
| 178 |
+
}}
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
# Episode-level update
|
| 182 |
+
for season in tv["seasons"]:
|
| 183 |
+
if CANCEL_REQUESTED:
|
| 184 |
+
return
|
| 185 |
+
|
| 186 |
+
s = season["season_number"]
|
| 187 |
+
|
| 188 |
+
for ep in season["episodes"]:
|
| 189 |
+
e = ep["episode_number"]
|
| 190 |
+
|
| 191 |
+
ep_meta = await fetch_tv_metadata(
|
| 192 |
+
title=title,
|
| 193 |
+
season=s,
|
| 194 |
+
episode=e,
|
| 195 |
+
encoded_string=None,
|
| 196 |
+
year=year,
|
| 197 |
+
quality=None,
|
| 198 |
+
default_id=None
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
if ep_meta:
|
| 202 |
+
await collection.update_one(
|
| 203 |
+
{"tmdb_id": tmdb_id},
|
| 204 |
+
{"$set": {
|
| 205 |
+
"seasons.$[s].episodes.$[e].overview": ep_meta.get("episode_overview"),
|
| 206 |
+
"seasons.$[s].episodes.$[e].released": ep_meta.get("episode_released"),
|
| 207 |
+
"seasons.$[s].episodes.$[e].episode_backdrop": ep_meta.get("episode_backdrop"),
|
| 208 |
+
}},
|
| 209 |
+
array_filters=[
|
| 210 |
+
{"s.season_number": s},
|
| 211 |
+
{"e.episode_number": e}
|
| 212 |
+
]
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
DONE += 1
|
| 216 |
+
|
| 217 |
+
if DONE % 5 == 0:
|
| 218 |
+
elapsed = time.time() - start_time
|
| 219 |
+
avg_time = elapsed / DONE
|
| 220 |
+
eta = avg_time * (TOTAL - DONE)
|
| 221 |
+
|
| 222 |
+
await status.edit_text(
|
| 223 |
+
f"📺 Updating TV Shows…\n"
|
| 224 |
+
f"{progress_bar(DONE, TOTAL)}\n"
|
| 225 |
+
f"⏱ ETA: {format_eta(eta)}",
|
| 226 |
+
reply_markup=InlineKeyboardMarkup([
|
| 227 |
+
[InlineKeyboardButton("❌ Cancel", callback_data="cancel_fix")]
|
| 228 |
+
])
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
# Run the process
|
| 232 |
+
await update_movies()
|
| 233 |
+
if not CANCEL_REQUESTED:
|
| 234 |
+
await update_tv()
|
| 235 |
+
|
| 236 |
+
if CANCEL_REQUESTED:
|
| 237 |
+
return
|
| 238 |
+
|
| 239 |
+
await status.edit_text(
|
| 240 |
+
f"🎉 **Metadata Fix Completed!**\n"
|
| 241 |
+
f"{progress_bar(DONE, TOTAL)}\n"
|
| 242 |
+
f"⏱ Time Taken: {format_eta(time.time() - start_time)}"
|
| 243 |
+
)
|
pyproject.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
[project]
|
| 2 |
name = "Telegram-Stremio"
|
| 3 |
-
version = "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.0"
|
| 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.
|
| 905 |
source = { virtual = "." }
|
| 906 |
dependencies = [
|
| 907 |
{ name = "aiofiles" },
|
|
|
|
| 901 |
|
| 902 |
[[package]]
|
| 903 |
name = "telegram-stremio"
|
| 904 |
+
version = "1.3.0"
|
| 905 |
source = { virtual = "." }
|
| 906 |
dependencies = [
|
| 907 |
{ name = "aiofiles" },
|