Skip to content

Commit

Permalink
New Sonos S2 player provider (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Aug 23, 2024
1 parent 4c05fb6 commit 69101ba
Show file tree
Hide file tree
Showing 17 changed files with 1,113 additions and 421 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"editor.defaultFormatter": "charliermarsh.ruff",
"[github-actions-workflow]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"python.analysis.extraPaths": ["../aiosonos/"]
}
1 change: 1 addition & 0 deletions music_assistant/common/models/player_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PlayerQueue(DataClassDictMixin):
flow_mode_start_index: int = 0
stream_finished: bool | None = None
end_of_track_reached: bool | None = None
queue_items_last_updated: float = time.time()

@property
def corrected_elapsed_time(self) -> float:
Expand Down
5 changes: 4 additions & 1 deletion music_assistant/server/controllers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ def get_image_url(
# return imageproxy url for images that need to be resolved
# the original path is double encoded
encoded_url = urllib.parse.quote(urllib.parse.quote(image.path))
return f"{self.mass.streams.base_url}/imageproxy?path={encoded_url}&provider={image.provider}&size={size}&fmt={image_format}" # noqa: E501
return (
f"{self.mass.streams.base_url}/imageproxy?path={encoded_url}"
f"&provider={image.provider}&size={size}&fmt={image_format}"
)
return image.path

async def get_thumbnail(
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/controllers/player_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ def signal_update(self, queue_id: str, items_changed: bool = False) -> None:
"""Signal state changed of given queue."""
queue = self._queues[queue_id]
if items_changed:
queue.queue_items_last_updated = time.time()
self.mass.signal_event(EventType.QUEUE_ITEMS_UPDATED, object_id=queue_id, data=queue)
# save items in cache
self.mass.create_task(
Expand All @@ -1055,7 +1056,6 @@ def signal_update(self, queue_id: str, items_changed: bool = False) -> None:
base_key=queue_id,
)
)

# always send the base event
self.mass.signal_event(EventType.QUEUE_UPDATED, object_id=queue_id, data=queue)
# save state
Expand Down
10 changes: 6 additions & 4 deletions music_assistant/server/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
get_icy_stream,
get_player_filter_params,
get_silence,
get_stream_details,
parse_loudnorm,
strip_silence,
)
Expand Down Expand Up @@ -252,7 +253,10 @@ async def serve_queue_item_stream(self, request: web.Request) -> web.Response:
if not queue_item:
raise web.HTTPNotFound(reason=f"Unknown Queue item: {queue_item_id}")
if not queue_item.streamdetails:
raise web.HTTPNotFound(reason=f"No streamdetails for Queue item: {queue_item_id}")
# raise web.HTTPNotFound(reason=f"No streamdetails for Queue item: {queue_item_id}")
queue_item.streamdetails = await get_stream_details(
mass=self.mass, queue_item=queue_item
)
# work out output format/details
output_format = await self._get_output_format(
output_format_str=request.match_info["fmt"],
Expand Down Expand Up @@ -390,8 +394,6 @@ async def serve_queue_flow_stream(self, request: web.Request) -> web.Response:
else:
title = "Music Assistant"
metadata = f"StreamTitle='{title}';".encode()
if current_item and current_item.image:
metadata += f"StreamURL='{current_item.image.path}'".encode()
while len(metadata) % 16 != 0:
metadata += b"\x00"
length = len(metadata)
Expand Down Expand Up @@ -873,7 +875,7 @@ async def _get_output_format(
if default_sample_rate in supported_sample_rates:
output_sample_rate = default_sample_rate
else:
output_sample_rate = min(supported_sample_rates)
output_sample_rate = max(supported_sample_rates)
output_bit_depth = min(default_bit_depth, player_max_bit_depth)
output_channels_str = self.mass.config.get_raw_player_config_value(
player.player_id, CONF_OUTPUT_CHANNELS, "stereo"
Expand Down
4 changes: 2 additions & 2 deletions music_assistant/server/providers/airplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ async def _send_metadata(self, queue: PlayerQueue) -> None:
title = stream_title
# set album to radio station name
album = queue.current_item.name
if media_item := queue.current_item.media_item:
elif media_item := queue.current_item.media_item:
title = media_item.name
if artist_str := getattr(media_item, "artist_str", None):
artist = artist_str
if _album := getattr(media_item, "album", None):
Expand Down Expand Up @@ -499,7 +500,6 @@ class AirplayProvider(PlayerProvider):

cliraop_bin: str | None = None
_players: dict[str, AirPlayPlayer]
_discovery_running: bool = False
_dacp_server: asyncio.Server = None
_dacp_info: AsyncServiceInfo = None
_play_media_lock: asyncio.Lock = asyncio.Lock()
Expand Down
Loading

0 comments on commit 69101ba

Please sign in to comment.