Skip to content

Commit

Permalink
add config options for icy meta
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 28, 2024
1 parent 886b727 commit 78d065b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
19 changes: 19 additions & 0 deletions music_assistant/common/models/config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CONF_AUTO_PLAY,
CONF_CROSSFADE,
CONF_CROSSFADE_DURATION,
CONF_ENABLE_ICY_METADATA,
CONF_ENFORCE_MP3,
CONF_EQ_BASS,
CONF_EQ_MID,
Expand Down Expand Up @@ -620,6 +621,24 @@ class CoreConfig(Config):
{**CONF_ENTRY_HTTP_PROFILE.to_dict(), "default_value": "no_content_length", "hidden": True}
)

CONF_ENTRY_ENABLE_ICY_METADATA = ConfigEntry(
key=CONF_ENABLE_ICY_METADATA,
type=ConfigEntryType.STRING,
options=(
ConfigValueOption("Disabled - do not send ICY metadata", "disabled"),
ConfigValueOption("Profile 1 - basic info", "basic"),
ConfigValueOption("Profile 2 - full info (including image)", "full"),
),
depends_on=CONF_FLOW_MODE,
default_value="basic",
label="Try to ingest metadata into stream (ICY)",
category="advanced",
description="Try to ingest metadata into the stream (ICY) to show track info on the player, "
"even when flow mode is enabled.\n\nThis is called ICY metadata and its what is also used by "
"online radio station to inform you what is playing. \n\nBe aware that not all players support "
"this correctly. If you experience issues with playback, try to disable this setting.",
)


def create_sample_rates_config_entry(
max_sample_rate: int,
Expand Down
1 change: 1 addition & 0 deletions music_assistant/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
CONF_BYPASS_NORMALIZATION_SHORT: Final[str] = "bypass_normalization_short"
CONF_PREVENT_SYNC_LEADER_OFF: Final[str] = "prevent_sync_leader_off"
CONF_SYNCGROUP_DEFAULT_ON: Final[str] = "syncgroup_default_on"
CONF_ENABLE_ICY_METADATA: Final[str] = "enable_icy_metadata"

# config default values
DEFAULT_HOST: Final[str] = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion music_assistant/server/controllers/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def update(
changed_values = get_changed_values(
prev_state,
new_state,
ignore_keys=["elapsed_time", "elapsed_time_last_updated", "seq_no"],
ignore_keys=["elapsed_time", "elapsed_time_last_updated", "seq_no", "last_poll"],
)
self._prev_states[player_id] = new_state

Expand Down
12 changes: 8 additions & 4 deletions music_assistant/server/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
CONF_BYPASS_NORMALIZATION_SHORT,
CONF_CROSSFADE,
CONF_CROSSFADE_DURATION,
CONF_ENABLE_ICY_METADATA,
CONF_HTTP_PROFILE,
CONF_OUTPUT_CHANNELS,
CONF_PUBLISH_IP,
Expand Down Expand Up @@ -375,10 +376,11 @@ async def serve_queue_flow_stream(self, request: web.Request) -> web.Response:
default_sample_rate=flow_pcm_format.sample_rate,
default_bit_depth=flow_pcm_format.bit_depth,
)
# play it safe: only allow icy metadata for mp3 and aac
enable_icy = request.headers.get(
"Icy-MetaData", ""
) == "1" and output_format.content_type in (ContentType.MP3, ContentType.AAC)
# work out ICY metadata support
icy_preference = self.mass.config.get_raw_player_config_value(
queue_id, CONF_ENABLE_ICY_METADATA, "basic"
)
enable_icy = request.headers.get("Icy-MetaData", "") == "1" and icy_preference != "disabled"
icy_meta_interval = 16384

# prepare request, add some DLNA/UPNP compatible headers
Expand Down Expand Up @@ -446,6 +448,8 @@ async def serve_queue_flow_stream(self, request: web.Request) -> web.Response:
else:
title = "Music Assistant"
metadata = f"StreamTitle='{title}';".encode()
if icy_preference == "full" and 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
2 changes: 2 additions & 0 deletions music_assistant/server/providers/dlna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from music_assistant.common.models.config_entries import (
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_CROSSFADE_FLOW_MODE_REQUIRED,
CONF_ENTRY_ENABLE_ICY_METADATA,
CONF_ENTRY_ENFORCE_MP3,
CONF_ENTRY_HTTP_PROFILE,
ConfigEntry,
Expand Down Expand Up @@ -81,6 +82,7 @@
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_ENFORCE_MP3,
CONF_ENTRY_HTTP_PROFILE,
CONF_ENTRY_ENABLE_ICY_METADATA,
create_sample_rates_config_entry(192000, 24, 96000, 24),
)

Expand Down
2 changes: 2 additions & 0 deletions music_assistant/server/providers/hass_players/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from music_assistant.common.models.config_entries import (
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_CROSSFADE_FLOW_MODE_REQUIRED,
CONF_ENTRY_ENABLE_ICY_METADATA,
CONF_ENTRY_ENFORCE_MP3_DEFAULT_ENABLED,
CONF_ENTRY_FLOW_MODE_DEFAULT_ENABLED,
CONF_ENTRY_HTTP_PROFILE,
Expand Down Expand Up @@ -96,6 +97,7 @@ class MediaPlayerEntityFeature(IntFlag):
CONF_ENTRY_CROSSFADE_DURATION,
CONF_ENTRY_ENFORCE_MP3_DEFAULT_ENABLED,
CONF_ENTRY_HTTP_PROFILE,
CONF_ENTRY_ENABLE_ICY_METADATA,
)


Expand Down

0 comments on commit 78d065b

Please sign in to comment.