From 7ec03299263956f73bf9376f8ad2264c5792eb1a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 17 Jun 2022 01:28:26 +0200 Subject: [PATCH] add additional logging for spotify --- music_assistant/helpers/audio.py | 6 +++-- music_assistant/helpers/process.py | 26 ++++++++++++---------- music_assistant/music_providers/spotify.py | 14 +++++++++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/music_assistant/helpers/audio.py b/music_assistant/helpers/audio.py index a9d7af02..152f3038 100644 --- a/music_assistant/helpers/audio.py +++ b/music_assistant/helpers/audio.py @@ -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( diff --git a/music_assistant/helpers/process.py b/music_assistant/helpers/process.py index 95263786..b368a28d 100644 --- a/music_assistant/helpers/process.py +++ b/music_assistant/helpers/process.py @@ -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() diff --git a/music_assistant/music_providers/spotify.py b/music_assistant/music_providers/spotify.py index 31b4b8c4..268b8a81 100644 --- a/music_assistant/music_providers/spotify.py +++ b/music_assistant/music_providers/spotify.py @@ -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.""" -- 2.34.1