diff --git a/VERSION b/VERSION index 3f684d2..e75da3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.4 +2.3.6 diff --git a/core/database.py b/core/database.py index 304b606..2b17710 100644 --- a/core/database.py +++ b/core/database.py @@ -111,7 +111,9 @@ class NFOGuardDatabase: else: 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): """Initialize PostgreSQL tables""" @@ -464,6 +466,16 @@ class NFOGuardDatabase: cursor.execute("SELECT COUNT(*) FROM processing_history") 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 { "series_count": series_count, "episodes_total": episodes_total, @@ -471,7 +483,8 @@ class NFOGuardDatabase: "movies_total": movies_total, "movies_with_video": movies_with_video, "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): diff --git a/processors/tv_processor.py b/processors/tv_processor.py index 79414c6..f9aaf60 100644 --- a/processors/tv_processor.py +++ b/processors/tv_processor.py @@ -93,7 +93,12 @@ class TVProcessor: self.nfo_manager.set_file_mtime(video_file, dateadded) # 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) if episode_count % 10 == 0: @@ -415,7 +420,12 @@ class TVProcessor: self.nfo_manager.set_file_mtime(video_file, dateadded) # 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 _log("INFO", f"Processed {processed_count} episodes in season {season_num}") @@ -556,7 +566,12 @@ class TVProcessor: mtime_operations.append((video_file, dateadded)) # 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 results = {}