Tweak for spotify streamer
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 7 Dec 2025 23:51:35 +0000 (00:51 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 7 Dec 2025 23:52:41 +0000 (00:52 +0100)
music_assistant/providers/spotify/streaming.py

index bb8bf7464c667c8792653e3fa7c5f0a54e832641..6c2b824f08d7523aa389c270f2d1a972dfa6052d 100644 (file)
@@ -81,27 +81,18 @@ class LibrespotStreamer:
                     log_history.append(line)
                     if "ERROR" in line or "WARNING" in line:
                         logger.warning("[librespot] %s", line)
+                        if "Unable to read audio file" in line:
+                            # if this happens, we should stop the process to avoid hanging
+                            await librespot_proc.close()
                     else:
                         logger.log(VERBOSE_LOG_LEVEL, "[librespot] %s", line)
 
             librespot_proc.attach_stderr_reader(asyncio.create_task(log_librespot_output()))
+            # yield from librespot's stdout
+            async for chunk in librespot_proc.iter_chunked():
+                yield chunk
 
-            try:
-                # yield from librespot's stdout
-                async for chunk in librespot_proc.iter_chunked():
-                    yield chunk
-
-                if librespot_proc.returncode != 0:
-                    raise AudioError(
-                        f"Librespot exited with code {librespot_proc.returncode} for {spotify_uri}"
-                    )
-
-            except Exception as ex:
-                log_lines_str = "\n".join(log_history)
-                logger.error(
-                    "Librespot streaming error for %s: %s\n%s",
-                    spotify_uri,
-                    ex,
-                    log_lines_str,
+            if librespot_proc.returncode != 0:
+                raise AudioError(
+                    f"Librespot exited with code {librespot_proc.returncode} for {spotify_uri}"
                 )
-                raise AudioError(f"Error streaming from librespot for {spotify_uri}: {ex}") from ex