Audible: fixed popup flow, disabled internal cache. (#1880)
authorZtripez <reg@otherland.nu>
Thu, 16 Jan 2025 17:36:38 +0000 (18:36 +0100)
committerGitHub <noreply@github.com>
Thu, 16 Jan 2025 17:36:38 +0000 (18:36 +0100)
music_assistant/providers/audible/__init__.py
music_assistant/providers/audible/audible_helper.py

index 4d4d3c351799c67e9ddb94abc89430b3070bc803..e7d8820faa79569b687a1d2b67d5c7d982541237 100644 (file)
@@ -4,7 +4,6 @@ from __future__ import annotations
 
 import asyncio
 import os
-import webbrowser
 from collections.abc import AsyncGenerator
 from logging import getLevelName
 from typing import TYPE_CHECKING, cast
@@ -17,7 +16,7 @@ from music_assistant_models.config_entries import (
     ConfigValueType,
     ProviderConfig,
 )
-from music_assistant_models.enums import ConfigEntryType, MediaType, ProviderFeature
+from music_assistant_models.enums import ConfigEntryType, EventType, MediaType, ProviderFeature
 from music_assistant_models.errors import LoginFailed
 
 from music_assistant.models.music_provider import MusicProvider
@@ -111,7 +110,9 @@ async def get_config_entries(
         values[CONF_CODE_VERIFIER] = code_verifier
         values[CONF_SERIAL] = serial
         values[CONF_LOGIN_URL] = login_url
-        webbrowser.open_new_tab(login_url)
+        session_id = str(values["session_id"])
+        mass.signal_event(EventType.AUTH_SESSION, session_id, login_url)
+        await asyncio.sleep(15)
 
     if action == CONF_ACTION_VERIFY:
         code_verifier = str(values.get(CONF_CODE_VERIFIER))
index d8682cfc9cd4ccda5166c16e20da6b05a006990f..37bcfcb940759d2988e36e270d045610fd733ba8 100644 (file)
@@ -74,6 +74,7 @@ class AudibleHelper:
         while True:
             library = await self._call_api(
                 "library",
+                use_cache=False,
                 response_groups=",".join(response_groups),
                 page=page,
                 num_results=page_size,
@@ -204,13 +205,15 @@ class AudibleHelper:
         """Report last position."""
 
     async def _call_api(self, path: str, **kwargs: Any) -> Any:
+        response = None
+        use_cache = False
         params_str = json.dumps(kwargs, sort_keys=True)
         params_hash = hashlib.md5(params_str.encode()).hexdigest()
         cache_key_with_params = f"{path}:{params_hash}"
-
-        response = await self.mass.cache.get(
-            key=cache_key_with_params, base_key=CACHE_DOMAIN, category=CACHE_CATEGORY_API
-        )
+        if use_cache:
+            response = await self.mass.cache.get(
+                key=cache_key_with_params, base_key=CACHE_DOMAIN, category=CACHE_CATEGORY_API
+            )
         if not response:
             response = await self.client.get(path, **kwargs)
             await self.mass.cache.set(