add additional logging for spotify
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 16 Jun 2022 23:28:26 +0000 (01:28 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 16 Jun 2022 23:28:26 +0000 (01:28 +0200)
music_assistant/helpers/audio.py
music_assistant/helpers/process.py
music_assistant/music_providers/spotify.py

index a9d7af0269e7add8a197744960b5ec36a376d5ca..152f3038996b00ddb06043f7ab389070d49748dc 100644 (file)
@@ -190,7 +190,9 @@ async def analyze_audio(mass: MusicAssistant, streamdetails: StreamDetails) -> N
         "null",
         "-",
     ]
-    async with AsyncProcess(proc_args, True, use_stderr=True) as ffmpeg_proc:
+    async with AsyncProcess(
+        proc_args, True, enable_stdout=False, enable_stderr=True
+    ) as ffmpeg_proc:
 
         async def writer():
             """Task that grabs the source audio and feeds it to ffmpeg."""
@@ -392,7 +394,7 @@ async def get_media_stream(
         streamdetails, pcm_fmt, pcm_sample_rate=sample_rate, pcm_channels=channels
     )
     async with AsyncProcess(
-        args, enable_write=True, chunk_size=chunk_size
+        args, enable_stdin=True, chunk_size=chunk_size
     ) as ffmpeg_proc:
 
         LOGGER.debug(
index 952637869d93e88c119112af372dc8215a4c0d9a..b368a28d8f9a9c5fd4b97e65948a2275aab04924 100644 (file)
@@ -24,18 +24,20 @@ class AsyncProcess:
     def __init__(
         self,
         args: Union[List, str],
-        enable_write: bool = False,
+        enable_stdin: bool = False,
         chunk_size: int = DEFAULT_CHUNKSIZE,
-        use_stderr: bool = False,
+        enable_stdout: bool = True,
+        enable_stderr: bool = False,
     ):
         """Initialize."""
         self._proc = None
         self._args = args
-        self._use_stderr = use_stderr
-        self._enable_write = enable_write
+        self._enable_stdin = enable_stdin
+        self.chunk_size = chunk_size or DEFAULT_CHUNKSIZE
+        self._enable_stdout = enable_stdout
+        self._enable_stderr = enable_stderr
         self._attached_task: asyncio.Task = None
         self.closed = False
-        self.chunk_size = chunk_size or DEFAULT_CHUNKSIZE
 
     async def __aenter__(self) -> "AsyncProcess":
         """Enter context manager."""
@@ -47,18 +49,18 @@ class AsyncProcess:
         if isinstance(args, str):
             self._proc = await asyncio.create_subprocess_shell(
                 args,
-                stdin=asyncio.subprocess.PIPE if self._enable_write else None,
-                stdout=asyncio.subprocess.PIPE if not self._use_stderr else None,
-                stderr=asyncio.subprocess.PIPE if self._use_stderr else None,
+                stdin=asyncio.subprocess.PIPE if self._enable_stdin else None,
+                stdout=asyncio.subprocess.PIPE if self._enable_stdout else None,
+                stderr=asyncio.subprocess.PIPE if self._enable_stderr else None,
                 limit=self.chunk_size * 5,
                 close_fds=True,
             )
         else:
             self._proc = await asyncio.create_subprocess_exec(
                 *args,
-                stdin=asyncio.subprocess.PIPE if self._enable_write else None,
-                stdout=asyncio.subprocess.PIPE if not self._use_stderr else None,
-                stderr=asyncio.subprocess.PIPE if self._use_stderr else None,
+                stdin=asyncio.subprocess.PIPE if self._enable_stdin else None,
+                stdout=asyncio.subprocess.PIPE if self._enable_stdout else None,
+                stderr=asyncio.subprocess.PIPE if self._enable_stderr else None,
                 limit=self.chunk_size * 5,
                 close_fds=True,
             )
@@ -76,7 +78,7 @@ class AsyncProcess:
                 pass
         if self._proc.returncode is None:
             # prevent subprocess deadlocking, read remaining bytes
-            await self._proc.communicate(b"" if self._enable_write else None)
+            await self._proc.communicate(b"" if self._enable_stdin else None)
             if self._proc.returncode is None:
                 # just in case?
                 self._proc.kill()
index 31b4b8c4723380bf4b898c90a7c9ba5f94cd002b..268b8a816a393477bdf7ea9d031ec55fa149b859 100644 (file)
@@ -312,9 +312,17 @@ class SpotifyProvider(MusicProvider):
                 bytes_sent += len(chunk)
         # TEMP: diagnose issues with librespot dump details
         if bytes_sent < 100:
-            async with AsyncProcess(args, use_stderr=True) as librespot_proc:
-                _, stderr = await librespot_proc.communicate()
-            raise AudioError(f"Error getting stream from librespot: {stderr.decode()}")
+            async with AsyncProcess(args, enable_stderr=True) as librespot_proc:
+                stdout, stderr = await librespot_proc.communicate()
+                if len(stdout) > 512000:
+                    yield stdout
+                    return
+            raise AudioError(
+                "Error getting stream from librespot: "
+                f"err: {stderr.decode()} - "
+                f"out: {stdout.decode()} - "
+                f"binary: {librespot}"
+            )
 
     async def _parse_artist(self, artist_obj):
         """Parse spotify artist object to generic layout."""