dev #66
+122
@@ -2221,6 +2221,116 @@ async def update_episode_nfo(imdb_id: str, season: int, episode: int, request: R
|
|||||||
return {"success": False, "message": f"Failed to update NFO file: {str(e)}"}
|
return {"success": False, "message": f"Failed to update NFO file: {str(e)}"}
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# Emby Plugin Lookup Functions
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
|
async def lookup_episode(imdb_id: str, season: int, episode: int, dependencies: dict):
|
||||||
|
"""
|
||||||
|
Lookup episode dateadded from NFOGuard database for Emby plugin integration
|
||||||
|
|
||||||
|
Returns dateadded information if found, or null if not available.
|
||||||
|
Used by Emby plugin to populate missing dateadded elements in NFO files.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
db = dependencies.get("db")
|
||||||
|
if not db:
|
||||||
|
raise HTTPException(status_code=500, detail="Database not available")
|
||||||
|
|
||||||
|
# Normalize IMDb ID (ensure tt prefix)
|
||||||
|
if not imdb_id.startswith('tt'):
|
||||||
|
imdb_id = f"tt{imdb_id}"
|
||||||
|
|
||||||
|
# Query database for episode
|
||||||
|
result = db.get_episode_data(imdb_id, season, episode)
|
||||||
|
|
||||||
|
if result and result.get('dateadded'):
|
||||||
|
# Format response for Emby plugin
|
||||||
|
dateadded = result['dateadded']
|
||||||
|
|
||||||
|
# Convert datetime to ISO string if needed
|
||||||
|
if hasattr(dateadded, 'isoformat'):
|
||||||
|
dateadded_str = dateadded.isoformat()
|
||||||
|
else:
|
||||||
|
dateadded_str = str(dateadded)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"found": True,
|
||||||
|
"imdb_id": imdb_id,
|
||||||
|
"season": season,
|
||||||
|
"episode": episode,
|
||||||
|
"dateadded": dateadded_str,
|
||||||
|
"source": result.get('source', 'database'),
|
||||||
|
"air_date": result.get('air_date') if result.get('air_date') else None
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# Not found in database
|
||||||
|
return {
|
||||||
|
"found": False,
|
||||||
|
"imdb_id": imdb_id,
|
||||||
|
"season": season,
|
||||||
|
"episode": episode,
|
||||||
|
"dateadded": None,
|
||||||
|
"source": None,
|
||||||
|
"air_date": None
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: Episode lookup failed for {imdb_id} S{season:02d}E{episode:02d}: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"Episode lookup failed: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
async def lookup_movie(imdb_id: str, dependencies: dict):
|
||||||
|
"""
|
||||||
|
Lookup movie dateadded from NFOGuard database for Emby plugin integration
|
||||||
|
|
||||||
|
Returns dateadded information if found, or null if not available.
|
||||||
|
Used by Emby plugin to populate missing dateadded elements in NFO files.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
db = dependencies.get("db")
|
||||||
|
if not db:
|
||||||
|
raise HTTPException(status_code=500, detail="Database not available")
|
||||||
|
|
||||||
|
# Normalize IMDb ID (ensure tt prefix)
|
||||||
|
if not imdb_id.startswith('tt'):
|
||||||
|
imdb_id = f"tt{imdb_id}"
|
||||||
|
|
||||||
|
# Query database for movie
|
||||||
|
result = db.get_movie_data(imdb_id)
|
||||||
|
|
||||||
|
if result and result.get('dateadded'):
|
||||||
|
# Format response for Emby plugin
|
||||||
|
dateadded = result['dateadded']
|
||||||
|
|
||||||
|
# Convert datetime to ISO string if needed
|
||||||
|
if hasattr(dateadded, 'isoformat'):
|
||||||
|
dateadded_str = dateadded.isoformat()
|
||||||
|
else:
|
||||||
|
dateadded_str = str(dateadded)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"found": True,
|
||||||
|
"imdb_id": imdb_id,
|
||||||
|
"dateadded": dateadded_str,
|
||||||
|
"source": result.get('source', 'database'),
|
||||||
|
"released": result.get('released') if result.get('released') else None
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# Not found in database
|
||||||
|
return {
|
||||||
|
"found": False,
|
||||||
|
"imdb_id": imdb_id,
|
||||||
|
"dateadded": None,
|
||||||
|
"source": None,
|
||||||
|
"released": None
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR: Movie lookup failed for {imdb_id}: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"Movie lookup failed: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def register_routes(app, dependencies: dict):
|
def register_routes(app, dependencies: dict):
|
||||||
"""
|
"""
|
||||||
Register all routes with the FastAPI app
|
Register all routes with the FastAPI app
|
||||||
@@ -2352,6 +2462,18 @@ def register_routes(app, dependencies: dict):
|
|||||||
async def _debug_tmdb_lookup(imdb_id: str):
|
async def _debug_tmdb_lookup(imdb_id: str):
|
||||||
return await debug_tmdb_lookup(imdb_id, dependencies)
|
return await debug_tmdb_lookup(imdb_id, dependencies)
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# Emby Plugin Lookup Endpoints
|
||||||
|
# ---------------------------
|
||||||
|
|
||||||
|
@app.get("/api/lookup/episode/{imdb_id}/{season}/{episode}")
|
||||||
|
async def _lookup_episode(imdb_id: str, season: int, episode: int):
|
||||||
|
return await lookup_episode(imdb_id, season, episode, dependencies)
|
||||||
|
|
||||||
|
@app.get("/api/lookup/movie/{imdb_id}")
|
||||||
|
async def _lookup_movie(imdb_id: str):
|
||||||
|
return await lookup_movie(imdb_id, dependencies)
|
||||||
|
|
||||||
# Include monitoring routes
|
# Include monitoring routes
|
||||||
from api.monitoring_routes import router as monitoring_router
|
from api.monitoring_routes import router as monitoring_router
|
||||||
app.include_router(monitoring_router)
|
app.include_router(monitoring_router)
|
||||||
|
|||||||
Reference in New Issue
Block a user