small fix for spotify login
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 27 Feb 2024 08:55:54 +0000 (09:55 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Tue, 27 Feb 2024 08:55:54 +0000 (09:55 +0100)
music_assistant/server/providers/spotify/__init__.py

index 4c3152fbb7448b83527000c13b94df9706efea91..dbed1bfe0ebb71754bdc688a0947ff55a27b4eb6 100644 (file)
@@ -597,7 +597,7 @@ class SpotifyProvider(MusicProvider):
             raise LoginFailed(msg)
         # retrieve token with librespot
         retries = 0
-        while retries < 20:
+        while retries < 5:
             try:
                 retries += 1
                 if not tokeninfo:
@@ -651,8 +651,14 @@ class SpotifyProvider(MusicProvider):
             "-p",
             self.config.get_value(CONF_PASSWORD),
         ]
-        librespot = await asyncio.create_subprocess_exec(*args)
-        await librespot.wait()
+        if self._ap_workaround:
+            args += ["--ap-port", "12345"]
+        librespot = await asyncio.create_subprocess_exec(
+            *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT
+        )
+        stdout, _ = await librespot.communicate()
+        if stdout.decode().strip() != "authorized":
+            raise LoginFailed(f"Login failed for username {self.config.get_value(CONF_USERNAME)}")
         # get token with (authorized) librespot
         scopes = [
             "user-read-playback-state",