''' 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 '''
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 '''
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 '''