imdb: missing imdge improvments

This commit is contained in:
2025-10-26 15:48:26 -04:00
parent 10a9677804
commit 0b9f450b1d
6 changed files with 472 additions and 5 deletions
+90
View File
@@ -129,11 +129,32 @@ class NFOGuardDatabase:
)
""")
# Missing IMDb tracking table
cursor.execute("""
CREATE TABLE IF NOT EXISTS missing_imdb (
id SERIAL PRIMARY KEY,
file_path TEXT NOT NULL UNIQUE,
media_type VARCHAR(20) NOT NULL,
folder_name TEXT,
filename TEXT,
discovered_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_checked TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
check_count INTEGER DEFAULT 1,
notes TEXT,
resolved BOOLEAN DEFAULT FALSE,
resolved_at TIMESTAMP,
resolved_imdb_id VARCHAR(20)
)
""")
# Create indexes for PostgreSQL
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_imdb ON episodes(imdb_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_episodes_video ON episodes(has_video_file)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_movies_video ON movies(has_video_file)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_history_imdb ON processing_history(imdb_id)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_missing_imdb_type ON missing_imdb(media_type)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_missing_imdb_resolved ON missing_imdb(resolved)")
cursor.execute("CREATE INDEX IF NOT EXISTS idx_missing_imdb_path ON missing_imdb(file_path)")
def upsert_series(self, imdb_id: str, path: str, metadata: Optional[Dict] = None):
"""Insert or update series record"""
with self.get_connection() as conn:
@@ -583,6 +604,75 @@ class NFOGuardDatabase:
return deleted_series
def add_missing_imdb(self, file_path: str, media_type: str, folder_name: str = None, filename: str = None, notes: str = None):
"""Add or update a missing IMDb entry"""
with self.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
INSERT INTO missing_imdb (file_path, media_type, folder_name, filename, notes)
VALUES (%s, %s, %s, %s, %s)
ON CONFLICT (file_path) DO UPDATE SET
last_checked = CURRENT_TIMESTAMP,
check_count = missing_imdb.check_count + 1,
media_type = EXCLUDED.media_type,
folder_name = EXCLUDED.folder_name,
filename = EXCLUDED.filename,
notes = EXCLUDED.notes
""", (file_path, media_type, folder_name, filename, notes))
conn.commit()
def get_missing_imdb_items(self, media_type: str = None, resolved: bool = False) -> List[Dict]:
"""Get missing IMDb items, optionally filtered by type and resolution status"""
with self.get_connection() as conn:
cursor = conn.cursor()
query = """
SELECT id, file_path, media_type, folder_name, filename,
discovered_at, last_checked, check_count, notes,
resolved, resolved_at, resolved_imdb_id
FROM missing_imdb
WHERE resolved = %s
"""
params = [resolved]
if media_type:
query += " AND media_type = %s"
params.append(media_type)
query += " ORDER BY last_checked DESC"
cursor.execute(query, params)
return cursor.fetchall()
def resolve_missing_imdb(self, file_path: str, imdb_id: str):
"""Mark a missing IMDb item as resolved"""
with self.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
UPDATE missing_imdb
SET resolved = TRUE,
resolved_at = CURRENT_TIMESTAMP,
resolved_imdb_id = %s
WHERE file_path = %s
""", (imdb_id, file_path))
conn.commit()
return cursor.rowcount > 0
def delete_missing_imdb(self, file_path: str) -> bool:
"""Delete a missing IMDb entry"""
with self.get_connection() as conn:
cursor = conn.cursor()
cursor.execute("DELETE FROM missing_imdb WHERE file_path = %s", (file_path,))
deleted_count = cursor.rowcount
conn.commit()
return deleted_count > 0
def close(self):
"""Close all database connections"""
if hasattr(self._local, 'connection'):