catch some inner exceptions
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 10 Jun 2019 18:58:48 +0000 (20:58 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 10 Jun 2019 18:58:48 +0000 (20:58 +0200)
music_assistant/modules/http_streamer.py
music_assistant/modules/musicproviders/qobuz.py
music_assistant/modules/musicproviders/spotify.py

index 0c89ee6f32466bcbb8c086f09f57952a6d5ae830..66c9ba1fb1d409e6a9dcb4a5446bb1d9deb1454d 100755 (executable)
@@ -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 '''
index 5ad9689e6ed9dba280623cdaa54d6625288bd781..798670af5ed1f6916d45bfc387ce0be8ce6ca041 100644 (file)
@@ -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 '''
index 7fe22cbcb78c10652b1bdb6c4cf083d6e189176e..9a7b748c2ddb9431b98bc7277205800ce88b4007 100644 (file)
@@ -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 '''