From: Marcel van der Veldt Date: Mon, 10 Jun 2019 18:58:48 +0000 (+0200) Subject: catch some inner exceptions X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=f2b434ff7954d4071f509473ab60b57a823b1f69;p=music-assistant-server.git catch some inner exceptions --- diff --git a/music_assistant/modules/http_streamer.py b/music_assistant/modules/http_streamer.py index 0c89ee6f..66c9ba1f 100755 --- a/music_assistant/modules/http_streamer.py +++ b/music_assistant/modules/http_streamer.py @@ -455,20 +455,24 @@ class HTTPStreamer(): ''' get audio data from provider and write to buffer''' # fill the buffer with audio data # a tempfile is created so we can do audio analysis - tmpfile = os.path.join(AUDIO_TEMP_DIR, '%s%s%s.tmp' % (random.randint(0, 999), track_id, random.randint(0, 999))) - fd = open(tmpfile, 'wb') - async for chunk in self.mass.music.providers[provider].get_audio_stream(track_id): - buf.write(chunk) + try: + tmpfile = os.path.join(AUDIO_TEMP_DIR, '%s%s%s.tmp' % (random.randint(0, 999), track_id, random.randint(0, 999))) + fd = open(tmpfile, 'wb') + async for chunk in self.mass.music.providers[provider].get_audio_stream(track_id): + buf.write(chunk) + await buf.drain() + fd.write(chunk) await buf.drain() - fd.write(chunk) - await buf.drain() - buf.write_eof() - fd.close() - LOGGER.info("fill_audio_buffer complete for track %s" % track_id) - # successfull completion, process temp file for analysis - self.mass.event_loop.create_task( - self.__analyze_audio(tmpfile, track_id, provider, content_type)) - return + LOGGER.info("fill_audio_buffer complete for track %s" % track_id) + # successfull completion, process temp file for analysis + self.mass.event_loop.create_task( + self.__analyze_audio(tmpfile, track_id, provider, content_type)) + except Exception as exc: + LOGGER.exception("fill_audio_buffer failed for track %s" % track_id) + finally: + buf.write_eof() + await buf.drain() + fd.close() def __get_track_cache_filename(self, track_id, provider): ''' get filename for a track to use as cache file ''' diff --git a/music_assistant/modules/musicproviders/qobuz.py b/music_assistant/modules/musicproviders/qobuz.py index 5ad9689e..798670af 100644 --- a/music_assistant/modules/musicproviders/qobuz.py +++ b/music_assistant/modules/musicproviders/qobuz.py @@ -265,13 +265,16 @@ class QobuzProvider(MusicProvider): self.mass.event_loop ) streamdetails = streamdetails_future.result() - async with aiohttp.ClientSession(loop=asyncio.get_event_loop(), connector=aiohttp.TCPConnector(verify_ssl=False)) as session: - async with session.get(streamdetails['url']) as resp: - while True: - chunk = await resp.content.read(64000) - if not chunk: - break - yield chunk + try: + async with aiohttp.ClientSession(loop=asyncio.get_event_loop(), connector=aiohttp.TCPConnector(verify_ssl=False)) as session: + async with session.get(streamdetails['url']) as resp: + while True: + chunk = await resp.content.read(64000) + yield chunk + if not chunk: + break + except Exception as exc: + LOGGER.exception(exc) async def __parse_artist(self, artist_obj): ''' parse spotify artist object to generic layout ''' diff --git a/music_assistant/modules/musicproviders/spotify.py b/music_assistant/modules/musicproviders/spotify.py index 7fe22cbc..9a7b748c 100644 --- a/music_assistant/modules/musicproviders/spotify.py +++ b/music_assistant/modules/musicproviders/spotify.py @@ -248,16 +248,19 @@ class SpotifyProvider(MusicProvider): async def get_audio_stream(self, track_id): ''' get audio stream for a track ''' - import subprocess - spotty = self.get_spotty_binary() - args = ['-n', 'temp', '-u', self._username, '-p', self._password, '--pass-through', '--single-track', track_id] - process = await asyncio.create_subprocess_exec(spotty, *args, stdout=asyncio.subprocess.PIPE) - while not process.stdout.at_eof(): - chunk = await process.stdout.read(32000) - if not chunk: - break - yield chunk - await process.wait() + try: + import subprocess + spotty = self.get_spotty_binary() + args = ['-n', 'temp', '-u', self._username, '-p', self._password, '--pass-through', '--single-track', track_id] + process = await asyncio.create_subprocess_exec(spotty, *args, stdout=asyncio.subprocess.PIPE) + while not process.stdout.at_eof(): + chunk = await process.stdout.read(32000) + if not chunk: + break + yield chunk + await process.wait() + except Exception as exc: + LOGGER.exception(exc) async def __parse_artist(self, artist_obj): ''' parse spotify artist object to generic layout '''