if http_request.method.upper() != 'HEAD':
# stream audio with sox
sox_effects = await self.__get_player_sox_options(radio_id, provider, player_id, True)
+ if self.mass.config['base']['http_streamer']['volume_normalisation']:
+ gain_correct = await self.__get_track_gain_correct(radio_id, provider)
+ gain_correct = 'vol %s dB ' % gain_correct
+ else:
+ gain_correct = ''
media_item = await self.mass.music.item(radio_id, MediaType.Radio, provider)
stream = sorted(media_item.provider_ids, key=operator.itemgetter('quality'), reverse=True)[0]
stream_url = stream["details"]
else:
input_content_type = "mp3"
if input_content_type == "aac":
- args = 'ffmpeg -i "%s" -f flac - | sox -t flac - -t flac -C 0 - %s' % (stream_url, sox_effects)
+ args = 'ffmpeg -i "%s" -f flac - | sox -t flac - -t flac -C 0 - %s %s' % (stream_url, gain_correct, sox_effects)
else:
- args = 'sox -t %s "%s" -t flac -C 0 - %s' % (input_content_type, stream_url, sox_effects)
+ args = 'sox -t %s "%s" -t flac -C 0 - %s %s' % (input_content_type, stream_url, gain_correct, sox_effects)
LOGGER.info("Running sox with args: %s" % args)
process = await asyncio.create_subprocess_shell(args, stdout=asyncio.subprocess.PIPE)
try:
if not streamdetails:
yield b''
return
+ # TODO: add support for AAC streams (which sox doesn't natively support)
if streamdetails['type'] == 'url':
args = 'sox -t %s "%s" -t %s - %s %s' % (streamdetails["content_type"], streamdetails["path"], outputfmt, gain_correct, sox_effects)
elif streamdetails['type'] == 'executable':
process = await asyncio.create_subprocess_shell(args,
stdout=asyncio.subprocess.PIPE, stdin=asyncio.subprocess.PIPE)
crossfade_part, stderr = await process.communicate()
- LOGGER.info("Got %s bytes in memory for crossfade_part after sox" % len(crossfade_part))
+ LOGGER.debug("Got %s bytes in memory for crossfade_part after sox" % len(crossfade_part))
return crossfade_part
async def mass_event(self, msg, msg_details):
''' received event from mass '''
+ # TODO: need to figure out if the streamed track is purchased
if msg == "streaming_started" and msg_details['provider'] == self.prov_id:
# report streaming started to qobuz
LOGGER.debug("streaming_started %s" % msg_details["track_id"])
castplayer = self._chromecasts[player_id]
cur_queue_index = self._player_queue_index.get(player_id, 0)
enable_crossfade = self.mass.config['player_settings'][player_id]["crossfade_duration"] > 0
+ is_radio = media_items[0].media_type == MediaType.Radio
if queue_opt == 'replace' or not self._player_queue[player_id]:
# overwrite queue with new items
self._player_queue[player_id] = media_items
- if enable_crossfade:
+ if enable_crossfade and not is_radio:
await self.__play_stream_queue(player_id, cur_queue_index)
else:
await self.__queue_load(player_id, self._player_queue[player_id], 0)
elif queue_opt == 'play':
# replace current item with new item(s)
self._player_queue[player_id] = self._player_queue[player_id][:cur_queue_index] + media_items + self._player_queue[player_id][cur_queue_index+1:]
- if enable_crossfade:
+ if enable_crossfade and not is_radio:
await self.__play_stream_queue(player_id, cur_queue_index)
else:
await self.__queue_load(player_id, self._player_queue[player_id], cur_queue_index)
else:
old_next_uri = None
self._player_queue[player_id] = self._player_queue[player_id][:cur_queue_index+1] + media_items + self._player_queue[player_id][cur_queue_index+1:]
- if not enable_crossfade:
+ if not enable_crossfade or is_radio:
# find out the itemID of the next item in CC queue
insert_at_item_id = None
if old_next_uri:
elif queue_opt == 'add':
# add new items at end of queue
self._player_queue[player_id] = self._player_queue[player_id] + media_items
- if not enable_crossfade:
+ if not enable_crossfade or is_radio:
await self.__queue_insert(player_id, media_items)
async def player_queue_stream_update(self, player_id, cur_index, is_start=False):
castplayer = self._chromecasts[player_id]
player = self._players[player_id]
queue_items = await self.__create_queue_items(new_tracks[:50])
- self.mass.player._players[player_id].cur_queue_index = 0
+ self._player_queue_index[player_id] = 0
queuedata = {
"type": 'QUEUE_LOAD',
"repeatMode": "REPEAT_ALL" if player.repeat_enabled else "REPEAT_OFF",