Karan Adhikari commited on
Release: v2.2.0 ✨ add metadata rescan UI for mismatched media entries
Browse files- Backend/__init__.py +1 -1
- Backend/fastapi/main.py +23 -1
- Backend/fastapi/routes/api_routes.py +64 -0
- Backend/fastapi/templates/media_edit.html +248 -0
- Backend/helper/database.py +65 -0
- Backend/helper/metadata.py +256 -1
- pyproject.toml +1 -1
Backend/__init__.py
CHANGED
|
@@ -11,4 +11,4 @@ StartTime = time()
|
|
| 11 |
USE_DEFAULT_ID: str = None
|
| 12 |
db = Database()
|
| 13 |
|
| 14 |
-
__version__ = "2.
|
|
|
|
| 11 |
USE_DEFAULT_ID: str = None
|
| 12 |
db = Database()
|
| 13 |
|
| 14 |
+
__version__ = "2.2.0"
|
Backend/fastapi/main.py
CHANGED
|
@@ -23,7 +23,8 @@ from Backend.fastapi.routes.api_routes import (
|
|
| 23 |
get_subscription_plans_api, add_subscription_plan_api,
|
| 24 |
update_subscription_plan_api, delete_subscription_plan_api,
|
| 25 |
get_all_subscribers_api, manage_subscriber_api,
|
| 26 |
-
get_all_tokens_api, assign_plan_api, link_token_user_api
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
app = FastAPI(
|
|
@@ -259,6 +260,27 @@ async def speed_test_stream(
|
|
| 259 |
):
|
| 260 |
return await speed_test_stream_api(quality_id, tmdb_id, db_index, media_type)
|
| 261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
@app.exception_handler(401)
|
| 263 |
async def auth_exception_handler(request: Request, exc):
|
| 264 |
return RedirectResponse(url="/login", status_code=302)
|
|
|
|
| 23 |
get_subscription_plans_api, add_subscription_plan_api,
|
| 24 |
update_subscription_plan_api, delete_subscription_plan_api,
|
| 25 |
get_all_subscribers_api, manage_subscriber_api,
|
| 26 |
+
get_all_tokens_api, assign_plan_api, link_token_user_api,
|
| 27 |
+
search_media_rescan_api, apply_media_rescan_api
|
| 28 |
)
|
| 29 |
|
| 30 |
app = FastAPI(
|
|
|
|
| 260 |
):
|
| 261 |
return await speed_test_stream_api(quality_id, tmdb_id, db_index, media_type)
|
| 262 |
|
| 263 |
+
|
| 264 |
+
@app.get("/api/media/rescan/search")
|
| 265 |
+
async def search_media_rescan(
|
| 266 |
+
media_type: str,
|
| 267 |
+
query: str,
|
| 268 |
+
year: int | None = None,
|
| 269 |
+
_: bool = Depends(require_auth)
|
| 270 |
+
):
|
| 271 |
+
return await search_media_rescan_api(media_type, query, year)
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
@app.post("/api/media/rescan/apply")
|
| 275 |
+
async def apply_media_rescan(
|
| 276 |
+
request: Request,
|
| 277 |
+
tmdb_id: int,
|
| 278 |
+
db_index: int,
|
| 279 |
+
media_type: str,
|
| 280 |
+
_: bool = Depends(require_auth)
|
| 281 |
+
):
|
| 282 |
+
return await apply_media_rescan_api(request, tmdb_id, db_index, media_type)
|
| 283 |
+
|
| 284 |
@app.exception_handler(401)
|
| 285 |
async def auth_exception_handler(request: Request, exc):
|
| 286 |
return RedirectResponse(url="/login", status_code=302)
|
Backend/fastapi/routes/api_routes.py
CHANGED
|
@@ -5,6 +5,12 @@ from fastapi.responses import StreamingResponse
|
|
| 5 |
from Backend import db, StartTime, __version__
|
| 6 |
from Backend.logger import LOGGER
|
| 7 |
from Backend.helper.pyro import get_readable_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from Backend.pyrofork.bot import multi_clients, StreamBot
|
| 9 |
from Backend.helper.custom_dl import run_speed_test, _speed_test_single_client
|
| 10 |
from time import time
|
|
@@ -726,3 +732,61 @@ async def link_token_user_api(token: str, user_id: int) -> dict:
|
|
| 726 |
raise
|
| 727 |
except Exception as e:
|
| 728 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from Backend import db, StartTime, __version__
|
| 6 |
from Backend.logger import LOGGER
|
| 7 |
from Backend.helper.pyro import get_readable_time
|
| 8 |
+
from Backend.helper.metadata import (
|
| 9 |
+
search_movie_candidates,
|
| 10 |
+
search_tv_candidates,
|
| 11 |
+
fetch_selected_movie_metadata,
|
| 12 |
+
fetch_selected_tv_metadata,
|
| 13 |
+
)
|
| 14 |
from Backend.pyrofork.bot import multi_clients, StreamBot
|
| 15 |
from Backend.helper.custom_dl import run_speed_test, _speed_test_single_client
|
| 16 |
from time import time
|
|
|
|
| 732 |
raise
|
| 733 |
except Exception as e:
|
| 734 |
raise HTTPException(status_code=500, detail=str(e))
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
|
| 738 |
+
|
| 739 |
+
async def search_media_rescan_api(media_type: str, query: str, year: int | None = None):
|
| 740 |
+
query = (query or "").strip()
|
| 741 |
+
if not query:
|
| 742 |
+
raise HTTPException(status_code=400, detail="query is required.")
|
| 743 |
+
|
| 744 |
+
if media_type == "movie":
|
| 745 |
+
results = await search_movie_candidates(query=query, year=year)
|
| 746 |
+
elif media_type == "tv":
|
| 747 |
+
results = await search_tv_candidates(query=query)
|
| 748 |
+
else:
|
| 749 |
+
raise HTTPException(status_code=400, detail="Invalid media_type.")
|
| 750 |
+
|
| 751 |
+
return {"results": results}
|
| 752 |
+
|
| 753 |
+
|
| 754 |
+
async def apply_media_rescan_api(request: Request, tmdb_id: int, db_index: int, media_type: str):
|
| 755 |
+
body = await request.json()
|
| 756 |
+
selected_id = str(body.get("selected_id") or "").strip()
|
| 757 |
+
|
| 758 |
+
if not selected_id:
|
| 759 |
+
raise HTTPException(status_code=400, detail="selected_id is required.")
|
| 760 |
+
|
| 761 |
+
current_doc = await db.get_document(media_type, tmdb_id, db_index)
|
| 762 |
+
if not current_doc:
|
| 763 |
+
raise HTTPException(status_code=404, detail="Media not found.")
|
| 764 |
+
|
| 765 |
+
if media_type == "movie":
|
| 766 |
+
metadata = await fetch_selected_movie_metadata(selected_id)
|
| 767 |
+
elif media_type == "tv":
|
| 768 |
+
metadata = await fetch_selected_tv_metadata(selected_id)
|
| 769 |
+
else:
|
| 770 |
+
raise HTTPException(status_code=400, detail="Invalid media_type.")
|
| 771 |
+
|
| 772 |
+
if not metadata:
|
| 773 |
+
raise HTTPException(status_code=404, detail="Unable to fetch metadata for selected item.")
|
| 774 |
+
|
| 775 |
+
updated_doc = await db.replace_media_metadata(
|
| 776 |
+
media_type=media_type,
|
| 777 |
+
tmdb_id=tmdb_id,
|
| 778 |
+
db_index=db_index,
|
| 779 |
+
metadata=metadata,
|
| 780 |
+
)
|
| 781 |
+
|
| 782 |
+
if not updated_doc:
|
| 783 |
+
raise HTTPException(status_code=500, detail="Failed to replace media metadata.")
|
| 784 |
+
|
| 785 |
+
return {
|
| 786 |
+
"success": True,
|
| 787 |
+
"message": "Metadata rescanned successfully.",
|
| 788 |
+
"redirect_tmdb_id": updated_doc.get("tmdb_id"),
|
| 789 |
+
"db_index": updated_doc.get("db_index", db_index),
|
| 790 |
+
"media_type": media_type,
|
| 791 |
+
"data": updated_doc,
|
| 792 |
+
}
|
Backend/fastapi/templates/media_edit.html
CHANGED
|
@@ -174,6 +174,34 @@
|
|
| 174 |
overflow-wrap: anywhere;
|
| 175 |
}
|
| 176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
@keyframes spin {
|
| 178 |
to { transform: rotate(360deg); }
|
| 179 |
}
|
|
@@ -289,6 +317,55 @@
|
|
| 289 |
</div>
|
| 290 |
{% endif %}
|
| 291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
<div class="glass-card rounded-3xl p-5 sm:p-6 lg:p-8 mb-6 sm:mb-8">
|
| 293 |
<div class="flex items-center justify-between gap-3 mb-5 sm:mb-6">
|
| 294 |
<h3 class="section-title text-xl sm:text-2xl">Edit Details</h3>
|
|
@@ -554,6 +631,177 @@
|
|
| 554 |
const dbIndex = {{ db_index }};
|
| 555 |
const mediaType = '{{ media_type }}';
|
| 556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
function toggleSeason(seasonIndex) {
|
| 558 |
const content = document.getElementById(`season-content-${seasonIndex}`);
|
| 559 |
const arrow = document.getElementById(`season-arrow-${seasonIndex}`);
|
|
|
|
| 174 |
overflow-wrap: anywhere;
|
| 175 |
}
|
| 176 |
|
| 177 |
+
.match-card {
|
| 178 |
+
background: color-mix(in srgb, var(--bg) 72%, transparent);
|
| 179 |
+
border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
|
| 180 |
+
border-radius: 1.25rem;
|
| 181 |
+
padding: 1rem;
|
| 182 |
+
transition: all 0.2s ease;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
.match-card:hover {
|
| 186 |
+
transform: translateY(-2px);
|
| 187 |
+
border-color: color-mix(in srgb, var(--primary) 35%, transparent);
|
| 188 |
+
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.18);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.match-card.active {
|
| 192 |
+
border-color: var(--primary);
|
| 193 |
+
box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.match-thumb {
|
| 197 |
+
width: 4.75rem;
|
| 198 |
+
height: 7rem;
|
| 199 |
+
border-radius: 1rem;
|
| 200 |
+
object-fit: cover;
|
| 201 |
+
border: 1px solid rgba(255,255,255,0.08);
|
| 202 |
+
flex-shrink: 0;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
@keyframes spin {
|
| 206 |
to { transform: rotate(360deg); }
|
| 207 |
}
|
|
|
|
| 317 |
</div>
|
| 318 |
{% endif %}
|
| 319 |
|
| 320 |
+
{% if media_details %}
|
| 321 |
+
<div class="glass-card rounded-3xl p-5 sm:p-6 lg:p-8 mb-6 sm:mb-8">
|
| 322 |
+
<div class="flex flex-col lg:flex-row lg:items-end lg:justify-between gap-3 mb-5 sm:mb-6">
|
| 323 |
+
<div>
|
| 324 |
+
<h3 class="section-title text-xl sm:text-2xl">Rescan Metadata</h3>
|
| 325 |
+
<p class="muted mt-1 text-sm sm:text-base">
|
| 326 |
+
Use this only when the auto-detected {{ media_type }} is mismatched. Existing Telegram files will stay safe.
|
| 327 |
+
</p>
|
| 328 |
+
</div>
|
| 329 |
+
<span class="pill">IMDb / TMDb re-match</span>
|
| 330 |
+
</div>
|
| 331 |
+
|
| 332 |
+
<div class="grid grid-cols-1 lg:grid-cols-[1fr_auto] gap-3">
|
| 333 |
+
<input
|
| 334 |
+
id="rescan-query"
|
| 335 |
+
type="text"
|
| 336 |
+
class="field-input"
|
| 337 |
+
placeholder="Search correct {{ media_type }} title..."
|
| 338 |
+
value="{{ media_details.title if media_details else '' }}"
|
| 339 |
+
>
|
| 340 |
+
<button type="button" class="btn-ui btn-primary" onclick="searchRescanCandidates()">
|
| 341 |
+
🔎 Search Matches
|
| 342 |
+
</button>
|
| 343 |
+
</div>
|
| 344 |
+
|
| 345 |
+
<div id="rescan-state" class="muted text-sm mt-4 hidden"></div>
|
| 346 |
+
|
| 347 |
+
<div id="rescan-results" class="grid grid-cols-1 xl:grid-cols-2 gap-3 mt-4"></div>
|
| 348 |
+
|
| 349 |
+
<div id="rescan-preview" class="hidden mt-5 rounded-3xl border border-white/10 bg-white/5 p-4 sm:p-5">
|
| 350 |
+
<div class="flex items-start gap-4">
|
| 351 |
+
<img id="rescan-preview-poster" src="/static/placeholder.jpg" alt="Selected poster" class="match-thumb">
|
| 352 |
+
<div class="min-w-0 flex-1">
|
| 353 |
+
<h4 id="rescan-preview-title" class="text-white font-bold text-lg"></h4>
|
| 354 |
+
<p id="rescan-preview-subtitle" class="muted text-sm mt-1"></p>
|
| 355 |
+
<p id="rescan-preview-ids" class="muted text-xs mt-2 break-all"></p>
|
| 356 |
+
</div>
|
| 357 |
+
</div>
|
| 358 |
+
|
| 359 |
+
<div class="flex flex-col sm:flex-row justify-end gap-3 mt-5">
|
| 360 |
+
<button type="button" onclick="clearRescanSelection()" class="btn-ui btn-ghost">Cancel</button>
|
| 361 |
+
<button type="button" onclick="applyRescanSelection()" class="btn-ui btn-primary">
|
| 362 |
+
✨ Apply Selected Match
|
| 363 |
+
</button>
|
| 364 |
+
</div>
|
| 365 |
+
</div>
|
| 366 |
+
</div>
|
| 367 |
+
{% endif %}
|
| 368 |
+
|
| 369 |
<div class="glass-card rounded-3xl p-5 sm:p-6 lg:p-8 mb-6 sm:mb-8">
|
| 370 |
<div class="flex items-center justify-between gap-3 mb-5 sm:mb-6">
|
| 371 |
<h3 class="section-title text-xl sm:text-2xl">Edit Details</h3>
|
|
|
|
| 631 |
const dbIndex = {{ db_index }};
|
| 632 |
const mediaType = '{{ media_type }}';
|
| 633 |
|
| 634 |
+
let selectedRescanMatch = null;
|
| 635 |
+
let latestRescanResults = [];
|
| 636 |
+
|
| 637 |
+
function escapeHtml(value) {
|
| 638 |
+
return String(value ?? '')
|
| 639 |
+
.replaceAll('&', '&')
|
| 640 |
+
.replaceAll('<', '<')
|
| 641 |
+
.replaceAll('>', '>')
|
| 642 |
+
.replaceAll('"', '"')
|
| 643 |
+
.replaceAll("'", ''');
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
function setRescanState(message = '', visible = false) {
|
| 647 |
+
const el = document.getElementById('rescan-state');
|
| 648 |
+
if (!el) return;
|
| 649 |
+
el.textContent = message;
|
| 650 |
+
el.classList.toggle('hidden', !visible);
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
function clearRescanSelection() {
|
| 654 |
+
selectedRescanMatch = null;
|
| 655 |
+
document.querySelectorAll('.match-card').forEach(card => card.classList.remove('active'));
|
| 656 |
+
const preview = document.getElementById('rescan-preview');
|
| 657 |
+
if (preview) preview.classList.add('hidden');
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
function selectRescanMatch(index) {
|
| 661 |
+
const item = latestRescanResults[index];
|
| 662 |
+
if (!item) return;
|
| 663 |
+
|
| 664 |
+
selectedRescanMatch = item;
|
| 665 |
+
document.querySelectorAll('.match-card').forEach(card => card.classList.remove('active'));
|
| 666 |
+
const activeCard = document.getElementById(`match-card-${index}`);
|
| 667 |
+
if (activeCard) activeCard.classList.add('active');
|
| 668 |
+
|
| 669 |
+
document.getElementById('rescan-preview-title').textContent = item.title || 'Unknown title';
|
| 670 |
+
document.getElementById('rescan-preview-subtitle').textContent = `${item.subtitle || 'Match'}${item.year ? ` • ${item.year}` : ''}`;
|
| 671 |
+
document.getElementById('rescan-preview-ids').textContent = `IMDb: ${item.imdb_id || 'N/A'} • TMDb: ${item.tmdb_id || 'N/A'}`;
|
| 672 |
+
document.getElementById('rescan-preview-poster').src = item.poster || '/static/placeholder.jpg';
|
| 673 |
+
document.getElementById('rescan-preview').classList.remove('hidden');
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
async function searchRescanCandidates() {
|
| 677 |
+
const query = document.getElementById('rescan-query').value.trim();
|
| 678 |
+
const resultsEl = document.getElementById('rescan-results');
|
| 679 |
+
|
| 680 |
+
if (!query) {
|
| 681 |
+
showErrorMessage('Please enter a title to search.');
|
| 682 |
+
return;
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
clearRescanSelection();
|
| 686 |
+
latestRescanResults = [];
|
| 687 |
+
resultsEl.innerHTML = '';
|
| 688 |
+
setRescanState('Searching matches...', true);
|
| 689 |
+
|
| 690 |
+
try {
|
| 691 |
+
const params = new URLSearchParams({
|
| 692 |
+
media_type: mediaType,
|
| 693 |
+
query
|
| 694 |
+
});
|
| 695 |
+
|
| 696 |
+
const yearValue = document.getElementById('release_year')?.value;
|
| 697 |
+
if (yearValue) {
|
| 698 |
+
params.set('year', yearValue);
|
| 699 |
+
}
|
| 700 |
+
|
| 701 |
+
const response = await fetch(`/api/media/rescan/search?${params.toString()}`);
|
| 702 |
+
const data = await response.json().catch(() => ({}));
|
| 703 |
+
|
| 704 |
+
if (!response.ok) {
|
| 705 |
+
setRescanState('', false);
|
| 706 |
+
showErrorMessage(data.detail || 'Failed to search matches.');
|
| 707 |
+
return;
|
| 708 |
+
}
|
| 709 |
+
|
| 710 |
+
const results = data.results || [];
|
| 711 |
+
latestRescanResults = results;
|
| 712 |
+
|
| 713 |
+
if (!results.length) {
|
| 714 |
+
setRescanState('No matches found.', true);
|
| 715 |
+
return;
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
setRescanState(`Found ${results.length} match${results.length > 1 ? 'es' : ''}. Select one below.`, true);
|
| 719 |
+
|
| 720 |
+
resultsEl.innerHTML = results.map((item, index) => `
|
| 721 |
+
<button
|
| 722 |
+
type="button"
|
| 723 |
+
id="match-card-${index}"
|
| 724 |
+
class="match-card text-left w-full"
|
| 725 |
+
data-index="${index}"
|
| 726 |
+
>
|
| 727 |
+
<div class="flex items-start gap-4">
|
| 728 |
+
<img
|
| 729 |
+
src="${item.poster || '/static/placeholder.jpg'}"
|
| 730 |
+
alt="${escapeHtml(item.title || 'Poster')}"
|
| 731 |
+
class="match-thumb"
|
| 732 |
+
onerror="this.src='/static/placeholder.jpg'"
|
| 733 |
+
>
|
| 734 |
+
<div class="min-w-0 flex-1">
|
| 735 |
+
<div class="flex flex-wrap items-center gap-2">
|
| 736 |
+
<h4 class="text-white font-bold text-base sm:text-lg">${escapeHtml(item.title || 'Unknown title')}</h4>
|
| 737 |
+
<span class="pill">${escapeHtml(item.year || '—')}</span>
|
| 738 |
+
</div>
|
| 739 |
+
<p class="muted text-sm mt-2">${escapeHtml(item.subtitle || '')}</p>
|
| 740 |
+
<p class="muted text-xs mt-2 break-all">
|
| 741 |
+
IMDb: ${escapeHtml(item.imdb_id || 'N/A')} · TMDb: ${escapeHtml(item.tmdb_id || 'N/A')}
|
| 742 |
+
</p>
|
| 743 |
+
</div>
|
| 744 |
+
</div>
|
| 745 |
+
</button>
|
| 746 |
+
`).join('');
|
| 747 |
+
|
| 748 |
+
document.querySelectorAll('#rescan-results .match-card').forEach((card) => {
|
| 749 |
+
card.addEventListener('click', () => {
|
| 750 |
+
const index = Number(card.dataset.index);
|
| 751 |
+
selectRescanMatch(index);
|
| 752 |
+
});
|
| 753 |
+
});
|
| 754 |
+
} catch (error) {
|
| 755 |
+
console.error('Rescan search failed:', error);
|
| 756 |
+
setRescanState('', false);
|
| 757 |
+
showErrorMessage('Failed to search matches. Please try again.');
|
| 758 |
+
}
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
async function applyRescanSelection() {
|
| 762 |
+
if (!selectedRescanMatch) {
|
| 763 |
+
showErrorMessage('Please select a match first.');
|
| 764 |
+
return;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
const selectedId = selectedRescanMatch.imdb_id || selectedRescanMatch.tmdb_id;
|
| 768 |
+
if (!selectedId) {
|
| 769 |
+
showErrorMessage('Selected match does not contain a valid IMDb/TMDb id.');
|
| 770 |
+
return;
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
if (!confirm(`Replace current metadata with "${selectedRescanMatch.title}"?\n\nExisting Telegram files will stay safe.`)) {
|
| 774 |
+
return;
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
try {
|
| 778 |
+
const response = await fetch(`/api/media/rescan/apply?tmdb_id=${tmdbId}&db_index=${dbIndex}&media_type=${mediaType}`, {
|
| 779 |
+
method: 'POST',
|
| 780 |
+
headers: { 'Content-Type': 'application/json' },
|
| 781 |
+
body: JSON.stringify({ selected_id: String(selectedId) })
|
| 782 |
+
});
|
| 783 |
+
|
| 784 |
+
const data = await response.json().catch(() => ({}));
|
| 785 |
+
|
| 786 |
+
if (!response.ok) {
|
| 787 |
+
showErrorMessage(data.detail || 'Failed to apply selected metadata.');
|
| 788 |
+
return;
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
showSuccessMessage(data.message || 'Metadata rescanned successfully.');
|
| 792 |
+
|
| 793 |
+
const newTmdbId = data.redirect_tmdb_id || tmdbId;
|
| 794 |
+
const newDbIndex = data.db_index || dbIndex;
|
| 795 |
+
|
| 796 |
+
setTimeout(() => {
|
| 797 |
+
window.location.href = `/media/edit?tmdb_id=${newTmdbId}&db_index=${newDbIndex}&media_type=${mediaType}`;
|
| 798 |
+
}, 700);
|
| 799 |
+
} catch (error) {
|
| 800 |
+
console.error('Apply rescan failed:', error);
|
| 801 |
+
showErrorMessage('Failed to apply selected metadata. Please try again.');
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
function toggleSeason(seasonIndex) {
|
| 806 |
const content = document.getElementById(`season-content-${seasonIndex}`);
|
| 807 |
const arrow = document.getElementById(`season-arrow-${seasonIndex}`);
|
Backend/helper/database.py
CHANGED
|
@@ -1467,3 +1467,68 @@ class Database:
|
|
| 1467 |
except Exception as e:
|
| 1468 |
LOGGER.error(f"get_stream_analytics error: {e}")
|
| 1469 |
return {"summary": {}, "per_client": [], "recent": []}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1467 |
except Exception as e:
|
| 1468 |
LOGGER.error(f"get_stream_analytics error: {e}")
|
| 1469 |
return {"summary": {}, "per_client": [], "recent": []}
|
| 1470 |
+
|
| 1471 |
+
|
| 1472 |
+
|
| 1473 |
+
async def replace_media_metadata(
|
| 1474 |
+
self,
|
| 1475 |
+
media_type: str,
|
| 1476 |
+
tmdb_id: int,
|
| 1477 |
+
db_index: int,
|
| 1478 |
+
metadata: Dict[str, Any]
|
| 1479 |
+
) -> Optional[dict]:
|
| 1480 |
+
db_key = f"storage_{db_index}"
|
| 1481 |
+
collection_name = "tv" if media_type.lower() in ["tv", "series"] else "movie"
|
| 1482 |
+
collection = self.dbs[db_key][collection_name]
|
| 1483 |
+
|
| 1484 |
+
current_doc = await collection.find_one({"tmdb_id": int(tmdb_id)})
|
| 1485 |
+
if not current_doc:
|
| 1486 |
+
return None
|
| 1487 |
+
|
| 1488 |
+
current_doc.pop("_id", None)
|
| 1489 |
+
|
| 1490 |
+
if collection_name == "movie":
|
| 1491 |
+
preserved_telegram = current_doc.get("telegram", [])
|
| 1492 |
+
current_doc.update({
|
| 1493 |
+
"tmdb_id": int(metadata.get("tmdb_id") or tmdb_id),
|
| 1494 |
+
"imdb_id": metadata.get("imdb_id"),
|
| 1495 |
+
"title": metadata.get("title") or current_doc.get("title"),
|
| 1496 |
+
"release_year": metadata.get("release_year", current_doc.get("release_year")),
|
| 1497 |
+
"rating": metadata.get("rating", current_doc.get("rating")),
|
| 1498 |
+
"description": metadata.get("description", current_doc.get("description")),
|
| 1499 |
+
"poster": metadata.get("poster", current_doc.get("poster")),
|
| 1500 |
+
"backdrop": metadata.get("backdrop", current_doc.get("backdrop")),
|
| 1501 |
+
"logo": metadata.get("logo", current_doc.get("logo")),
|
| 1502 |
+
"genres": metadata.get("genres", current_doc.get("genres", [])),
|
| 1503 |
+
"cast": metadata.get("cast", current_doc.get("cast", [])),
|
| 1504 |
+
"runtime": metadata.get("runtime", current_doc.get("runtime")),
|
| 1505 |
+
"media_type": "movie",
|
| 1506 |
+
"telegram": preserved_telegram,
|
| 1507 |
+
"updated_on": datetime.utcnow(),
|
| 1508 |
+
})
|
| 1509 |
+
else:
|
| 1510 |
+
preserved_seasons = current_doc.get("seasons", [])
|
| 1511 |
+
current_doc.update({
|
| 1512 |
+
"tmdb_id": int(metadata.get("tmdb_id") or tmdb_id) if metadata.get("tmdb_id") else int(tmdb_id),
|
| 1513 |
+
"imdb_id": metadata.get("imdb_id"),
|
| 1514 |
+
"title": metadata.get("title") or current_doc.get("title"),
|
| 1515 |
+
"release_year": metadata.get("release_year", current_doc.get("release_year")),
|
| 1516 |
+
"rating": metadata.get("rating", current_doc.get("rating")),
|
| 1517 |
+
"description": metadata.get("description", current_doc.get("description")),
|
| 1518 |
+
"poster": metadata.get("poster", current_doc.get("poster")),
|
| 1519 |
+
"backdrop": metadata.get("backdrop", current_doc.get("backdrop")),
|
| 1520 |
+
"logo": metadata.get("logo", current_doc.get("logo")),
|
| 1521 |
+
"genres": metadata.get("genres", current_doc.get("genres", [])),
|
| 1522 |
+
"cast": metadata.get("cast", current_doc.get("cast", [])),
|
| 1523 |
+
"runtime": metadata.get("runtime", current_doc.get("runtime")),
|
| 1524 |
+
"media_type": "tv",
|
| 1525 |
+
"seasons": preserved_seasons,
|
| 1526 |
+
"updated_on": datetime.utcnow(),
|
| 1527 |
+
})
|
| 1528 |
+
|
| 1529 |
+
new_tmdb_id = int(current_doc["tmdb_id"])
|
| 1530 |
+
await collection.delete_one({"tmdb_id": int(tmdb_id)})
|
| 1531 |
+
await collection.insert_one(current_doc)
|
| 1532 |
+
|
| 1533 |
+
updated_doc = await collection.find_one({"tmdb_id": new_tmdb_id})
|
| 1534 |
+
return convert_objectid_to_str(updated_doc) if updated_doc else None
|
Backend/helper/metadata.py
CHANGED
|
@@ -525,4 +525,259 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 525 |
"genres": imdb.get("genre", []),
|
| 526 |
"quality": quality,
|
| 527 |
"encoded_string": encoded_string,
|
| 528 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
"genres": imdb.get("genre", []),
|
| 526 |
"quality": quality,
|
| 527 |
"encoded_string": encoded_string,
|
| 528 |
+
}
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
async def search_movie_candidates(query: str, year: int | None = None, limit: int = 8) -> list[dict]:
|
| 532 |
+
query = (query or "").strip()
|
| 533 |
+
if not query:
|
| 534 |
+
return []
|
| 535 |
+
|
| 536 |
+
results: list[dict] = []
|
| 537 |
+
seen: set[tuple[str, str]] = set()
|
| 538 |
+
|
| 539 |
+
# IMDb/Cinemeta top result
|
| 540 |
+
try:
|
| 541 |
+
imdb_result = await search_title(query=query, type="movie")
|
| 542 |
+
if imdb_result and imdb_result.get("id"):
|
| 543 |
+
key = ("imdb", imdb_result["id"])
|
| 544 |
+
if key not in seen:
|
| 545 |
+
seen.add(key)
|
| 546 |
+
results.append({
|
| 547 |
+
"source": "imdb",
|
| 548 |
+
"title": imdb_result.get("title", ""),
|
| 549 |
+
"year": imdb_result.get("year", ""),
|
| 550 |
+
"imdb_id": imdb_result.get("id"),
|
| 551 |
+
"tmdb_id": imdb_result.get("moviedb_id"),
|
| 552 |
+
"poster": imdb_result.get("poster", ""),
|
| 553 |
+
"backdrop": "",
|
| 554 |
+
"subtitle": "IMDb / Cinemeta",
|
| 555 |
+
})
|
| 556 |
+
except Exception as e:
|
| 557 |
+
LOGGER.warning(f"IMDb movie candidate search failed for '{query}': {e}")
|
| 558 |
+
|
| 559 |
+
# TMDb multiple results
|
| 560 |
+
try:
|
| 561 |
+
async with API_SEMAPHORE:
|
| 562 |
+
tmdb_results = await tmdb.search().movies(query=query, year=year) if year else await tmdb.search().movies(query=query)
|
| 563 |
+
|
| 564 |
+
for item in (tmdb_results or [])[:limit]:
|
| 565 |
+
tmdb_id = getattr(item, "id", None)
|
| 566 |
+
if not tmdb_id:
|
| 567 |
+
continue
|
| 568 |
+
|
| 569 |
+
imdb_id = None
|
| 570 |
+
try:
|
| 571 |
+
details = await _tmdb_movie_details(tmdb_id)
|
| 572 |
+
ext = getattr(details, "external_ids", None) if details else None
|
| 573 |
+
imdb_id = getattr(ext, "imdb_id", None) if ext else None
|
| 574 |
+
except Exception:
|
| 575 |
+
pass
|
| 576 |
+
|
| 577 |
+
key = ("tmdb", str(tmdb_id))
|
| 578 |
+
if key in seen:
|
| 579 |
+
continue
|
| 580 |
+
seen.add(key)
|
| 581 |
+
|
| 582 |
+
release_date = getattr(item, "release_date", None)
|
| 583 |
+
year_value = getattr(release_date, "year", None) if release_date else None
|
| 584 |
+
|
| 585 |
+
results.append({
|
| 586 |
+
"source": "tmdb",
|
| 587 |
+
"title": getattr(item, "title", "") or "",
|
| 588 |
+
"year": year_value or "",
|
| 589 |
+
"imdb_id": imdb_id,
|
| 590 |
+
"tmdb_id": tmdb_id,
|
| 591 |
+
"poster": format_tmdb_image(getattr(item, "poster_path", None)),
|
| 592 |
+
"backdrop": format_tmdb_image(getattr(item, "backdrop_path", None), "original"),
|
| 593 |
+
"subtitle": "TMDb",
|
| 594 |
+
})
|
| 595 |
+
except Exception as e:
|
| 596 |
+
LOGGER.warning(f"TMDb movie candidate search failed for '{query}': {e}")
|
| 597 |
+
|
| 598 |
+
return results[:limit]
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
async def search_tv_candidates(query: str, limit: int = 8) -> list[dict]:
|
| 602 |
+
query = (query or "").strip()
|
| 603 |
+
if not query:
|
| 604 |
+
return []
|
| 605 |
+
|
| 606 |
+
results: list[dict] = []
|
| 607 |
+
seen: set[tuple[str, str]] = set()
|
| 608 |
+
|
| 609 |
+
# IMDb/Cinemeta top result
|
| 610 |
+
try:
|
| 611 |
+
imdb_result = await search_title(query=query, type="tvSeries")
|
| 612 |
+
if imdb_result and imdb_result.get("id"):
|
| 613 |
+
key = ("imdb", imdb_result["id"])
|
| 614 |
+
if key not in seen:
|
| 615 |
+
seen.add(key)
|
| 616 |
+
results.append({
|
| 617 |
+
"source": "imdb",
|
| 618 |
+
"title": imdb_result.get("title", ""),
|
| 619 |
+
"year": imdb_result.get("year", ""),
|
| 620 |
+
"imdb_id": imdb_result.get("id"),
|
| 621 |
+
"tmdb_id": imdb_result.get("moviedb_id"),
|
| 622 |
+
"poster": imdb_result.get("poster", ""),
|
| 623 |
+
"backdrop": "",
|
| 624 |
+
"subtitle": "IMDb / Cinemeta",
|
| 625 |
+
})
|
| 626 |
+
except Exception as e:
|
| 627 |
+
LOGGER.warning(f"IMDb TV candidate search failed for '{query}': {e}")
|
| 628 |
+
|
| 629 |
+
# TMDb multiple results
|
| 630 |
+
try:
|
| 631 |
+
async with API_SEMAPHORE:
|
| 632 |
+
tmdb_results = await tmdb.search().tv(query=query)
|
| 633 |
+
|
| 634 |
+
for item in (tmdb_results or [])[:limit]:
|
| 635 |
+
tmdb_id = getattr(item, "id", None)
|
| 636 |
+
if not tmdb_id:
|
| 637 |
+
continue
|
| 638 |
+
|
| 639 |
+
imdb_id = None
|
| 640 |
+
try:
|
| 641 |
+
details = await _tmdb_tv_details(tmdb_id)
|
| 642 |
+
ext = getattr(details, "external_ids", None) if details else None
|
| 643 |
+
imdb_id = getattr(ext, "imdb_id", None) if ext else None
|
| 644 |
+
except Exception:
|
| 645 |
+
pass
|
| 646 |
+
|
| 647 |
+
key = ("tmdb", str(tmdb_id))
|
| 648 |
+
if key in seen:
|
| 649 |
+
continue
|
| 650 |
+
seen.add(key)
|
| 651 |
+
|
| 652 |
+
first_air_date = getattr(item, "first_air_date", None)
|
| 653 |
+
year_value = getattr(first_air_date, "year", None) if first_air_date else None
|
| 654 |
+
|
| 655 |
+
results.append({
|
| 656 |
+
"source": "tmdb",
|
| 657 |
+
"title": getattr(item, "name", "") or "",
|
| 658 |
+
"year": year_value or "",
|
| 659 |
+
"imdb_id": imdb_id,
|
| 660 |
+
"tmdb_id": tmdb_id,
|
| 661 |
+
"poster": format_tmdb_image(getattr(item, "poster_path", None)),
|
| 662 |
+
"backdrop": format_tmdb_image(getattr(item, "backdrop_path", None), "original"),
|
| 663 |
+
"subtitle": "TMDb",
|
| 664 |
+
})
|
| 665 |
+
except Exception as e:
|
| 666 |
+
LOGGER.warning(f"TMDb TV candidate search failed for '{query}': {e}")
|
| 667 |
+
|
| 668 |
+
return results[:limit]
|
| 669 |
+
|
| 670 |
+
|
| 671 |
+
async def fetch_selected_movie_metadata(selected_id: str) -> dict | None:
|
| 672 |
+
selected_id = str(selected_id).strip()
|
| 673 |
+
if not selected_id:
|
| 674 |
+
return None
|
| 675 |
+
|
| 676 |
+
data = await fetch_movie_metadata(
|
| 677 |
+
title="manual-rescan",
|
| 678 |
+
encoded_string=None,
|
| 679 |
+
year=None,
|
| 680 |
+
quality=None,
|
| 681 |
+
default_id=selected_id
|
| 682 |
+
)
|
| 683 |
+
if not data:
|
| 684 |
+
return None
|
| 685 |
+
|
| 686 |
+
return {
|
| 687 |
+
"tmdb_id": data.get("tmdb_id"),
|
| 688 |
+
"imdb_id": data.get("imdb_id"),
|
| 689 |
+
"title": data.get("title"),
|
| 690 |
+
"release_year": data.get("year"),
|
| 691 |
+
"rating": data.get("rate"),
|
| 692 |
+
"description": data.get("description"),
|
| 693 |
+
"poster": data.get("poster"),
|
| 694 |
+
"backdrop": data.get("backdrop"),
|
| 695 |
+
"logo": data.get("logo"),
|
| 696 |
+
"genres": data.get("genres", []),
|
| 697 |
+
"cast": data.get("cast", []),
|
| 698 |
+
"runtime": data.get("runtime"),
|
| 699 |
+
"media_type": "movie",
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
|
| 703 |
+
async def fetch_selected_tv_metadata(selected_id: str) -> dict | None:
|
| 704 |
+
selected_id = str(selected_id).strip()
|
| 705 |
+
if not selected_id:
|
| 706 |
+
return None
|
| 707 |
+
|
| 708 |
+
imdb_id = None
|
| 709 |
+
tmdb_id = None
|
| 710 |
+
imdb_tv = None
|
| 711 |
+
use_tmdb = False
|
| 712 |
+
|
| 713 |
+
if selected_id.startswith("tt"):
|
| 714 |
+
imdb_id = selected_id
|
| 715 |
+
elif selected_id.isdigit():
|
| 716 |
+
tmdb_id = int(selected_id)
|
| 717 |
+
use_tmdb = True
|
| 718 |
+
else:
|
| 719 |
+
return None
|
| 720 |
+
|
| 721 |
+
if imdb_id and not use_tmdb:
|
| 722 |
+
try:
|
| 723 |
+
imdb_tv = await get_detail(imdb_id=imdb_id, media_type="tvSeries")
|
| 724 |
+
except Exception:
|
| 725 |
+
imdb_tv = None
|
| 726 |
+
use_tmdb = True
|
| 727 |
+
|
| 728 |
+
if use_tmdb or not imdb_tv:
|
| 729 |
+
if not tmdb_id and imdb_tv and imdb_tv.get("moviedb_id"):
|
| 730 |
+
try:
|
| 731 |
+
tmdb_id = int(imdb_tv["moviedb_id"])
|
| 732 |
+
except Exception:
|
| 733 |
+
tmdb_id = None
|
| 734 |
+
|
| 735 |
+
if not tmdb_id:
|
| 736 |
+
return None
|
| 737 |
+
|
| 738 |
+
tv = await _tmdb_tv_details(tmdb_id)
|
| 739 |
+
if not tv:
|
| 740 |
+
return None
|
| 741 |
+
|
| 742 |
+
credits = getattr(tv, "credits", None) or {}
|
| 743 |
+
cast_arr = getattr(credits, "cast", []) or []
|
| 744 |
+
cast = [
|
| 745 |
+
getattr(c, "name", None) or getattr(c, "original_name", None)
|
| 746 |
+
for c in cast_arr
|
| 747 |
+
]
|
| 748 |
+
|
| 749 |
+
runtime_val = tv.episode_run_time[0] if getattr(tv, "episode_run_time", None) else None
|
| 750 |
+
runtime = f"{runtime_val} min" if runtime_val else ""
|
| 751 |
+
|
| 752 |
+
return {
|
| 753 |
+
"tmdb_id": tv.id,
|
| 754 |
+
"imdb_id": getattr(getattr(tv, "external_ids", None), "imdb_id", None),
|
| 755 |
+
"title": tv.name,
|
| 756 |
+
"release_year": getattr(tv.first_air_date, "year", 0) if getattr(tv, "first_air_date", None) else 0,
|
| 757 |
+
"rating": getattr(tv, "vote_average", 0) or 0,
|
| 758 |
+
"description": tv.overview or "",
|
| 759 |
+
"poster": format_tmdb_image(tv.poster_path),
|
| 760 |
+
"backdrop": format_tmdb_image(tv.backdrop_path, "original"),
|
| 761 |
+
"logo": get_tmdb_logo(getattr(tv, "images", None)),
|
| 762 |
+
"genres": [g.name for g in (tv.genres or [])],
|
| 763 |
+
"cast": cast,
|
| 764 |
+
"runtime": str(runtime),
|
| 765 |
+
"media_type": "tv",
|
| 766 |
+
}
|
| 767 |
+
|
| 768 |
+
images = format_imdb_images(imdb_id)
|
| 769 |
+
return {
|
| 770 |
+
"tmdb_id": int(imdb_tv.get("moviedb_id")) if imdb_tv.get("moviedb_id") else None,
|
| 771 |
+
"imdb_id": imdb_id,
|
| 772 |
+
"title": imdb_tv.get("title", ""),
|
| 773 |
+
"release_year": imdb_tv.get("releaseDetailed", {}).get("year", 0),
|
| 774 |
+
"rating": imdb_tv.get("rating", {}).get("star", 0),
|
| 775 |
+
"description": imdb_tv.get("plot", ""),
|
| 776 |
+
"poster": images["poster"],
|
| 777 |
+
"backdrop": images["backdrop"],
|
| 778 |
+
"logo": images["logo"],
|
| 779 |
+
"genres": imdb_tv.get("genre", []),
|
| 780 |
+
"cast": imdb_tv.get("cast", []),
|
| 781 |
+
"runtime": str(imdb_tv.get("runtime") or ""),
|
| 782 |
+
"media_type": "tv",
|
| 783 |
+
}
|
pyproject.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
[project]
|
| 2 |
name = "Telegram-Stremio"
|
| 3 |
-
version = "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"
|
|
|
|
| 1 |
[project]
|
| 2 |
name = "Telegram-Stremio"
|
| 3 |
+
version = "2.2.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"
|