Skip to content

Commit

Permalink
Fixes for slimproto cli and wiim pro streamers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Nov 23, 2023
1 parent 6f12531 commit 75a6a9b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
8 changes: 6 additions & 2 deletions music_assistant/server/providers/chromecast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from music_assistant.common.models.errors import PlayerUnavailableError, QueueEmpty
from music_assistant.common.models.player import DeviceInfo, Player
from music_assistant.common.models.queue_item import QueueItem
from music_assistant.constants import CONF_PLAYERS, MASS_LOGO_ONLINE
from music_assistant.constants import CONF_LOG_LEVEL, CONF_PLAYERS, MASS_LOGO_ONLINE
from music_assistant.server.models.player_provider import PlayerProvider

from .helpers import CastStatusListener, ChromecastInfo
Expand Down Expand Up @@ -130,7 +130,11 @@ async def handle_setup(self) -> None:
self.mass.zeroconf,
)
# silence pychromecast logging
logging.getLogger("pychromecast").setLevel(self.logger.level)
log_level = self.config.get_value(CONF_LOG_LEVEL)
if log_level == "DEBUG":
logging.getLogger("pychromecast").setLevel(logging.DEBUG)
else:
logging.getLogger("pychromecast").setLevel(logging.INFO)
# start discovery in executor
await self.mass.loop.run_in_executor(None, self.browser.start_discovery)

Expand Down
24 changes: 12 additions & 12 deletions music_assistant/server/providers/slimproto/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,20 +901,20 @@ def _handle_playlist(
next_index = (queue.current_index or 0) - int(arg.split("-")[1])
self.mass.create_task(self.mass.player_queues.play_index, player_id, next_index)
return
if subcommand == "shuffle" and arg == "?":
return queue.shuffle_enabled
if subcommand == "shuffle":
self.mass.player_queues.set_shuffle(queue.queue_id, not queue.shuffle_enabled)
self.mass.player_queues.set_shuffle(queue.queue_id, bool(arg))
return
if subcommand == "repeat" and arg == "?":
return str(REPEATMODE_MAP[queue.repeat_mode])
if subcommand == "repeat":
if queue.repeat_mode == RepeatMode.ALL:
new_repeat_mode = RepeatMode.OFF
elif queue.repeat_mode == RepeatMode.OFF:
new_repeat_mode = RepeatMode.ONE
else:
new_repeat_mode = RepeatMode.ALL
repeat_map = {val: key for key, val in REPEATMODE_MAP.items()}
new_repeat_mode = repeat_map.get(int(arg))
self.mass.player_queues.set_repeat(queue.queue_id, new_repeat_mode)
return
if subcommand == "crossfade":
self.mass.player_queues.set_crossfade(queue.queue_id, not queue.crossfade_enabled)
self.mass.player_queues.set_crossfade(queue.queue_id, bool(arg))
return

self.logger.warning("Unhandled command: playlist/%s", subcommand)
Expand Down Expand Up @@ -1034,16 +1034,16 @@ def _handle_button(
return
# queue related button commands
queue = self.mass.player_queues.get_active_queue(player_id)
if subcommand == "jump_fwd":
if subcommand == "fwd":
self.mass.create_task(self.mass.player_queues.next, queue.queue_id)
return
if subcommand == "jump_rew":
if subcommand == "rew":
self.mass.create_task(self.mass.player_queues.previous, queue.queue_id)
return
if subcommand == "fwd":
if subcommand == "jump_fwd":
self.mass.create_task(self.mass.player_queues.skip, queue.queue_id, 10)
return
if subcommand == "rew":
if subcommand == "jump_rew":
self.mass.create_task(self.mass.player_queues.skip, queue.queue_id, -10)
return
if subcommand == "shuffle":
Expand Down
13 changes: 12 additions & 1 deletion music_assistant/server/providers/slimproto/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def player_item_from_mass(playerindex: int, player: Player) -> PlayerItem:
"remote_title": str,
"artwork_url": str,
"bitrate": str,
"samplerate": str,
"samplesize": str,
"duration": str | int | None,
"coverid": str,
"params": dict,
Expand All @@ -150,6 +152,9 @@ def playlist_item_from_mass(
mass: MusicAssistant, queue_item: QueueItem, index: int = 0, is_cur_index: bool = False
) -> PlaylistItem:
"""Parse PlaylistItem for the Json RPC interface from MA QueueItem."""
samplerate = "44100"
samplesize = "16"
bitrate = "1411"
if (
is_cur_index
and queue_item.streamdetails
Expand All @@ -174,6 +179,10 @@ def playlist_item_from_mass(
title = queue_item.name
artist = ""
album = queue_item.media_type.value
if queue_item.streamdetails:
samplerate = str(queue_item.streamdetails.audio_format.sample_rate)
samplesize = str(queue_item.streamdetails.audio_format.bit_depth)
bitrate = str(queue_item.streamdetails.audio_format.bit_rate)
return {
"playlist index": index,
"id": "-187651250107376",
Expand All @@ -186,7 +195,9 @@ def playlist_item_from_mass(
else "",
"coverid": "-187651250107376",
"duration": queue_item.duration,
"bitrate": "",
"bitrate": bitrate,
"samplerate": samplerate,
"samplesize": samplesize,
}


Expand Down

0 comments on commit 75a6a9b

Please sign in to comment.