Skip NFO creation if exists and update DB
This commit is contained in:
@@ -381,7 +381,7 @@ class BackgroundLoaderService:
|
||||
db: Database session
|
||||
"""
|
||||
task.status = LoadingStatus.LOADING_NFO
|
||||
await self._broadcast_status(task, "Generating NFO file...")
|
||||
await self._broadcast_status(task, "Checking NFO file...")
|
||||
|
||||
try:
|
||||
# Check if NFOService is available
|
||||
@@ -394,6 +394,37 @@ class BackgroundLoaderService:
|
||||
task.progress["images"] = False
|
||||
return
|
||||
|
||||
# Check if NFO already exists
|
||||
if self.series_app.nfo_service.has_nfo(task.folder):
|
||||
logger.info(f"NFO already exists for {task.key}, skipping creation")
|
||||
|
||||
# Update task progress
|
||||
task.progress["nfo"] = True
|
||||
task.progress["logo"] = True # Assume logo exists if NFO exists
|
||||
task.progress["images"] = True # Assume images exist if NFO exists
|
||||
|
||||
# Update database with existing NFO info
|
||||
from src.server.database.service import AnimeSeriesService
|
||||
series_db = await AnimeSeriesService.get_by_key(db, task.key)
|
||||
if series_db:
|
||||
# Only update if not already marked
|
||||
if not series_db.has_nfo:
|
||||
series_db.has_nfo = True
|
||||
series_db.nfo_created_at = datetime.now(timezone.utc)
|
||||
logger.info(f"Updated database with existing NFO for {task.key}")
|
||||
if not series_db.logo_loaded:
|
||||
series_db.logo_loaded = True
|
||||
if not series_db.images_loaded:
|
||||
series_db.images_loaded = True
|
||||
await db.commit()
|
||||
|
||||
logger.info(f"Existing NFO found and database updated for series: {task.key}")
|
||||
return
|
||||
|
||||
# NFO doesn't exist, create it
|
||||
await self._broadcast_status(task, "Generating NFO file...")
|
||||
logger.info(f"Creating new NFO for {task.key}")
|
||||
|
||||
# Use existing NFOService to create NFO with all images
|
||||
# This reuses all existing TMDB API logic and image downloading
|
||||
nfo_path = await self.series_app.nfo_service.create_tvshow_nfo(
|
||||
@@ -421,7 +452,7 @@ class BackgroundLoaderService:
|
||||
series_db.loading_status = "loading_nfo"
|
||||
await db.commit()
|
||||
|
||||
logger.info(f"NFO and images loaded for series: {task.key}")
|
||||
logger.info(f"NFO and images created and loaded for series: {task.key}")
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to load NFO/images for {task.key}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user