This commit is contained in:
+15
-2
@@ -111,7 +111,9 @@ class NFOGuardDatabase:
|
|||||||
else:
|
else:
|
||||||
self._init_sqlite_tables(cursor)
|
self._init_sqlite_tables(cursor)
|
||||||
|
|
||||||
print(f"✅ Database initialized: {self.db_type.upper()}")
|
# Test the connection works
|
||||||
|
cursor.execute("SELECT 1")
|
||||||
|
print(f"✅ Database initialized and connection verified: {self.db_type.upper()}")
|
||||||
|
|
||||||
def _init_postgresql_tables(self, cursor):
|
def _init_postgresql_tables(self, cursor):
|
||||||
"""Initialize PostgreSQL tables"""
|
"""Initialize PostgreSQL tables"""
|
||||||
@@ -464,6 +466,16 @@ class NFOGuardDatabase:
|
|||||||
cursor.execute("SELECT COUNT(*) FROM processing_history")
|
cursor.execute("SELECT COUNT(*) FROM processing_history")
|
||||||
history_count = self._get_first_value(cursor.fetchone())
|
history_count = self._get_first_value(cursor.fetchone())
|
||||||
|
|
||||||
|
# Database size calculation
|
||||||
|
if self.db_type == "postgresql":
|
||||||
|
# PostgreSQL: Query pg_database_size
|
||||||
|
cursor.execute("SELECT pg_database_size(%s)", (self.db_name,))
|
||||||
|
db_size_bytes = self._get_first_value(cursor.fetchone())
|
||||||
|
db_size_mb = round(db_size_bytes / 1024 / 1024, 2) if db_size_bytes else 0
|
||||||
|
else:
|
||||||
|
# SQLite: File size
|
||||||
|
db_size_mb = round(self.db_path.stat().st_size / 1024 / 1024, 2)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"series_count": series_count,
|
"series_count": series_count,
|
||||||
"episodes_total": episodes_total,
|
"episodes_total": episodes_total,
|
||||||
@@ -471,7 +483,8 @@ class NFOGuardDatabase:
|
|||||||
"movies_total": movies_total,
|
"movies_total": movies_total,
|
||||||
"movies_with_video": movies_with_video,
|
"movies_with_video": movies_with_video,
|
||||||
"processing_history_count": history_count,
|
"processing_history_count": history_count,
|
||||||
"database_size_mb": round(self.db_path.stat().st_size / 1024 / 1024, 2)
|
"database_size_mb": db_size_mb,
|
||||||
|
"database_type": self.db_type
|
||||||
}
|
}
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|||||||
@@ -93,7 +93,12 @@ class TVProcessor:
|
|||||||
self.nfo_manager.set_file_mtime(video_file, dateadded)
|
self.nfo_manager.set_file_mtime(video_file, dateadded)
|
||||||
|
|
||||||
# Save to database
|
# Save to database
|
||||||
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
try:
|
||||||
|
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
||||||
|
_log("DEBUG", f"S{season:02d}E{episode:02d}: Database record saved successfully")
|
||||||
|
except Exception as e:
|
||||||
|
_log("ERROR", f"S{season:02d}E{episode:02d}: Database write failed: {e}")
|
||||||
|
# Continue processing other episodes
|
||||||
|
|
||||||
# Yield control every 10 episodes to allow other requests (webhooks, web interface)
|
# Yield control every 10 episodes to allow other requests (webhooks, web interface)
|
||||||
if episode_count % 10 == 0:
|
if episode_count % 10 == 0:
|
||||||
@@ -415,7 +420,12 @@ class TVProcessor:
|
|||||||
self.nfo_manager.set_file_mtime(video_file, dateadded)
|
self.nfo_manager.set_file_mtime(video_file, dateadded)
|
||||||
|
|
||||||
# Save to database
|
# Save to database
|
||||||
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
try:
|
||||||
|
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
||||||
|
_log("DEBUG", f"S{season:02d}E{episode:02d}: Database record saved successfully")
|
||||||
|
except Exception as e:
|
||||||
|
_log("ERROR", f"S{season:02d}E{episode:02d}: Database write failed: {e}")
|
||||||
|
# Continue processing other episodes
|
||||||
processed_count += 1
|
processed_count += 1
|
||||||
|
|
||||||
_log("INFO", f"Processed {processed_count} episodes in season {season_num}")
|
_log("INFO", f"Processed {processed_count} episodes in season {season_num}")
|
||||||
@@ -556,7 +566,12 @@ class TVProcessor:
|
|||||||
mtime_operations.append((video_file, dateadded))
|
mtime_operations.append((video_file, dateadded))
|
||||||
|
|
||||||
# Save to database
|
# Save to database
|
||||||
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
try:
|
||||||
|
self.db.upsert_episode_date(imdb_id, season, episode, aired, dateadded, source, True)
|
||||||
|
_log("DEBUG", f"S{season:02d}E{episode:02d}: Database record saved successfully")
|
||||||
|
except Exception as e:
|
||||||
|
_log("ERROR", f"S{season:02d}E{episode:02d}: Database write failed: {e}")
|
||||||
|
# Continue processing other episodes
|
||||||
|
|
||||||
# Process NFOs and mtimes concurrently
|
# Process NFOs and mtimes concurrently
|
||||||
results = {}
|
results = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user