fix: not shutting down during scan

This commit is contained in:
2025-10-20 10:36:23 -04:00
parent 55de6284c8
commit 1e2cf49c10
3 changed files with 94 additions and 2 deletions
+52
View File
@@ -501,6 +501,58 @@ class NFOGuardDatabase:
return deleted_movies
def delete_orphaned_series(self) -> List[Dict]:
"""
Find and delete TV series that don't have corresponding directories on disk
This requires checking filesystem for each series, so use carefully
Returns:
List of deleted series with their details
"""
from pathlib import Path
deleted_series = []
with self.get_connection() as conn:
cursor = conn.cursor()
# Get all series with their paths
cursor.execute("""
SELECT imdb_id, path, last_updated, metadata
FROM series
""")
series_list = cursor.fetchall()
for series in series_list:
imdb_id = series['imdb_id']
series_path = Path(series['path'])
if not series_path.exists():
# Series directory doesn't exist - delete the series and all its episodes
cursor.execute("""
DELETE FROM episodes
WHERE imdb_id = %s
""", (imdb_id,))
episodes_deleted = cursor.rowcount
cursor.execute("""
DELETE FROM series
WHERE imdb_id = %s
""", (imdb_id,))
deleted_series.append({
'imdb_id': imdb_id,
'reason': 'directory_not_found',
'path': str(series_path),
'last_updated': series['last_updated'],
'episodes_deleted': episodes_deleted
})
conn.commit()
return deleted_series
def close(self):
"""Close all database connections"""
if hasattr(self._local, 'connection'):