From ee2347769853c50c59f301f63918c4304141d159 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 16 Jun 2019 00:24:39 +0200 Subject: [PATCH] small fixes fix radio and some other small stuff --- music_assistant/modules/http_streamer.py | 12 +++++++++--- music_assistant/modules/musicproviders/qobuz.py | 1 + .../modules/playerproviders/chromecast.py | 11 ++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/music_assistant/modules/http_streamer.py b/music_assistant/modules/http_streamer.py index 552d4def..83c451e2 100755 --- a/music_assistant/modules/http_streamer.py +++ b/music_assistant/modules/http_streamer.py @@ -94,6 +94,11 @@ class HTTPStreamer(): 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"] @@ -104,9 +109,9 @@ class HTTPStreamer(): 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: @@ -314,6 +319,7 @@ class HTTPStreamer(): 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': @@ -449,5 +455,5 @@ class HTTPStreamer(): 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 diff --git a/music_assistant/modules/musicproviders/qobuz.py b/music_assistant/modules/musicproviders/qobuz.py index ee0a781a..f4c94a0d 100644 --- a/music_assistant/modules/musicproviders/qobuz.py +++ b/music_assistant/modules/musicproviders/qobuz.py @@ -275,6 +275,7 @@ class QobuzProvider(MusicProvider): 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"]) diff --git a/music_assistant/modules/playerproviders/chromecast.py b/music_assistant/modules/playerproviders/chromecast.py index 486a5aa4..a4ccdc5d 100644 --- a/music_assistant/modules/playerproviders/chromecast.py +++ b/music_assistant/modules/playerproviders/chromecast.py @@ -128,18 +128,19 @@ class ChromecastProvider(PlayerProvider): 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) @@ -150,7 +151,7 @@ class ChromecastProvider(PlayerProvider): 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: @@ -161,7 +162,7 @@ class ChromecastProvider(PlayerProvider): 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): @@ -192,7 +193,7 @@ class ChromecastProvider(PlayerProvider): 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", -- 2.34.1