mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Improve Sonos handling of TuneIn stations (#56479)
This commit is contained in:
parent
ca6b53c16d
commit
931cf4eaab
@ -1050,25 +1050,32 @@ class SonosSpeaker:
|
|||||||
def update_media_radio(self, variables: dict | None) -> None:
|
def update_media_radio(self, variables: dict | None) -> None:
|
||||||
"""Update state when streaming radio."""
|
"""Update state when streaming radio."""
|
||||||
self.media.clear_position()
|
self.media.clear_position()
|
||||||
|
radio_title = None
|
||||||
|
|
||||||
try:
|
if current_track_metadata := variables.get("current_track_meta_data"):
|
||||||
album_art_uri = variables["current_track_meta_data"].album_art_uri
|
if album_art_uri := getattr(current_track_metadata, "album_art_uri", None):
|
||||||
self.media.image_url = self.media.library.build_album_art_full_uri(
|
self.media.image_url = self.media.library.build_album_art_full_uri(
|
||||||
album_art_uri
|
album_art_uri
|
||||||
)
|
)
|
||||||
except (TypeError, KeyError, AttributeError):
|
if not self.media.artist:
|
||||||
pass
|
self.media.artist = getattr(current_track_metadata, "creator", None)
|
||||||
|
|
||||||
if not self.media.artist:
|
# A missing artist implies metadata is incomplete, try a different method
|
||||||
try:
|
if not self.media.artist:
|
||||||
self.media.artist = variables["current_track_meta_data"].creator
|
radio_show = None
|
||||||
except (TypeError, KeyError, AttributeError):
|
stream_content = None
|
||||||
pass
|
if current_track_metadata.radio_show:
|
||||||
|
radio_show = current_track_metadata.radio_show.split(",")[0]
|
||||||
|
if not current_track_metadata.stream_content.startswith(
|
||||||
|
("ZPSTR_", "TYPE=")
|
||||||
|
):
|
||||||
|
stream_content = current_track_metadata.stream_content
|
||||||
|
radio_title = " • ".join(filter(None, [radio_show, stream_content]))
|
||||||
|
|
||||||
# Radios without tagging can have part of the radio URI as title.
|
if radio_title:
|
||||||
# In this case we try to use the radio name instead.
|
# Prefer the radio title created above
|
||||||
try:
|
self.media.title = radio_title
|
||||||
uri_meta_data = variables["enqueued_transport_uri_meta_data"]
|
elif uri_meta_data := variables.get("enqueued_transport_uri_meta_data"):
|
||||||
if isinstance(uri_meta_data, DidlAudioBroadcast) and (
|
if isinstance(uri_meta_data, DidlAudioBroadcast) and (
|
||||||
self.soco.music_source_from_uri(self.media.title) == MUSIC_SRC_RADIO
|
self.soco.music_source_from_uri(self.media.title) == MUSIC_SRC_RADIO
|
||||||
or (
|
or (
|
||||||
@ -1080,18 +1087,23 @@ class SonosSpeaker:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
|
# Fall back to the radio channel name as a last resort
|
||||||
self.media.title = uri_meta_data.title
|
self.media.title = uri_meta_data.title
|
||||||
except (TypeError, KeyError, AttributeError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
media_info = self.soco.get_current_media_info()
|
media_info = self.soco.get_current_media_info()
|
||||||
|
|
||||||
self.media.channel = media_info["channel"]
|
self.media.channel = media_info["channel"]
|
||||||
|
|
||||||
# Check if currently playing radio station is in favorites
|
# Check if currently playing radio station is in favorites
|
||||||
for fav in self.favorites:
|
fav = next(
|
||||||
if fav.reference.get_uri() == media_info["uri"]:
|
(
|
||||||
self.media.source_name = fav.title
|
fav
|
||||||
|
for fav in self.favorites
|
||||||
|
if fav.reference.get_uri() == media_info["uri"]
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if fav:
|
||||||
|
self.media.source_name = fav.title
|
||||||
|
|
||||||
def update_media_music(self, track_info: dict) -> None:
|
def update_media_music(self, track_info: dict) -> None:
|
||||||
"""Update state when playing music tracks."""
|
"""Update state when playing music tracks."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user