imdb: missing imdge improvments
This commit is contained in:
+99
-5
@@ -844,9 +844,25 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
for item in scan_path.iterdir():
|
||||
if (item.is_dir() and
|
||||
not item.name.lower().startswith('season') and
|
||||
not re.match(r'^season\s+\d+$', item.name, re.IGNORECASE) and
|
||||
nfo_manager.parse_imdb_from_path(item)):
|
||||
tv_series_list.append(item)
|
||||
not re.match(r'^season\s+\d+$', item.name, re.IGNORECASE)):
|
||||
|
||||
# Check for IMDb ID
|
||||
imdb_id = nfo_manager.parse_imdb_from_path(item)
|
||||
if imdb_id:
|
||||
tv_series_list.append(item)
|
||||
else:
|
||||
# Log missing IMDb ID for TV series
|
||||
try:
|
||||
db.add_missing_imdb(
|
||||
file_path=str(item),
|
||||
media_type="tv",
|
||||
folder_name=item.name,
|
||||
filename=None,
|
||||
notes=f"TV series directory without IMDb ID detected during scan"
|
||||
)
|
||||
print(f"⚠️ Missing IMDb ID: TV series {item.name} - logged for manual review")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to log missing IMDb for TV series {item.name}: {e}")
|
||||
|
||||
tv_series_count = len(tv_series_list)
|
||||
update_scan_status("tv", tv_series_total=tv_series_count)
|
||||
@@ -894,8 +910,24 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
|
||||
# Count total movies first for progress tracking
|
||||
movie_list = []
|
||||
for item in scan_path.iterdir():
|
||||
if item.is_dir() and nfo_manager.find_movie_imdb_id(item):
|
||||
movie_list.append(item)
|
||||
if item.is_dir():
|
||||
# Check for IMDb ID
|
||||
imdb_id = nfo_manager.find_movie_imdb_id(item)
|
||||
if imdb_id:
|
||||
movie_list.append(item)
|
||||
else:
|
||||
# Log missing IMDb ID for movie
|
||||
try:
|
||||
db.add_missing_imdb(
|
||||
file_path=str(item),
|
||||
media_type="movie",
|
||||
folder_name=item.name,
|
||||
filename=None,
|
||||
notes=f"Movie directory without IMDb ID detected during scan"
|
||||
)
|
||||
print(f"⚠️ Missing IMDb ID: Movie {item.name} - logged for manual review")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to log missing IMDb for movie {item.name}: {e}")
|
||||
|
||||
movie_total_count = len(movie_list)
|
||||
update_scan_status(movies_total=movie_total_count)
|
||||
@@ -2967,6 +2999,68 @@ def register_routes(app, dependencies: dict):
|
||||
async def _nfo_repair_fix():
|
||||
return await nfo_repair_fix()
|
||||
|
||||
@app.get("/admin/missing-imdb")
|
||||
async def get_missing_imdb():
|
||||
"""Get items missing IMDb IDs for manual review"""
|
||||
config = dependencies.get("config")
|
||||
db = dependencies.get("db")
|
||||
|
||||
if not config or not db:
|
||||
raise HTTPException(status_code=500, detail="Dependencies not available")
|
||||
|
||||
print("📋 Retrieving missing IMDb items from core container")
|
||||
|
||||
try:
|
||||
# Get missing items by type
|
||||
missing_tv = db.get_missing_imdb_items(media_type="tv", resolved=False)
|
||||
missing_movies = db.get_missing_imdb_items(media_type="movie", resolved=False)
|
||||
|
||||
# Format for web interface
|
||||
missing_items = []
|
||||
|
||||
for item in missing_tv:
|
||||
missing_items.append({
|
||||
"id": item["id"],
|
||||
"type": "TV Series",
|
||||
"folder_name": item["folder_name"],
|
||||
"file_path": item["file_path"],
|
||||
"discovered_at": item["discovered_at"].isoformat() if item["discovered_at"] else None,
|
||||
"last_checked": item["last_checked"].isoformat() if item["last_checked"] else None,
|
||||
"check_count": item["check_count"],
|
||||
"notes": item["notes"]
|
||||
})
|
||||
|
||||
for item in missing_movies:
|
||||
missing_items.append({
|
||||
"id": item["id"],
|
||||
"type": "Movie",
|
||||
"folder_name": item["folder_name"],
|
||||
"file_path": item["file_path"],
|
||||
"discovered_at": item["discovered_at"].isoformat() if item["discovered_at"] else None,
|
||||
"last_checked": item["last_checked"].isoformat() if item["last_checked"] else None,
|
||||
"check_count": item["check_count"],
|
||||
"notes": item["notes"]
|
||||
})
|
||||
|
||||
print(f"✅ Found {len(missing_tv)} TV series and {len(missing_movies)} movies missing IMDb IDs")
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
"missing_items": missing_items,
|
||||
"summary": {
|
||||
"total_missing": len(missing_items),
|
||||
"tv_series": len(missing_tv),
|
||||
"movies": len(missing_movies)
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error retrieving missing IMDb items: {e}")
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Failed to retrieve missing IMDb items: {str(e)}"
|
||||
}
|
||||
|
||||
# ---------------------------
|
||||
# Core API - No Web Interface
|
||||
# ---------------------------
|
||||
|
||||
@@ -1676,6 +1676,58 @@ async def fix_nfo_missing_dateadded(dependencies: dict):
|
||||
}
|
||||
|
||||
|
||||
async def get_missing_imdb_items(dependencies: dict):
|
||||
"""Get items missing IMDb IDs for manual review via core container"""
|
||||
config = dependencies["config"]
|
||||
|
||||
try:
|
||||
print("📋 Calling core container for missing IMDb items...")
|
||||
|
||||
# Call the core container's missing IMDb endpoint
|
||||
import aiohttp
|
||||
import asyncio
|
||||
|
||||
core_url = f"http://nfoguard:{config.core_api_port}/admin/missing-imdb"
|
||||
print(f"🔍 DEBUG: Calling core container at: {core_url}")
|
||||
|
||||
timeout = aiohttp.ClientTimeout(total=60.0) # 1 minute timeout
|
||||
async with aiohttp.ClientSession(timeout=timeout) as session:
|
||||
async with session.get(core_url) as response:
|
||||
if response.status == 200:
|
||||
result = await response.json()
|
||||
print(f"✅ Core container retrieved missing IMDb items: {result['summary']['total_missing']} items")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"total_missing": result['summary']['total_missing'],
|
||||
"tv_series_missing": result['summary']['tv_series'],
|
||||
"movies_missing": result['summary']['movies'],
|
||||
"items": result['missing_items'],
|
||||
"debug_info": {
|
||||
"scan_method": "core_container_database",
|
||||
"core_container_response": "success"
|
||||
}
|
||||
}
|
||||
else:
|
||||
error_text = await response.text()
|
||||
print(f"❌ Core container missing IMDb retrieval failed: {response.status} - {error_text}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"Core container retrieval failed: {response.status}",
|
||||
"message": f"Failed to retrieve missing IMDb items via core container: {response.status}"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error calling core container for missing IMDb items: {str(e)}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"Core container communication failed: {str(e)}",
|
||||
"message": f"Failed to retrieve missing IMDb items: {str(e)}"
|
||||
}
|
||||
|
||||
|
||||
async def bulk_update_nfo_files(dependencies: dict, imdb_ids: list = None, fix_all: bool = False):
|
||||
"""Update NFO files with missing dateadded elements from database"""
|
||||
db = dependencies["db"]
|
||||
@@ -1794,6 +1846,11 @@ def register_database_admin_routes(app, dependencies):
|
||||
"""Get episodes missing dateadded in NFO files"""
|
||||
return await get_episodes_missing_nfo_dateadded(dependencies)
|
||||
|
||||
@app.get("/api/admin/missing-imdb")
|
||||
async def api_missing_imdb_items():
|
||||
"""Get items missing IMDb IDs for manual review"""
|
||||
return await get_missing_imdb_items(dependencies)
|
||||
|
||||
@app.post("/api/admin/nfo/bulk-update")
|
||||
async def api_bulk_update_nfo_files(imdb_ids: list = None, fix_all: bool = False):
|
||||
"""Bulk update NFO files with missing dateadded via core container"""
|
||||
|
||||
Reference in New Issue
Block a user