From: Fabian Munkes <105975993+fmunkes@users.noreply.github.com> Date: Fri, 28 Feb 2025 17:44:19 +0000 (+0100) Subject: ABS: Login via API key (#1990) X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=bd6786d73534902ff7333d8e08d28fe6c6059c80;p=music-assistant-server.git ABS: Login via API key (#1990) --- diff --git a/music_assistant/providers/audiobookshelf/__init__.py b/music_assistant/providers/audiobookshelf/__init__.py index 5b9cba5b..30fc66b3 100644 --- a/music_assistant/providers/audiobookshelf/__init__.py +++ b/music_assistant/providers/audiobookshelf/__init__.py @@ -55,6 +55,7 @@ from .constants import ( CACHE_KEY_LIBRARIES, CONF_HIDE_EMPTY_PODCASTS, CONF_PASSWORD, + CONF_TOKEN, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL, @@ -97,6 +98,14 @@ async def get_config_entries( """ # ruff: noqa: ARG001 return ( + ConfigEntry( + key="label", + type=ConfigEntryType.LABEL, + label="Please provide the address of your Audiobookshelf instance. To authenticate " + "you have two options: " + "a) Provide username AND password. Leave token empty." + "b) Provide ONLY the token.", + ), ConfigEntry( key=CONF_URL, type=ConfigEntryType.STRING, @@ -108,7 +117,7 @@ async def get_config_entries( key=CONF_USERNAME, type=ConfigEntryType.STRING, label="Username", - required=True, + required=False, description="The username to authenticate to the remote server.", ), ConfigEntry( @@ -118,6 +127,14 @@ async def get_config_entries( required=False, description="The password to authenticate to the remote server.", ), + ConfigEntry( + key=CONF_TOKEN, + type=ConfigEntryType.SECURE_STRING, + label="Token _instead_ of user/ password.", + required=False, + description="Instead of using username and password, you may provide the user's token." + "\nThe token can be seen in Audiobookshelf as an admin user in Settings -> Users.", + ), ConfigEntry( key=CONF_VERIFY_SSL, type=ConfigEntryType.BOOLEAN, @@ -156,6 +173,7 @@ class Audiobookshelf(MusicProvider): base_url = str(self.config.get_value(CONF_URL)) username = str(self.config.get_value(CONF_USERNAME)) password = str(self.config.get_value(CONF_PASSWORD)) + token = self.config.get_value(CONF_TOKEN) verify_ssl = bool(self.config.get_value(CONF_VERIFY_SSL)) session_config = aioabs.SessionConfiguration( session=self.mass.http_session, @@ -165,9 +183,16 @@ class Audiobookshelf(MusicProvider): pagination_items_per_page=30, # audible provider goes with 50 for pagination ) try: - self._client, self._client_socket = await aioabs.get_user_and_socket_client( - session_config=session_config, username=username, password=password - ) + if token is not None: + session_config.token = str(token) + ( + self._client, + self._client_socket, + ) = await aioabs.get_user_and_socket_client_by_token(session_config=session_config) + else: + self._client, self._client_socket = await aioabs.get_user_and_socket_client( + session_config=session_config, username=username, password=password + ) await self._client_socket.init_client() except AbsLoginError as exc: raise LoginFailed(f"Login to abs instance at {base_url} failed.") from exc diff --git a/music_assistant/providers/audiobookshelf/constants.py b/music_assistant/providers/audiobookshelf/constants.py index e3663b4e..9aba4e6f 100644 --- a/music_assistant/providers/audiobookshelf/constants.py +++ b/music_assistant/providers/audiobookshelf/constants.py @@ -6,6 +6,7 @@ from enum import StrEnum CONF_URL = "url" CONF_USERNAME = "username" CONF_PASSWORD = "password" +CONF_TOKEN = "token" CONF_VERIFY_SSL = "verify_ssl" # optionally hide podcasts with no episodes CONF_HIDE_EMPTY_PODCASTS = "hide_empty_podcasts" diff --git a/music_assistant/providers/audiobookshelf/manifest.json b/music_assistant/providers/audiobookshelf/manifest.json index 444e5954..84f410ec 100644 --- a/music_assistant/providers/audiobookshelf/manifest.json +++ b/music_assistant/providers/audiobookshelf/manifest.json @@ -7,7 +7,7 @@ "@fmunkes" ], "requirements": [ - "aioaudiobookshelf==0.1.2" + "aioaudiobookshelf==0.1.3" ], "documentation": "https://music-assistant.io/music-providers/audiobookshelf", "multi_instance": true diff --git a/requirements_all.txt b/requirements_all.txt index db89d3d1..1aaebb51 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1,7 +1,7 @@ # WARNING: this file is autogenerated! Brotli>=1.0.9 -aioaudiobookshelf==0.1.2 +aioaudiobookshelf==0.1.3 aiodns>=3.2.0 aiofiles==24.1.0 aiohttp==3.11.12