qobuz stream request seems to fail sometimes
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 10 Jun 2019 20:39:06 +0000 (22:39 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 10 Jun 2019 20:39:06 +0000 (22:39 +0200)
music_assistant/modules/musicproviders/qobuz.py
music_assistant/modules/musicproviders/spotify.py

index 95893475c8b417338fb8977648a5e96d50c0e5b4..1994ae2342d5d2194fb38d9fbcf8e8004c641e0c 100644 (file)
@@ -265,13 +265,20 @@ class QobuzProvider(MusicProvider):
             self.mass.event_loop
         )
         streamdetails = streamdetails_future.result()
-        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:
-                    async for data, end_of_http_chunk in resp.content.iter_chunks():
-                        yield data
-        except Exception as exc:
-            LOGGER.exception(exc)
+        if not streamdetails:
+            # simply retry this request
+            await asyncio.sleep(1)
+            streamdetails_future = asyncio.run_coroutine_threadsafe(
+                self.__get_data('track/getFileUrl', params, sign_request=True, ignore_cache=True),
+                self.mass.event_loop
+            )
+            streamdetails = streamdetails_future.result()
+        if not streamdetails:
+            raise Exception("Unable to retrieve stream url for track %s" % track_id)
+        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:
+                async for data, end_of_http_chunk in resp.content.iter_chunks():
+                    yield data
     
     async def __parse_artist(self, artist_obj):
         ''' parse spotify artist object to generic layout '''
index 9a7b748c2ddb9431b98bc7277205800ce88b4007..7fe22cbcb78c10652b1bdb6c4cf083d6e189176e 100644 (file)
@@ -248,19 +248,16 @@ class SpotifyProvider(MusicProvider):
 
     async def get_audio_stream(self, track_id):
         ''' get audio stream for a track '''
-        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)
+        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()
         
     async def __parse_artist(self, artist_obj):
         ''' parse spotify artist object to generic layout '''