This commit is contained in:
+62
-1
@@ -717,7 +717,68 @@ class NFOGuardDatabase:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
return deleted_count > 0
|
return deleted_count > 0
|
||||||
|
|
||||||
|
def update_movie_file_info(self, imdb_id: str, path: str, has_video_file: bool = True) -> bool:
|
||||||
|
"""
|
||||||
|
Update path and video file status for an existing movie
|
||||||
|
Used when population finds a video file for a manually-added movie
|
||||||
|
|
||||||
|
Args:
|
||||||
|
imdb_id: Movie IMDb ID
|
||||||
|
path: File path to the video file
|
||||||
|
has_video_file: Whether a video file exists (default True)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if movie was updated, False if not found
|
||||||
|
"""
|
||||||
|
with self.get_connection() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE movies
|
||||||
|
SET path = %s,
|
||||||
|
has_video_file = %s,
|
||||||
|
last_updated = %s
|
||||||
|
WHERE imdb_id = %s
|
||||||
|
""", (path, has_video_file, datetime.utcnow(), imdb_id))
|
||||||
|
|
||||||
|
updated_count = cursor.rowcount
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return updated_count > 0
|
||||||
|
|
||||||
|
def update_episode_file_info(self, imdb_id: str, season: int, episode: int,
|
||||||
|
path: str, has_video_file: bool = True) -> bool:
|
||||||
|
"""
|
||||||
|
Update path and video file status for an existing episode
|
||||||
|
Used when population finds a video file for a manually-added episode
|
||||||
|
|
||||||
|
Args:
|
||||||
|
imdb_id: Series IMDb ID
|
||||||
|
season: Season number
|
||||||
|
episode: Episode number
|
||||||
|
path: File path to the video file
|
||||||
|
has_video_file: Whether a video file exists (default True)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if episode was updated, False if not found
|
||||||
|
"""
|
||||||
|
with self.get_connection() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
UPDATE episodes
|
||||||
|
SET path = %s,
|
||||||
|
has_video_file = %s,
|
||||||
|
last_updated = %s
|
||||||
|
WHERE imdb_id = %s AND season = %s AND episode = %s
|
||||||
|
""", (path, has_video_file, datetime.utcnow(), imdb_id, season, episode))
|
||||||
|
|
||||||
|
updated_count = cursor.rowcount
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return updated_count > 0
|
||||||
|
|
||||||
def delete_orphaned_movies(self) -> List[Dict]:
|
def delete_orphaned_movies(self) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Find and delete movies that don't have corresponding video files on disk
|
Find and delete movies that don't have corresponding video files on disk
|
||||||
|
|||||||
@@ -111,8 +111,14 @@ class DatabasePopulator:
|
|||||||
# Check if movie already exists in database
|
# Check if movie already exists in database
|
||||||
existing = self.db.get_movie_dates(imdb_id)
|
existing = self.db.get_movie_dates(imdb_id)
|
||||||
if existing and existing.get('dateadded'):
|
if existing and existing.get('dateadded'):
|
||||||
# Already in database - skip silently (not an error)
|
# Already in database - update file path and video status if needed
|
||||||
_log("DEBUG", f"Movie {imdb_id} already in database, skipping")
|
existing_path = existing.get('path')
|
||||||
|
if not existing_path or existing_path == 'unknown' or existing_path != path:
|
||||||
|
_log("INFO", f"Movie {imdb_id} exists but updating file info: {path}")
|
||||||
|
self.db.update_movie_file_info(imdb_id, path, has_video_file=True)
|
||||||
|
stats['updated'] += 1
|
||||||
|
else:
|
||||||
|
_log("DEBUG", f"Movie {imdb_id} already in database with correct path, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get release date
|
# Get release date
|
||||||
@@ -308,7 +314,13 @@ class DatabasePopulator:
|
|||||||
# Check if episode already exists
|
# Check if episode already exists
|
||||||
existing = self.db.get_episode_date(imdb_id, season_num, episode_num)
|
existing = self.db.get_episode_date(imdb_id, season_num, episode_num)
|
||||||
if existing and existing.get('dateadded'):
|
if existing and existing.get('dateadded'):
|
||||||
# Already in database - skip silently (not an error)
|
# Already in database - update file path and video status if needed
|
||||||
|
existing_path = existing.get('path')
|
||||||
|
episode_path = episode.get('path', 'unknown')
|
||||||
|
if not existing_path or existing_path == 'unknown' or existing_path != episode_path:
|
||||||
|
_log("INFO", f"Episode {imdb_id} S{season_num:02d}E{episode_num:02d} exists but updating file info: {episode_path}")
|
||||||
|
self.db.update_episode_file_info(imdb_id, season_num, episode_num, episode_path, has_video_file=True)
|
||||||
|
stats['updated'] += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Only process episodes that have video files
|
# Only process episodes that have video files
|
||||||
|
|||||||
Reference in New Issue
Block a user