Fix automated scans for non-Plex servers & incremental scan performance
This commit is contained in:
parent
dc9a8a3845
commit
822568a2d5
3 changed files with 30 additions and 40 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue