refactor: update and remove anything to do with NFO files
Local Docker Build (Dev) / build-dev (push) Successful in 35s
Local Docker Build (Dev) / build-dev (push) Successful in 35s
moving to an all DB approach since radarr overwrites .nfo files
This commit is contained in:
+117
@@ -2538,6 +2538,115 @@ async def lookup_movie(imdb_id: str, dependencies: dict):
|
||||
raise HTTPException(status_code=500, detail=f"Movie lookup failed: {str(e)}")
|
||||
|
||||
|
||||
async def populate_database(background_tasks: BackgroundTasks, media_type: str = "both", dependencies: dict = None):
|
||||
"""
|
||||
Populate NFOGuard database from Radarr/Sonarr sources
|
||||
|
||||
Args:
|
||||
background_tasks: FastAPI background tasks
|
||||
media_type: Type of media to populate ("movies", "tv", or "both")
|
||||
dependencies: Dictionary with db, radarr_client, sonarr_client
|
||||
|
||||
Returns:
|
||||
Status message indicating population has started
|
||||
"""
|
||||
from core.database_populator import DatabasePopulator
|
||||
|
||||
db = dependencies["db"]
|
||||
config = dependencies["config"]
|
||||
|
||||
# Get Radarr and Sonarr clients
|
||||
from clients.radarr_client import RadarrClient
|
||||
from clients.sonarr_client import SonarrClient
|
||||
|
||||
radarr_client = RadarrClient(config)
|
||||
sonarr_client = SonarrClient(config)
|
||||
|
||||
if media_type not in ["both", "movies", "tv"]:
|
||||
raise HTTPException(status_code=400, detail="media_type must be 'both', 'movies', or 'tv'")
|
||||
|
||||
# Create global status tracking
|
||||
populate_status = {
|
||||
"running": True,
|
||||
"media_type": media_type,
|
||||
"start_time": datetime.now().isoformat(),
|
||||
"movies": {"status": "pending", "stats": None},
|
||||
"tv": {"status": "pending", "stats": None},
|
||||
"completed": False,
|
||||
"error": None
|
||||
}
|
||||
|
||||
# Store status globally so it can be queried
|
||||
global _populate_status
|
||||
_populate_status = populate_status
|
||||
|
||||
async def run_population():
|
||||
"""Background task to populate the database"""
|
||||
try:
|
||||
populator = DatabasePopulator(db, radarr_client, sonarr_client)
|
||||
|
||||
_log("INFO", f"Starting database population: {media_type}")
|
||||
|
||||
if media_type == "movies":
|
||||
populate_status["movies"]["status"] = "running"
|
||||
movie_stats = populator.populate_movies()
|
||||
populate_status["movies"]["status"] = "completed"
|
||||
populate_status["movies"]["stats"] = movie_stats
|
||||
_log("INFO", f"Movie population completed: {movie_stats}")
|
||||
|
||||
elif media_type == "tv":
|
||||
populate_status["tv"]["status"] = "running"
|
||||
tv_stats = populator.populate_tv_episodes()
|
||||
populate_status["tv"]["status"] = "completed"
|
||||
populate_status["tv"]["stats"] = tv_stats
|
||||
_log("INFO", f"TV population completed: {tv_stats}")
|
||||
|
||||
elif media_type == "both":
|
||||
populate_status["movies"]["status"] = "running"
|
||||
movie_stats = populator.populate_movies()
|
||||
populate_status["movies"]["status"] = "completed"
|
||||
populate_status["movies"]["stats"] = movie_stats
|
||||
_log("INFO", f"Movie population completed: {movie_stats}")
|
||||
|
||||
populate_status["tv"]["status"] = "running"
|
||||
tv_stats = populator.populate_tv_episodes()
|
||||
populate_status["tv"]["status"] = "completed"
|
||||
populate_status["tv"]["stats"] = tv_stats
|
||||
_log("INFO", f"TV population completed: {tv_stats}")
|
||||
|
||||
populate_status["completed"] = True
|
||||
populate_status["running"] = False
|
||||
_log("INFO", "Database population completed successfully")
|
||||
|
||||
except Exception as e:
|
||||
_log("ERROR", f"Database population failed: {e}")
|
||||
populate_status["error"] = str(e)
|
||||
populate_status["running"] = False
|
||||
populate_status["completed"] = True
|
||||
|
||||
# Add task to background
|
||||
background_tasks.add_task(run_population)
|
||||
|
||||
_log("INFO", f"Database population started for: {media_type}")
|
||||
return {
|
||||
"status": "started",
|
||||
"media_type": media_type,
|
||||
"message": f"Database population started for {media_type}"
|
||||
}
|
||||
|
||||
|
||||
async def get_populate_status():
|
||||
"""Get the current status of database population"""
|
||||
global _populate_status
|
||||
if '_populate_status' not in globals():
|
||||
return {"running": False, "completed": False}
|
||||
return _populate_status
|
||||
|
||||
|
||||
# Initialize global populate status
|
||||
_populate_status = {"running": False, "completed": False}
|
||||
|
||||
|
||||
def register_routes(app, dependencies: dict):
|
||||
"""
|
||||
Register all routes with the FastAPI app
|
||||
@@ -2641,6 +2750,14 @@ def register_routes(app, dependencies: dict):
|
||||
async def _scan_status():
|
||||
return await get_scan_status()
|
||||
|
||||
@app.post("/admin/populate-database")
|
||||
async def _populate_database(background_tasks: BackgroundTasks, media_type: str = "both"):
|
||||
return await populate_database(background_tasks, media_type, dependencies)
|
||||
|
||||
@app.get("/api/populate/status")
|
||||
async def _populate_status():
|
||||
return await get_populate_status()
|
||||
|
||||
@app.post("/tv/scan-season")
|
||||
async def _scan_tv_season(background_tasks: BackgroundTasks, request: TVSeasonRequest):
|
||||
return await scan_tv_season(background_tasks, request, dependencies)
|
||||
|
||||
Reference in New Issue
Block a user