weebzone commited on
Commit Β·
adf3244
1
Parent(s): d5d1103
`v1.6.0`
Browse filesfeat: add HIDE_CATALOG option to hide default Telegram Stremio catalog
fix: minor catalog visibility bugs
docs: update README with new configuration option
- Backend/__init__.py +1 -1
- Backend/config.py +4 -1
- Backend/fastapi/routes/stremio_routes.py +46 -27
- Backend/helper/database.py +52 -53
- Backend/helper/imdb.py +1 -14
- Backend/helper/metadata.py +4 -3
- Backend/helper/pyro.py +1 -1
- Backend/pyrofork/plugins/fix_metadata.py +1 -1
- README.md +1 -0
- pyproject.toml +1 -1
- sample_config.env +1 -0
- 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.6.0"
|
Backend/config.py
CHANGED
|
@@ -21,8 +21,11 @@ class Telegram:
|
|
| 21 |
UPSTREAM_BRANCH = getenv("UPSTREAM_BRANCH", "")
|
| 22 |
|
| 23 |
OWNER_ID = int(getenv("OWNER_ID", "5422223708"))
|
|
|
|
| 24 |
REPLACE_MODE = getenv("REPLACE_MODE", "true").lower() == "true"
|
|
|
|
|
|
|
| 25 |
|
| 26 |
ADMIN_USERNAME = getenv("ADMIN_USERNAME", "fyvio")
|
| 27 |
ADMIN_PASSWORD = getenv("ADMIN_PASSWORD", "fyvio")
|
| 28 |
-
|
|
|
|
| 21 |
UPSTREAM_BRANCH = getenv("UPSTREAM_BRANCH", "")
|
| 22 |
|
| 23 |
OWNER_ID = int(getenv("OWNER_ID", "5422223708"))
|
| 24 |
+
|
| 25 |
REPLACE_MODE = getenv("REPLACE_MODE", "true").lower() == "true"
|
| 26 |
+
HIDE_CATALOG = getenv("HIDE_CATALOG", "false").lower() == "true"
|
| 27 |
+
# SKIP_MULTIPART = getenv("SKIP_MULTIPART", "true").lower() == "true"
|
| 28 |
|
| 29 |
ADMIN_USERNAME = getenv("ADMIN_USERNAME", "fyvio")
|
| 30 |
ADMIN_PASSWORD = getenv("ADMIN_PASSWORD", "fyvio")
|
| 31 |
+
|
Backend/fastapi/routes/stremio_routes.py
CHANGED
|
@@ -24,24 +24,33 @@ GENRES = [
|
|
| 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"
|
| 30 |
-
stremio_id = f"{item.get('tmdb_id')}-{item.get('db_index')}"
|
| 31 |
|
| 32 |
meta = {
|
| 33 |
-
"id":
|
| 34 |
"type": media_type,
|
| 35 |
"name": item.get("title"),
|
| 36 |
"poster": item.get("poster") or "",
|
| 37 |
"logo": item.get("logo") or "",
|
| 38 |
"year": item.get("release_year"),
|
| 39 |
-
"releaseInfo": item.get("release_year"),
|
| 40 |
"imdb_id": item.get("imdb_id", ""),
|
| 41 |
"moviedb_id": item.get("tmdb_id", ""),
|
| 42 |
"background": item.get("backdrop") or "",
|
| 43 |
"genres": item.get("genres") or [],
|
| 44 |
-
"imdbRating": item.get("rating") or "",
|
| 45 |
"description": item.get("description") or "",
|
| 46 |
"cast": item.get("cast") or [],
|
| 47 |
"runtime": item.get("runtime") or "",
|
|
@@ -96,19 +105,15 @@ def get_resolution_priority(stream_name: str) -> int:
|
|
| 96 |
return res_value
|
| 97 |
return 1
|
| 98 |
|
| 99 |
-
|
| 100 |
# --- Routes ---
|
| 101 |
@router.get("/manifest.json")
|
| 102 |
async def get_manifest():
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
"
|
| 108 |
-
|
| 109 |
-
"types": ["movie", "series"],
|
| 110 |
-
"resources": ["catalog", "meta", "stream"],
|
| 111 |
-
"catalogs": [
|
| 112 |
{
|
| 113 |
"type": "movie",
|
| 114 |
"id": "latest_movies",
|
|
@@ -151,8 +156,18 @@ async def get_manifest():
|
|
| 151 |
],
|
| 152 |
"extraSupported": ["genre", "skip", "search"]
|
| 153 |
}
|
| 154 |
-
]
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
"behaviorHints": {
|
| 157 |
"configurable": False,
|
| 158 |
"configurationRequired": False
|
|
@@ -163,6 +178,9 @@ async def get_manifest():
|
|
| 163 |
@router.get("/catalog/{media_type}/{id}/{extra:path}.json")
|
| 164 |
@router.get("/catalog/{media_type}/{id}.json")
|
| 165 |
async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
|
|
|
|
|
|
|
|
|
| 166 |
if media_type not in ["movie", "series"]:
|
| 167 |
raise HTTPException(status_code=404, detail="Invalid catalog type")
|
| 168 |
|
|
@@ -214,13 +232,14 @@ async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
|
| 214 |
|
| 215 |
@router.get("/meta/{media_type}/{id}.json")
|
| 216 |
async def get_meta(media_type: str, id: str):
|
|
|
|
|
|
|
| 217 |
try:
|
| 218 |
-
|
| 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(
|
| 224 |
if not media:
|
| 225 |
return {"meta": {}}
|
| 226 |
|
|
@@ -236,13 +255,17 @@ async def get_meta(media_type: str, id: str):
|
|
| 236 |
"logo": media.get("logo", ""),
|
| 237 |
"background": media.get("backdrop", ""),
|
| 238 |
"imdb_id": media.get("imdb_id", ""),
|
| 239 |
-
"releaseInfo": media.get("release_year"),
|
| 240 |
"moviedb_id": media.get("tmdb_id", ""),
|
| 241 |
"cast": media.get("cast") or [],
|
| 242 |
"runtime": media.get("runtime") or "",
|
| 243 |
-
|
| 244 |
}
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
# --- Add Episodes ---
|
| 247 |
if media_type == "series" and "seasons" in media:
|
| 248 |
|
|
@@ -269,23 +292,19 @@ async def get_meta(media_type: str, id: str):
|
|
| 269 |
meta_obj["videos"] = videos
|
| 270 |
return {"meta": meta_obj}
|
| 271 |
|
| 272 |
-
|
| 273 |
@router.get("/stream/{media_type}/{id}.json")
|
| 274 |
async def get_streams(media_type: str, id: str):
|
| 275 |
try:
|
| 276 |
parts = id.split(":")
|
| 277 |
-
|
| 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 |
-
|
| 288 |
-
db_index=db_index,
|
| 289 |
season_number=season_num,
|
| 290 |
episode_number=episode_num
|
| 291 |
)
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
|
| 27 |
+
def format_released_date(media):
|
| 28 |
+
year = media.get("release_year")
|
| 29 |
+
if year:
|
| 30 |
+
try:
|
| 31 |
+
return datetime(int(year), 1, 1).isoformat() + "Z"
|
| 32 |
+
except:
|
| 33 |
+
return None
|
| 34 |
+
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
# --- Helper Functions ---
|
| 38 |
def convert_to_stremio_meta(item: dict) -> dict:
|
| 39 |
media_type = "series" if item.get("media_type") == "tv" else "movie"
|
|
|
|
| 40 |
|
| 41 |
meta = {
|
| 42 |
+
"id": item.get('imdb_id'),
|
| 43 |
"type": media_type,
|
| 44 |
"name": item.get("title"),
|
| 45 |
"poster": item.get("poster") or "",
|
| 46 |
"logo": item.get("logo") or "",
|
| 47 |
"year": item.get("release_year"),
|
| 48 |
+
"releaseInfo": str(item.get("release_year", "")),
|
| 49 |
"imdb_id": item.get("imdb_id", ""),
|
| 50 |
"moviedb_id": item.get("tmdb_id", ""),
|
| 51 |
"background": item.get("backdrop") or "",
|
| 52 |
"genres": item.get("genres") or [],
|
| 53 |
+
"imdbRating": str(item.get("rating") or ""),
|
| 54 |
"description": item.get("description") or "",
|
| 55 |
"cast": item.get("cast") or [],
|
| 56 |
"runtime": item.get("runtime") or "",
|
|
|
|
| 105 |
return res_value
|
| 106 |
return 1
|
| 107 |
|
|
|
|
| 108 |
# --- Routes ---
|
| 109 |
@router.get("/manifest.json")
|
| 110 |
async def get_manifest():
|
| 111 |
+
if Telegram.HIDE_CATALOG:
|
| 112 |
+
resources = ["stream"]
|
| 113 |
+
catalogs = []
|
| 114 |
+
else:
|
| 115 |
+
resources = ["catalog", "meta", "stream"]
|
| 116 |
+
catalogs = [
|
|
|
|
|
|
|
|
|
|
| 117 |
{
|
| 118 |
"type": "movie",
|
| 119 |
"id": "latest_movies",
|
|
|
|
| 156 |
],
|
| 157 |
"extraSupported": ["genre", "skip", "search"]
|
| 158 |
}
|
| 159 |
+
]
|
| 160 |
+
|
| 161 |
+
return {
|
| 162 |
+
"id": "telegram.media",
|
| 163 |
+
"version": ADDON_VERSION,
|
| 164 |
+
"name": ADDON_NAME,
|
| 165 |
+
"logo": "https://i.postimg.cc/XqWnmDXr/Picsart-25-10-09-08-09-45-867.png",
|
| 166 |
+
"description": "Streams movies and series from your Telegram.",
|
| 167 |
+
"types": ["movie", "series"],
|
| 168 |
+
"resources": resources,
|
| 169 |
+
"catalogs": catalogs,
|
| 170 |
+
"idPrefixes": ["tt"],
|
| 171 |
"behaviorHints": {
|
| 172 |
"configurable": False,
|
| 173 |
"configurationRequired": False
|
|
|
|
| 178 |
@router.get("/catalog/{media_type}/{id}/{extra:path}.json")
|
| 179 |
@router.get("/catalog/{media_type}/{id}.json")
|
| 180 |
async def get_catalog(media_type: str, id: str, extra: Optional[str] = None):
|
| 181 |
+
if Telegram.HIDE_CATALOG:
|
| 182 |
+
raise HTTPException(status_code=404, detail="Catalog disabled")
|
| 183 |
+
|
| 184 |
if media_type not in ["movie", "series"]:
|
| 185 |
raise HTTPException(status_code=404, detail="Invalid catalog type")
|
| 186 |
|
|
|
|
| 232 |
|
| 233 |
@router.get("/meta/{media_type}/{id}.json")
|
| 234 |
async def get_meta(media_type: str, id: str):
|
| 235 |
+
if Telegram.HIDE_CATALOG:
|
| 236 |
+
raise HTTPException(status_code=404, detail="Meta disabled")
|
| 237 |
try:
|
| 238 |
+
imdb_id = id
|
|
|
|
| 239 |
except (ValueError, IndexError):
|
| 240 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 241 |
|
| 242 |
+
media = await db.get_media_details(imdb_id=imdb_id)
|
| 243 |
if not media:
|
| 244 |
return {"meta": {}}
|
| 245 |
|
|
|
|
| 255 |
"logo": media.get("logo", ""),
|
| 256 |
"background": media.get("backdrop", ""),
|
| 257 |
"imdb_id": media.get("imdb_id", ""),
|
| 258 |
+
"releaseInfo": str(media.get("release_year", "")),
|
| 259 |
"moviedb_id": media.get("tmdb_id", ""),
|
| 260 |
"cast": media.get("cast") or [],
|
| 261 |
"runtime": media.get("runtime") or "",
|
|
|
|
| 262 |
}
|
| 263 |
|
| 264 |
+
if media.get("media_type") == "movie":
|
| 265 |
+
released_date = format_released_date(media)
|
| 266 |
+
if released_date:
|
| 267 |
+
meta_obj["released"] = released_date
|
| 268 |
+
|
| 269 |
# --- Add Episodes ---
|
| 270 |
if media_type == "series" and "seasons" in media:
|
| 271 |
|
|
|
|
| 292 |
meta_obj["videos"] = videos
|
| 293 |
return {"meta": meta_obj}
|
| 294 |
|
|
|
|
| 295 |
@router.get("/stream/{media_type}/{id}.json")
|
| 296 |
async def get_streams(media_type: str, id: str):
|
| 297 |
try:
|
| 298 |
parts = id.split(":")
|
| 299 |
+
imdb_id = parts[0]
|
| 300 |
season_num = int(parts[1]) if len(parts) > 1 else None
|
| 301 |
episode_num = int(parts[2]) if len(parts) > 2 else None
|
|
|
|
|
|
|
| 302 |
|
| 303 |
except (ValueError, IndexError):
|
| 304 |
raise HTTPException(status_code=400, detail="Invalid Stremio ID format")
|
| 305 |
|
| 306 |
media_details = await db.get_media_details(
|
| 307 |
+
imdb_id=imdb_id,
|
|
|
|
| 308 |
season_number=season_num,
|
| 309 |
episode_number=episode_num
|
| 310 |
)
|
Backend/helper/database.py
CHANGED
|
@@ -9,7 +9,7 @@ from typing import Dict, List, Optional, Tuple, Any
|
|
| 9 |
from Backend.logger import LOGGER
|
| 10 |
from Backend.config import Telegram
|
| 11 |
import re
|
| 12 |
-
from Backend.helper.encrypt import decode_string
|
| 13 |
from Backend.helper.modal import Episode, MovieSchema, QualityDetail, Season, TVShowSchema
|
| 14 |
from Backend.helper.task_manager import delete_message
|
| 15 |
|
|
@@ -142,8 +142,6 @@ class Database:
|
|
| 142 |
|
| 143 |
return results, dbs_checked, total_count
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
async def _move_document(
|
| 148 |
self, collection_name: str, document: dict, old_db_index: int
|
| 149 |
) -> bool:
|
|
@@ -169,7 +167,6 @@ class Database:
|
|
| 169 |
LOGGER.info(f"Switched to storage_{self.current_db_index}")
|
| 170 |
return await func(*args)
|
| 171 |
|
| 172 |
-
|
| 173 |
# -------------------------------
|
| 174 |
# Multi Database Method for insert/update/delete/list
|
| 175 |
# -------------------------------
|
|
@@ -297,7 +294,6 @@ class Database:
|
|
| 297 |
existing_qualities = existing_movie.get("telegram", [])
|
| 298 |
|
| 299 |
if Telegram.REPLACE_MODE:
|
| 300 |
-
# delete all same-quality entries
|
| 301 |
to_delete = [q for q in existing_qualities if q.get("quality") == target_quality]
|
| 302 |
|
| 303 |
for q in to_delete:
|
|
@@ -498,8 +494,6 @@ class Database:
|
|
| 498 |
"tv_shows": [convert_objectid_to_str(result) for result in results],
|
| 499 |
}
|
| 500 |
|
| 501 |
-
|
| 502 |
-
|
| 503 |
async def search_documents(
|
| 504 |
self,
|
| 505 |
query: str,
|
|
@@ -590,63 +584,68 @@ class Database:
|
|
| 590 |
|
| 591 |
|
| 592 |
async def get_media_details(
|
| 593 |
-
self,
|
| 594 |
-
|
|
|
|
|
|
|
| 595 |
) -> Optional[dict]:
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
if
|
| 603 |
-
for
|
| 604 |
-
if
|
| 605 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
details.update({
|
| 607 |
-
"
|
| 608 |
"type": "tv",
|
| 609 |
"season_number": season_number,
|
| 610 |
-
"
|
| 611 |
-
"backdrop": episode.get("episode_backdrop")
|
| 612 |
})
|
| 613 |
return details
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
return
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
else:
|
| 632 |
-
tv_doc = await self.dbs[db_key]["tv"].find_one({"tmdb_id": tmdb_id})
|
| 633 |
-
if tv_doc:
|
| 634 |
-
tv_doc = convert_objectid_to_str(tv_doc)
|
| 635 |
-
tv_doc["type"] = "tv"
|
| 636 |
-
return tv_doc
|
| 637 |
-
movie_doc = await self.dbs[db_key]["movie"].find_one({"tmdb_id": tmdb_id})
|
| 638 |
-
if movie_doc:
|
| 639 |
-
movie_doc = convert_objectid_to_str(movie_doc)
|
| 640 |
-
movie_doc["type"] = "movie"
|
| 641 |
-
return movie_doc
|
| 642 |
-
return None
|
| 643 |
-
|
| 644 |
|
| 645 |
# -------------------------------
|
| 646 |
# DB Method for Edit Post
|
| 647 |
# -------------------------------
|
| 648 |
|
| 649 |
-
|
| 650 |
async def get_document(self, media_type: str, tmdb_id: int, db_index: int) -> Optional[Dict[str, Any]]:
|
| 651 |
db_key = f"storage_{db_index}"
|
| 652 |
if media_type.lower() in ["tv", "series"]:
|
|
|
|
| 9 |
from Backend.logger import LOGGER
|
| 10 |
from Backend.config import Telegram
|
| 11 |
import re
|
| 12 |
+
from Backend.helper.encrypt import decode_string
|
| 13 |
from Backend.helper.modal import Episode, MovieSchema, QualityDetail, Season, TVShowSchema
|
| 14 |
from Backend.helper.task_manager import delete_message
|
| 15 |
|
|
|
|
| 142 |
|
| 143 |
return results, dbs_checked, total_count
|
| 144 |
|
|
|
|
|
|
|
| 145 |
async def _move_document(
|
| 146 |
self, collection_name: str, document: dict, old_db_index: int
|
| 147 |
) -> bool:
|
|
|
|
| 167 |
LOGGER.info(f"Switched to storage_{self.current_db_index}")
|
| 168 |
return await func(*args)
|
| 169 |
|
|
|
|
| 170 |
# -------------------------------
|
| 171 |
# Multi Database Method for insert/update/delete/list
|
| 172 |
# -------------------------------
|
|
|
|
| 294 |
existing_qualities = existing_movie.get("telegram", [])
|
| 295 |
|
| 296 |
if Telegram.REPLACE_MODE:
|
|
|
|
| 297 |
to_delete = [q for q in existing_qualities if q.get("quality") == target_quality]
|
| 298 |
|
| 299 |
for q in to_delete:
|
|
|
|
| 494 |
"tv_shows": [convert_objectid_to_str(result) for result in results],
|
| 495 |
}
|
| 496 |
|
|
|
|
|
|
|
| 497 |
async def search_documents(
|
| 498 |
self,
|
| 499 |
query: str,
|
|
|
|
| 584 |
|
| 585 |
|
| 586 |
async def get_media_details(
|
| 587 |
+
self,
|
| 588 |
+
imdb_id: str,
|
| 589 |
+
season_number: Optional[int] = None,
|
| 590 |
+
episode_number: Optional[int] = None
|
| 591 |
) -> Optional[dict]:
|
| 592 |
+
|
| 593 |
+
for db_idx in range(self.current_db_index, 0, -1):
|
| 594 |
+
db_key = f"storage_{db_idx}"
|
| 595 |
+
|
| 596 |
+
if episode_number is not None and season_number is not None:
|
| 597 |
+
tv_show = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
|
| 598 |
+
if tv_show:
|
| 599 |
+
for season in tv_show.get("seasons", []):
|
| 600 |
+
if season.get("season_number") == season_number:
|
| 601 |
+
for episode in season.get("episodes", []):
|
| 602 |
+
if episode.get("episode_number") == episode_number:
|
| 603 |
+
details = convert_objectid_to_str(episode)
|
| 604 |
+
details.update({
|
| 605 |
+
"imdb_id": imdb_id,
|
| 606 |
+
"type": "tv",
|
| 607 |
+
"season_number": season_number,
|
| 608 |
+
"episode_number": episode_number,
|
| 609 |
+
"backdrop": episode.get("episode_backdrop"),
|
| 610 |
+
"db_index": db_idx
|
| 611 |
+
})
|
| 612 |
+
return details
|
| 613 |
+
|
| 614 |
+
elif season_number is not None:
|
| 615 |
+
tv_show = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
|
| 616 |
+
if tv_show:
|
| 617 |
+
for season in tv_show.get("seasons", []):
|
| 618 |
+
if season.get("season_number") == season_number:
|
| 619 |
+
details = convert_objectid_to_str(season)
|
| 620 |
details.update({
|
| 621 |
+
"imdb_id": imdb_id,
|
| 622 |
"type": "tv",
|
| 623 |
"season_number": season_number,
|
| 624 |
+
"db_index": db_idx
|
|
|
|
| 625 |
})
|
| 626 |
return details
|
| 627 |
+
|
| 628 |
+
else:
|
| 629 |
+
tv_doc = await self.dbs[db_key]["tv"].find_one({"imdb_id": imdb_id})
|
| 630 |
+
if tv_doc:
|
| 631 |
+
tv_doc = convert_objectid_to_str(tv_doc)
|
| 632 |
+
tv_doc["type"] = "tv"
|
| 633 |
+
tv_doc["db_index"] = db_idx
|
| 634 |
+
return tv_doc
|
| 635 |
+
|
| 636 |
+
movie_doc = await self.dbs[db_key]["movie"].find_one({"imdb_id": imdb_id})
|
| 637 |
+
if movie_doc:
|
| 638 |
+
movie_doc = convert_objectid_to_str(movie_doc)
|
| 639 |
+
movie_doc["type"] = "movie"
|
| 640 |
+
movie_doc["db_index"] = db_idx
|
| 641 |
+
return movie_doc
|
| 642 |
+
|
| 643 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
|
| 645 |
# -------------------------------
|
| 646 |
# DB Method for Edit Post
|
| 647 |
# -------------------------------
|
| 648 |
|
|
|
|
| 649 |
async def get_document(self, media_type: str, tmdb_id: int, db_index: int) -> Optional[Dict[str, Any]]:
|
| 650 |
db_key = f"storage_{db_index}"
|
| 651 |
if media_type.lower() in ["tv", "series"]:
|
Backend/helper/imdb.py
CHANGED
|
@@ -8,7 +8,6 @@ BASE_URL = "https://v3-cinemeta.strem.io"
|
|
| 8 |
_client: Optional[httpx.AsyncClient] = None
|
| 9 |
_client_lock = asyncio.Lock()
|
| 10 |
|
| 11 |
-
|
| 12 |
async def _get_client() -> httpx.AsyncClient:
|
| 13 |
global _client
|
| 14 |
async with _client_lock:
|
|
@@ -19,7 +18,6 @@ async def _get_client() -> httpx.AsyncClient:
|
|
| 19 |
)
|
| 20 |
return _client
|
| 21 |
|
| 22 |
-
|
| 23 |
def extract_first_year(year_string) -> int:
|
| 24 |
if not year_string:
|
| 25 |
return 0
|
|
@@ -29,12 +27,7 @@ def extract_first_year(year_string) -> int:
|
|
| 29 |
return int(year_match.group(1))
|
| 30 |
return 0
|
| 31 |
|
| 32 |
-
|
| 33 |
async def search_title(query: str, type: str) -> Optional[Dict[str, Any]]:
|
| 34 |
-
"""
|
| 35 |
-
Query Cinemeta search endpoint for a title.
|
| 36 |
-
type = 'tvSeries' or 'movie' (your code uses 'tvSeries' for TV)
|
| 37 |
-
"""
|
| 38 |
client = await _get_client()
|
| 39 |
cinemeta_type = "series" if type == "tvSeries" else type
|
| 40 |
url = f"{BASE_URL}/catalog/{cinemeta_type}/imdb/search={query}.json"
|
|
@@ -56,7 +49,6 @@ async def search_title(query: str, type: str) -> Optional[Dict[str, Any]]:
|
|
| 56 |
except Exception:
|
| 57 |
return None
|
| 58 |
|
| 59 |
-
|
| 60 |
async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
| 61 |
client = await _get_client()
|
| 62 |
cinemeta_type = "series" if media_type in ["tvSeries", "tv"] else "movie"
|
|
@@ -73,7 +65,6 @@ async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
|
| 73 |
if not meta:
|
| 74 |
return None
|
| 75 |
|
| 76 |
-
# ---- Extract year ----
|
| 77 |
year_value = 0
|
| 78 |
for field in ["year", "releaseInfo", "released"]:
|
| 79 |
if meta.get(field):
|
|
@@ -102,11 +93,7 @@ async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
|
| 102 |
except Exception:
|
| 103 |
return None
|
| 104 |
|
| 105 |
-
|
| 106 |
async def get_season(imdb_id: str, season_id: int, episode_id: int) -> Optional[Dict[str, Any]]:
|
| 107 |
-
"""
|
| 108 |
-
Return episode meta for a specific season/episode using Cinemeta series endpoint.
|
| 109 |
-
"""
|
| 110 |
client = await _get_client()
|
| 111 |
try:
|
| 112 |
url = f"{BASE_URL}/meta/series/{imdb_id}.json"
|
|
@@ -128,4 +115,4 @@ async def get_season(imdb_id: str, season_id: int, episode_id: int) -> Optional[
|
|
| 128 |
}
|
| 129 |
return None
|
| 130 |
except Exception:
|
| 131 |
-
return None
|
|
|
|
| 8 |
_client: Optional[httpx.AsyncClient] = None
|
| 9 |
_client_lock = asyncio.Lock()
|
| 10 |
|
|
|
|
| 11 |
async def _get_client() -> httpx.AsyncClient:
|
| 12 |
global _client
|
| 13 |
async with _client_lock:
|
|
|
|
| 18 |
)
|
| 19 |
return _client
|
| 20 |
|
|
|
|
| 21 |
def extract_first_year(year_string) -> int:
|
| 22 |
if not year_string:
|
| 23 |
return 0
|
|
|
|
| 27 |
return int(year_match.group(1))
|
| 28 |
return 0
|
| 29 |
|
|
|
|
| 30 |
async def search_title(query: str, type: str) -> Optional[Dict[str, Any]]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
client = await _get_client()
|
| 32 |
cinemeta_type = "series" if type == "tvSeries" else type
|
| 33 |
url = f"{BASE_URL}/catalog/{cinemeta_type}/imdb/search={query}.json"
|
|
|
|
| 49 |
except Exception:
|
| 50 |
return None
|
| 51 |
|
|
|
|
| 52 |
async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
| 53 |
client = await _get_client()
|
| 54 |
cinemeta_type = "series" if media_type in ["tvSeries", "tv"] else "movie"
|
|
|
|
| 65 |
if not meta:
|
| 66 |
return None
|
| 67 |
|
|
|
|
| 68 |
year_value = 0
|
| 69 |
for field in ["year", "releaseInfo", "released"]:
|
| 70 |
if meta.get(field):
|
|
|
|
| 93 |
except Exception:
|
| 94 |
return None
|
| 95 |
|
|
|
|
| 96 |
async def get_season(imdb_id: str, season_id: int, episode_id: int) -> Optional[Dict[str, Any]]:
|
|
|
|
|
|
|
|
|
|
| 97 |
client = await _get_client()
|
| 98 |
try:
|
| 99 |
url = f"{BASE_URL}/meta/series/{imdb_id}.json"
|
|
|
|
| 115 |
}
|
| 116 |
return None
|
| 117 |
except Exception:
|
| 118 |
+
return None
|
Backend/helper/metadata.py
CHANGED
|
@@ -165,6 +165,7 @@ async def metadata(filename: str, channel: int, msg_id) -> dict | None:
|
|
| 165 |
return None
|
| 166 |
|
| 167 |
# Skip split/multipart files
|
|
|
|
| 168 |
multipart_pattern = compile(r'(?:part|cd|disc|disk)[s._-]*\d+(?=\.\w+$)', IGNORECASE)
|
| 169 |
if multipart_pattern.search(filename):
|
| 170 |
LOGGER.info(f"Skipping {filename}: seems to be a split/multipart file")
|
|
@@ -400,10 +401,10 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 400 |
|
| 401 |
if default_id.startswith("tt"):
|
| 402 |
imdb_id = default_id
|
| 403 |
-
use_tmdb = False
|
| 404 |
elif default_id.isdigit():
|
| 405 |
tmdb_id = int(default_id)
|
| 406 |
-
use_tmdb = True
|
| 407 |
|
| 408 |
# -------------------------------------------------------
|
| 409 |
# 2. IF NO DEFAULT ID β SEARCH IMDb FIRST
|
|
@@ -516,4 +517,4 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 516 |
"genres": imdb.get("genre", []),
|
| 517 |
"quality": quality,
|
| 518 |
"encoded_string": encoded_string,
|
| 519 |
-
}
|
|
|
|
| 165 |
return None
|
| 166 |
|
| 167 |
# Skip split/multipart files
|
| 168 |
+
# if Telegram.SKIP_MULTIPART:
|
| 169 |
multipart_pattern = compile(r'(?:part|cd|disc|disk)[s._-]*\d+(?=\.\w+$)', IGNORECASE)
|
| 170 |
if multipart_pattern.search(filename):
|
| 171 |
LOGGER.info(f"Skipping {filename}: seems to be a split/multipart file")
|
|
|
|
| 401 |
|
| 402 |
if default_id.startswith("tt"):
|
| 403 |
imdb_id = default_id
|
| 404 |
+
use_tmdb = False
|
| 405 |
elif default_id.isdigit():
|
| 406 |
tmdb_id = int(default_id)
|
| 407 |
+
use_tmdb = True
|
| 408 |
|
| 409 |
# -------------------------------------------------------
|
| 410 |
# 2. IF NO DEFAULT ID β SEARCH IMDb FIRST
|
|
|
|
| 517 |
"genres": imdb.get("genre", []),
|
| 518 |
"quality": quality,
|
| 519 |
"encoded_string": encoded_string,
|
| 520 |
+
}
|
Backend/helper/pyro.py
CHANGED
|
@@ -145,7 +145,7 @@ async def restart_notification():
|
|
| 145 |
commands = [
|
| 146 |
BotCommand("start", "π Start the bot"),
|
| 147 |
BotCommand("set", "π¬ Manually add IMDb metadata"),
|
| 148 |
-
BotCommand("fixmetadata", "βοΈ Fix empty fields of Metadata"),
|
| 149 |
BotCommand("log", "π Send the log file"),
|
| 150 |
BotCommand("restart", "β»οΈ Restart the bot"),
|
| 151 |
]
|
|
|
|
| 145 |
commands = [
|
| 146 |
BotCommand("start", "π Start the bot"),
|
| 147 |
BotCommand("set", "π¬ Manually add IMDb metadata"),
|
| 148 |
+
# BotCommand("fixmetadata", "βοΈ Fix empty fields of Metadata"),
|
| 149 |
BotCommand("log", "π Send the log file"),
|
| 150 |
BotCommand("restart", "β»οΈ Restart the bot"),
|
| 151 |
]
|
Backend/pyrofork/plugins/fix_metadata.py
CHANGED
|
@@ -43,7 +43,7 @@ async def cancel_fix(_, query):
|
|
| 43 |
# -------------------------------
|
| 44 |
# MAIN COMMAND (REWRITTEN - Balanced)
|
| 45 |
# -------------------------------
|
| 46 |
-
@Client.on_message(filters.command("fixmetadata") & filters.private & CustomFilters.owner, group=10)
|
| 47 |
async def fix_metadata_handler(_, message):
|
| 48 |
global CANCEL_REQUESTED
|
| 49 |
CANCEL_REQUESTED = False
|
|
|
|
| 43 |
# -------------------------------
|
| 44 |
# MAIN COMMAND (REWRITTEN - Balanced)
|
| 45 |
# -------------------------------
|
| 46 |
+
# @Client.on_message(filters.command("fixmetadata") & filters.private & CustomFilters.owner, group=10)
|
| 47 |
async def fix_metadata_handler(_, message):
|
| 48 |
global CANCEL_REQUESTED
|
| 49 |
CANCEL_REQUESTED = False
|
README.md
CHANGED
|
@@ -218,6 +218,7 @@ All environment variables for this project are defined in the `config.env` file.
|
|
| 218 |
| **`HELPER_BOT_TOKEN`** | **Secondary bot token** used to assist the main bot with tasks like deleting, editing, or managing. |
|
| 219 |
| **`OWNER_ID`** | Your **Telegram user ID**. This ID has full administrative access. |
|
| 220 |
| **`REPLACE_MODE`** | When `true`, new files replace existing files of the same quality. When `false`, multiple files of the same quality are allowed. |
|
|
|
|
| 221 |
|
| 222 |
### ποΈ Storage
|
| 223 |
|
|
|
|
| 218 |
| **`HELPER_BOT_TOKEN`** | **Secondary bot token** used to assist the main bot with tasks like deleting, editing, or managing. |
|
| 219 |
| **`OWNER_ID`** | Your **Telegram user ID**. This ID has full administrative access. |
|
| 220 |
| **`REPLACE_MODE`** | When `true`, new files replace existing files of the same quality. When `false`, multiple files of the same quality are allowed. |
|
| 221 |
+
| **`HIDE_CATALOG`** | When `true`, the default Telegram Stremio Catalog is hidden, and streams only show in the Cinemata catalog (i.e., Cinemata addon is mandatory). Default is `false`. |
|
| 222 |
|
| 223 |
### ποΈ Storage
|
| 224 |
|
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.6.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"
|
sample_config.env
CHANGED
|
@@ -5,6 +5,7 @@ BOT_TOKEN = ""
|
|
| 5 |
HELPER_BOT_TOKEN = ""
|
| 6 |
OWNER_ID = ""
|
| 7 |
REPLACE_MODE = "true"
|
|
|
|
| 8 |
|
| 9 |
# STORAGE
|
| 10 |
AUTH_CHANNEL = ""
|
|
|
|
| 5 |
HELPER_BOT_TOKEN = ""
|
| 6 |
OWNER_ID = ""
|
| 7 |
REPLACE_MODE = "true"
|
| 8 |
+
HIDE_CATALOG = "false"
|
| 9 |
|
| 10 |
# STORAGE
|
| 11 |
AUTH_CHANNEL = ""
|
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.5.0"
|
| 905 |
source = { virtual = "." }
|
| 906 |
dependencies = [
|
| 907 |
{ name = "aiofiles" },
|