Merge pull request 'dev' (#57) from dev into main
Reviewed-on: #57
This commit was merged in pull request #57.
This commit is contained in:
@@ -29,6 +29,7 @@ class NFOGuardDatabase:
|
|||||||
self.db_name = config.db_name
|
self.db_name = config.db_name
|
||||||
self.db_user = config.db_user
|
self.db_user = config.db_user
|
||||||
self.db_password = config.db_password
|
self.db_password = config.db_password
|
||||||
|
self.db_type = "postgresql" # NFOGuard uses PostgreSQL
|
||||||
|
|
||||||
self._local = threading.local()
|
self._local = threading.local()
|
||||||
self._init_database()
|
self._init_database()
|
||||||
@@ -167,6 +168,8 @@ class NFOGuardDatabase:
|
|||||||
has_video_file = EXCLUDED.has_video_file,
|
has_video_file = EXCLUDED.has_video_file,
|
||||||
last_updated = EXCLUDED.last_updated
|
last_updated = EXCLUDED.last_updated
|
||||||
""", (imdb_id, season, episode, aired, dateadded, source, has_video_file, timestamp))
|
""", (imdb_id, season, episode, aired, dateadded, source, has_video_file, timestamp))
|
||||||
|
import os
|
||||||
|
if os.environ.get("DEBUG", "false").lower() == "true":
|
||||||
print(f"🔍 DEBUG: PostgreSQL upsert executed for {imdb_id} S{season:02d}E{episode:02d}, rows affected: {cursor.rowcount}")
|
print(f"🔍 DEBUG: PostgreSQL upsert executed for {imdb_id} S{season:02d}E{episode:02d}, rows affected: {cursor.rowcount}")
|
||||||
|
|
||||||
def upsert_movie(self, imdb_id: str, path: str):
|
def upsert_movie(self, imdb_id: str, path: str):
|
||||||
@@ -186,6 +189,8 @@ class NFOGuardDatabase:
|
|||||||
def upsert_movie_dates(self, imdb_id: str, released: Optional[str],
|
def upsert_movie_dates(self, imdb_id: str, released: Optional[str],
|
||||||
dateadded: Optional[str], source: str, has_video_file: bool = False):
|
dateadded: Optional[str], source: str, has_video_file: bool = False):
|
||||||
"""Insert or update movie date record"""
|
"""Insert or update movie date record"""
|
||||||
|
import os
|
||||||
|
if os.environ.get("DEBUG", "false").lower() == "true":
|
||||||
print(f"🔍 DATABASE UPSERT: imdb_id={imdb_id}, dateadded={dateadded}, source={source}")
|
print(f"🔍 DATABASE UPSERT: imdb_id={imdb_id}, dateadded={dateadded}, source={source}")
|
||||||
with self.get_connection() as conn:
|
with self.get_connection() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@@ -205,6 +210,8 @@ class NFOGuardDatabase:
|
|||||||
# Debug: Check what was actually saved
|
# Debug: Check what was actually saved
|
||||||
cursor.execute("SELECT dateadded, source FROM movies WHERE imdb_id = %s", (imdb_id,))
|
cursor.execute("SELECT dateadded, source FROM movies WHERE imdb_id = %s", (imdb_id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
import os
|
||||||
|
if os.environ.get("DEBUG", "false").lower() == "true":
|
||||||
print(f"🔍 DATABASE VERIFY: After upsert, found dateadded={result['dateadded'] if result else 'NOT_FOUND'}, source={result['source'] if result else 'NOT_FOUND'}")
|
print(f"🔍 DATABASE VERIFY: After upsert, found dateadded={result['dateadded'] if result else 'NOT_FOUND'}, source={result['source'] if result else 'NOT_FOUND'}")
|
||||||
|
|
||||||
def get_series_episodes(self, imdb_id: str, has_video_file_only: bool = False) -> List[Dict]:
|
def get_series_episodes(self, imdb_id: str, has_video_file_only: bool = False) -> List[Dict]:
|
||||||
|
|||||||
@@ -272,6 +272,9 @@ class NFOManager:
|
|||||||
"""Create or update movie.nfo file preserving existing content"""
|
"""Create or update movie.nfo file preserving existing content"""
|
||||||
nfo_path = movie_dir / "movie.nfo"
|
nfo_path = movie_dir / "movie.nfo"
|
||||||
|
|
||||||
|
# Debug output only if DEBUG=true in environment
|
||||||
|
import os
|
||||||
|
if os.environ.get("DEBUG", "false").lower() == "true":
|
||||||
print(f"🔍 create_movie_nfo called: imdb_id={imdb_id}, dateadded={dateadded}, released={released}, source={source}")
|
print(f"🔍 create_movie_nfo called: imdb_id={imdb_id}, dateadded={dateadded}, released={released}, source={source}")
|
||||||
print(f"🔍 NFO path: {nfo_path}")
|
print(f"🔍 NFO path: {nfo_path}")
|
||||||
print(f"🔍 NFO exists: {nfo_path.exists()}")
|
print(f"🔍 NFO exists: {nfo_path.exists()}")
|
||||||
@@ -365,6 +368,7 @@ class NFOManager:
|
|||||||
pass # Skip year if we can't extract it
|
pass # Skip year if we can't extract it
|
||||||
|
|
||||||
# Add dateadded - THIS IS CRITICAL FOR EMBY PLUGIN
|
# Add dateadded - THIS IS CRITICAL FOR EMBY PLUGIN
|
||||||
|
if os.environ.get("DEBUG", "false").lower() == "true":
|
||||||
print(f"🔍 About to add dateadded: {dateadded} (type: {type(dateadded)})")
|
print(f"🔍 About to add dateadded: {dateadded} (type: {type(dateadded)})")
|
||||||
if dateadded:
|
if dateadded:
|
||||||
dateadded_elem = ET.Element("dateadded")
|
dateadded_elem = ET.Element("dateadded")
|
||||||
|
|||||||
@@ -213,6 +213,12 @@ class MovieProcessor:
|
|||||||
_log("INFO", f"✅ TIER 1 - Using complete database data for {imdb_id}: {existing['dateadded']} (source: {existing['source']})")
|
_log("INFO", f"✅ TIER 1 - Using complete database data for {imdb_id}: {existing['dateadded']} (source: {existing['source']})")
|
||||||
dateadded, source, released = existing["dateadded"], existing["source"], existing.get("released")
|
dateadded, source, released = existing["dateadded"], existing["source"], existing.get("released")
|
||||||
|
|
||||||
|
# Convert datetime objects to strings for NFO manager
|
||||||
|
if hasattr(dateadded, 'isoformat'):
|
||||||
|
dateadded = dateadded.isoformat()
|
||||||
|
if released and hasattr(released, 'isoformat'):
|
||||||
|
released = released.isoformat()
|
||||||
|
|
||||||
# Create NFO with existing data and update files
|
# Create NFO with existing data and update files
|
||||||
if config.manage_nfo:
|
if config.manage_nfo:
|
||||||
self.nfo_manager.create_movie_nfo(
|
self.nfo_manager.create_movie_nfo(
|
||||||
@@ -351,13 +357,16 @@ class MovieProcessor:
|
|||||||
_log("INFO", f"Using release date as dateadded: {final_dateadded} (source: {final_source})")
|
_log("INFO", f"Using release date as dateadded: {final_dateadded} (source: {final_source})")
|
||||||
|
|
||||||
# Create NFO regardless of date availability (preserves existing metadata)
|
# Create NFO regardless of date availability (preserves existing metadata)
|
||||||
|
if config.debug:
|
||||||
print(f"🔍 TIER3 - config.manage_nfo: {config.manage_nfo}")
|
print(f"🔍 TIER3 - config.manage_nfo: {config.manage_nfo}")
|
||||||
if config.manage_nfo:
|
if config.manage_nfo:
|
||||||
|
if config.debug:
|
||||||
print(f"🔍 TIER3 - Calling create_movie_nfo with final_dateadded: {final_dateadded}")
|
print(f"🔍 TIER3 - Calling create_movie_nfo with final_dateadded: {final_dateadded}")
|
||||||
self.nfo_manager.create_movie_nfo(
|
self.nfo_manager.create_movie_nfo(
|
||||||
movie_path, imdb_id, final_dateadded, released, final_source, config.lock_metadata
|
movie_path, imdb_id, final_dateadded, released, final_source, config.lock_metadata
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
if config.debug:
|
||||||
print(f"❌ TIER3 - manage_nfo is disabled, skipping NFO creation")
|
print(f"❌ TIER3 - manage_nfo is disabled, skipping NFO creation")
|
||||||
|
|
||||||
# Skip remaining processing if no valid date found and file dates disabled
|
# Skip remaining processing if no valid date found and file dates disabled
|
||||||
|
|||||||
Reference in New Issue
Block a user