From 822568a2d51ba5111db4aea20718b996d9ab6977 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 12 Mar 2026 11:17:32 -0700 Subject: [PATCH] Fix automated scans for non-Plex servers & incremental scan performance --- core/database_update_worker.py | 5 +++- core/media_scan_manager.py | 53 ++++++++++++++-------------------- core/web_scan_manager.py | 12 +++----- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/core/database_update_worker.py b/core/database_update_worker.py index 4b63396a..5bb1aadc 100644 --- a/core/database_update_worker.py +++ b/core/database_update_worker.py @@ -229,7 +229,10 @@ class DatabaseUpdateWorker(QThread): logger.warning(f"Could not clear {self.server_type} cache: {e}") # Detect and remove content deleted from the media server - if not self.full_refresh and self.database: + # Only run on full refreshes — fetching the entire catalog on every + # incremental scan is too expensive (especially for Plex) and unnecessary + # since incremental scans add content, they don't detect removals. + if self.full_refresh and self.database: try: removal_results = self._detect_and_remove_stale_content() if removal_results: diff --git a/core/media_scan_manager.py b/core/media_scan_manager.py index 16acb7d8..2b2e674d 100644 --- a/core/media_scan_manager.py +++ b/core/media_scan_manager.py @@ -65,25 +65,18 @@ class MediaScanManager: break if main_window: - if active_server == "jellyfin": - client = getattr(main_window, 'jellyfin_client', None) + server_attr_map = { + 'jellyfin': 'jellyfin_client', + 'navidrome': 'navidrome_client', + 'plex': 'plex_client' + } + client_attr = server_attr_map.get(active_server) + if client_attr: + client = getattr(main_window, client_attr, None) if client and client.is_connected(): - return client, "jellyfin" + return client, active_server else: - logger.warning("Jellyfin client not connected, falling back to Plex") - elif active_server == "navidrome": - client = getattr(main_window, 'navidrome_client', None) - if client and client.is_connected(): - return client, "navidrome" - else: - logger.warning("Navidrome client not connected, falling back to Plex") - - # Default to Plex or fallback - client = getattr(main_window, 'plex_client', None) - if client and client.is_connected(): - return client, "plex" - else: - logger.debug(f"Plex client not connected or not found") + logger.warning(f"{active_server.title()} client not connected — scan skipped") else: logger.debug("No main window found in Qt application") else: @@ -94,21 +87,19 @@ class MediaScanManager: # Headless mode - try to get clients from global instances import sys - for module_name, module in sys.modules.items(): - if (hasattr(module, 'plex_client') and hasattr(module, 'jellyfin_client') and - hasattr(module, 'navidrome_client')): - if active_server == "jellyfin": - client = getattr(module, 'jellyfin_client', None) + server_attr_map = { + 'jellyfin': 'jellyfin_client', + 'navidrome': 'navidrome_client', + 'plex': 'plex_client' + } + client_attr = server_attr_map.get(active_server) + if client_attr: + for module_name, module in sys.modules.items(): + if hasattr(module, client_attr): + client = getattr(module, client_attr, None) if client and hasattr(client, 'is_connected') and client.is_connected(): - return client, "jellyfin" - elif active_server == "navidrome": - client = getattr(module, 'navidrome_client', None) - if client and hasattr(client, 'is_connected') and client.is_connected(): - return client, "navidrome" - - client = getattr(module, 'plex_client', None) - if client and hasattr(client, 'is_connected') and client.is_connected(): - return client, "plex" + return client, active_server + break except Exception as e: logger.debug(f"Could not access clients: {e}") diff --git a/core/web_scan_manager.py b/core/web_scan_manager.py index 824aa16d..55eb17cf 100644 --- a/core/web_scan_manager.py +++ b/core/web_scan_manager.py @@ -53,21 +53,17 @@ class WebScanManager: 'plex': 'plex_client' } - # Try to get the configured active server first + # Try to get the configured active server if active_server in server_client_map: client_key = server_client_map[active_server] client = self.media_clients.get(client_key) if client and hasattr(client, 'is_connected') and client.is_connected(): return client, active_server else: - logger.warning(f"{active_server.title()} client not connected, falling back to Plex") + logger.warning(f"{active_server.title()} client not connected — scan skipped") + return None, None - # Fallback to Plex - plex_client = self.media_clients.get('plex_client') - if plex_client and hasattr(plex_client, 'is_connected') and plex_client.is_connected(): - return plex_client, "plex" - - logger.error("No active media client available for scanning") + logger.error("No active media server configured for scanning") return None, None except Exception as e: