initial update

This commit is contained in:
2025-09-21 09:25:36 -04:00
parent f5fd954ebb
commit 22483717c4
11 changed files with 994 additions and 613 deletions
+25 -15
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
NFOGuard - Consolidated webhook server for TV and Movie import date management
Replaces webhook_server.py and media_date_cache.py with modular architecture
NFOGuard - Automated NFO file management for Radarr and Sonarr
Modular architecture with webhook processing and intelligent date handling
"""
import os
import json
@@ -949,9 +949,9 @@ class MovieProcessor:
def process_movie(self, movie_path: Path, webhook_mode: bool = False) -> None:
"""Process a movie directory"""
imdb_id = self.nfo_manager.parse_imdb_from_path(movie_path)
imdb_id = self.nfo_manager.find_movie_imdb_id(movie_path)
if not imdb_id:
_log("ERROR", f"No IMDb ID found in movie path: {movie_path}")
_log("ERROR", f"No IMDb ID found in movie directory, filenames, or NFO file: {movie_path}")
return
_log("INFO", f"Processing movie: {movie_path.name} (IMDb: {imdb_id})")
@@ -1005,24 +1005,34 @@ class MovieProcessor:
# Use existing movie date decision logic
dateadded, source, released = self._decide_movie_dates(imdb_id, movie_path, should_query, existing)
# Skip processing if no valid date found and file dates disabled
if dateadded is None:
_log("WARNING", f"Skipping movie {movie_path.name} - no valid date source available")
self.db.upsert_movie_dates(imdb_id, released, None, source, True)
return
# Create NFO
# Create NFO regardless of date availability (preserves existing metadata)
if config.manage_nfo:
self.nfo_manager.create_movie_nfo(
movie_path, imdb_id, dateadded, released, source, config.lock_metadata
)
# Update file mtimes
# Skip remaining processing if no valid date found and file dates disabled
if dateadded is None:
_log("WARNING", f"Movie {movie_path.name} - no valid date source available, but NFO was still processed")
self.db.upsert_movie_dates(imdb_id, released, None, source, True)
return
_log("DEBUG", f"Movie {movie_path.name} proceeding to save: dateadded={dateadded}, source={source}")
# Update file mtimes (only if we have a valid date)
if config.fix_dir_mtimes and dateadded and dateadded != "MANUAL_REVIEW_NEEDED":
self.nfo_manager.update_movie_files_mtime(movie_path, dateadded)
_log("DEBUG", f"Movie processing reached file mtime section: fix_dir_mtimes={config.fix_dir_mtimes}, dateadded={dateadded}")
# Save to database
self.db.upsert_movie_dates(imdb_id, released, dateadded, source, True)
_log("DEBUG", f"About to save to database: imdb_id={imdb_id}, dateadded={dateadded}")
try:
self.db.upsert_movie_dates(imdb_id, released, dateadded, source, True)
_log("DEBUG", f"Database save completed for {imdb_id}")
except Exception as e:
_log("ERROR", f"Database save failed for {imdb_id}: {e}")
raise
_log("INFO", f"Completed processing movie: {movie_path.name} (source: {source})")
@@ -1874,7 +1884,7 @@ async def manual_scan(background_tasks: BackgroundTasks, path: Optional[str] = N
_log("INFO", f"Scanning movies in: {scan_path}")
movie_count = 0
for item in scan_path.iterdir():
if item.is_dir() and nfo_manager.parse_imdb_from_path(item):
if item.is_dir() and nfo_manager.find_movie_imdb_id(item):
movie_count += 1
_log("INFO", f"Processing movie: {item.name}")
try:
@@ -1986,7 +1996,7 @@ async def test_movie_scan():
if path.exists():
for item in path.iterdir():
if item.is_dir() and nfo_manager.parse_imdb_from_path(item):
if item.is_dir() and nfo_manager.find_movie_imdb_id(item):
path_result["movies_found"] += 1
results.append(path_result)