Skip to content

Commit

Permalink
[122] Query connection libraries on boot
Browse files Browse the repository at this point in the history
Add to preferences model
  • Loading branch information
CollinHeist committed Oct 30, 2024
1 parent b51011f commit 9cd06f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/internal/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
)
from modules.Debug import Logger, log
from modules.Debug2 import SECRETS
from modules.EmbyInterface2 import EmbyInterface
from modules.InterfaceGroup import InterfaceGroup
from modules.JellyfinInterface2 import JellyfinInterface
from modules.PlexInterface2 import PlexInterface


_MediaServerInterface = (EmbyInterface, JellyfinInterface, PlexInterface)
_NewConnection = Union[
NewEmbyConnection, NewJellyfinConnection, NewPlexConnection,
NewSonarrConnection, NewTMDbConnection, NewTVDbConnection,
Expand Down Expand Up @@ -93,6 +97,11 @@ def initialize_connections(
interface_group.initialize_interface(
connection.id, connection.interface_kwargs, log=log,
)
interface = interface_group[connection.id]
if isinstance(interface, _MediaServerInterface):
preferences.libraries[connection.id] = interface.get_libraries()
log.trace(f'Preferences.libraries[{connection.id}] = '
f'{preferences.libraries[connection.id]}')
except Exception:
preferences.invalid_connections.append(connection.id)
log.exception(f'Error initializing {connection}')
Expand Down
8 changes: 5 additions & 3 deletions app/models/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Preferences:
'is_docker', 'file', 'asset_directory', 'card_type_directory',
'remote_card_types', 'local_card_types', 'invalid_connections',
'currently_running_sync', 'current_db_schema', 'current_version',
'server_boot_time',
'server_boot_time', 'libraries',
)

__slots__ = (
Expand Down Expand Up @@ -126,6 +126,7 @@ class Preferences:
'display_live_messages',
'source_preview_page_dimensions',
'title_card_preview_page_dimensions',
'libraries',
)


Expand Down Expand Up @@ -171,7 +172,7 @@ def __init__(self, file: Path) -> None:
self.blacklisted_blueprints: set[int] = set()


def __getstate__(self) -> dict:
def __getstate__(self) -> dict[str, Any]:
"""
Get the state definition of this object for pickling. This
is all attributes except `remote_card_types`.
Expand All @@ -191,7 +192,7 @@ def __getstate__(self) -> dict:
}


def __setstate__(self, state: dict) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
"""
Set the state of this object from the pickled representation.
Expand Down Expand Up @@ -262,6 +263,7 @@ def __initialize_defaults(self) -> None:
self.use_sonarr = False
self.use_tmdb = False
self.use_tvdb = False
self.libraries: dict[int, list[str]] = {}

self.use_magick_prefix = False
self.blacklisted_blueprints: set[int] = set()
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version_webui
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0-alpha.12.1-webui121
v2.0-alpha.12.1-webui122

0 comments on commit 9cd06f5

Please sign in to comment.