From: Marcel van der Veldt Date: Mon, 10 Jun 2019 20:39:06 +0000 (+0200) Subject: qobuz stream request seems to fail sometimes X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=de5bda16a5364902f27cf4b726802b47ccdb238a;p=music-assistant-server.git qobuz stream request seems to fail sometimes --- diff --git a/music_assistant/modules/musicproviders/qobuz.py b/music_assistant/modules/musicproviders/qobuz.py index 95893475..1994ae23 100644 --- a/music_assistant/modules/musicproviders/qobuz.py +++ b/music_assistant/modules/musicproviders/qobuz.py @@ -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 ''' diff --git a/music_assistant/modules/musicproviders/spotify.py b/music_assistant/modules/musicproviders/spotify.py index 9a7b748c..7fe22cbc 100644 --- a/music_assistant/modules/musicproviders/spotify.py +++ b/music_assistant/modules/musicproviders/spotify.py @@ -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 '''