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}")
|
logger.warning(f"Could not clear {self.server_type} cache: {e}")
|
||||||
|
|
||||||
# Detect and remove content deleted from the media server
|
# 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:
|
try:
|
||||||
removal_results = self._detect_and_remove_stale_content()
|
removal_results = self._detect_and_remove_stale_content()
|
||||||
if removal_results:
|
if removal_results:
|
||||||
|
|
|
||||||
|
|
@ -65,25 +65,18 @@ class MediaScanManager:
|
||||||
break
|
break
|
||||||
|
|
||||||
if main_window:
|
if main_window:
|
||||||
if active_server == "jellyfin":
|
server_attr_map = {
|
||||||
client = getattr(main_window, 'jellyfin_client', None)
|
'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():
|
if client and client.is_connected():
|
||||||
return client, "jellyfin"
|
return client, active_server
|
||||||
else:
|
else:
|
||||||
logger.warning("Jellyfin client not connected, falling back to Plex")
|
logger.warning(f"{active_server.title()} client not connected — scan skipped")
|
||||||
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")
|
|
||||||
else:
|
else:
|
||||||
logger.debug("No main window found in Qt application")
|
logger.debug("No main window found in Qt application")
|
||||||
else:
|
else:
|
||||||
|
|
@ -94,21 +87,19 @@ class MediaScanManager:
|
||||||
|
|
||||||
# Headless mode - try to get clients from global instances
|
# Headless mode - try to get clients from global instances
|
||||||
import sys
|
import sys
|
||||||
for module_name, module in sys.modules.items():
|
server_attr_map = {
|
||||||
if (hasattr(module, 'plex_client') and hasattr(module, 'jellyfin_client') and
|
'jellyfin': 'jellyfin_client',
|
||||||
hasattr(module, 'navidrome_client')):
|
'navidrome': 'navidrome_client',
|
||||||
if active_server == "jellyfin":
|
'plex': 'plex_client'
|
||||||
client = getattr(module, 'jellyfin_client', None)
|
}
|
||||||
|
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():
|
if client and hasattr(client, 'is_connected') and client.is_connected():
|
||||||
return client, "jellyfin"
|
return client, active_server
|
||||||
elif active_server == "navidrome":
|
break
|
||||||
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"
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Could not access clients: {e}")
|
logger.debug(f"Could not access clients: {e}")
|
||||||
|
|
|
||||||
|
|
@ -53,21 +53,17 @@ class WebScanManager:
|
||||||
'plex': 'plex_client'
|
'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:
|
if active_server in server_client_map:
|
||||||
client_key = server_client_map[active_server]
|
client_key = server_client_map[active_server]
|
||||||
client = self.media_clients.get(client_key)
|
client = self.media_clients.get(client_key)
|
||||||
if client and hasattr(client, 'is_connected') and client.is_connected():
|
if client and hasattr(client, 'is_connected') and client.is_connected():
|
||||||
return client, active_server
|
return client, active_server
|
||||||
else:
|
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
|
logger.error("No active media server configured for scanning")
|
||||||
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")
|
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue