mirror of
https://github.com/home-assistant/core.git
synced 2025-04-19 14:57:52 +00:00
Fix for media content type case in Squeezebox (#143099)
This commit is contained in:
parent
c7290908cc
commit
8355727eb1
@ -22,34 +22,34 @@ from homeassistant.helpers.network import is_internal_request
|
||||
from .const import UNPLAYABLE_TYPES
|
||||
|
||||
LIBRARY = [
|
||||
"Favorites",
|
||||
"Artists",
|
||||
"Albums",
|
||||
"Tracks",
|
||||
"Playlists",
|
||||
"Genres",
|
||||
"New Music",
|
||||
"Album Artists",
|
||||
"Apps",
|
||||
"Radios",
|
||||
"favorites",
|
||||
"artists",
|
||||
"albums",
|
||||
"tracks",
|
||||
"playlists",
|
||||
"genres",
|
||||
"new music",
|
||||
"album artists",
|
||||
"apps",
|
||||
"radios",
|
||||
]
|
||||
|
||||
MEDIA_TYPE_TO_SQUEEZEBOX: dict[str | MediaType, str] = {
|
||||
"Favorites": "favorites",
|
||||
"Artists": "artists",
|
||||
"Albums": "albums",
|
||||
"Tracks": "titles",
|
||||
"Playlists": "playlists",
|
||||
"Genres": "genres",
|
||||
"New Music": "new music",
|
||||
"Album Artists": "album artists",
|
||||
"favorites": "favorites",
|
||||
"artists": "artists",
|
||||
"albums": "albums",
|
||||
"tracks": "titles",
|
||||
"playlists": "playlists",
|
||||
"genres": "genres",
|
||||
"new music": "new music",
|
||||
"album artists": "album artists",
|
||||
MediaType.ALBUM: "album",
|
||||
MediaType.ARTIST: "artist",
|
||||
MediaType.TRACK: "title",
|
||||
MediaType.PLAYLIST: "playlist",
|
||||
MediaType.GENRE: "genre",
|
||||
"Apps": "apps",
|
||||
"Radios": "radios",
|
||||
MediaType.APPS: "apps",
|
||||
"radios": "radios",
|
||||
}
|
||||
|
||||
SQUEEZEBOX_ID_BY_TYPE: dict[str | MediaType, str] = {
|
||||
@ -58,22 +58,20 @@ SQUEEZEBOX_ID_BY_TYPE: dict[str | MediaType, str] = {
|
||||
MediaType.TRACK: "track_id",
|
||||
MediaType.PLAYLIST: "playlist_id",
|
||||
MediaType.GENRE: "genre_id",
|
||||
"Favorites": "item_id",
|
||||
"favorites": "item_id",
|
||||
MediaType.APPS: "item_id",
|
||||
}
|
||||
|
||||
CONTENT_TYPE_MEDIA_CLASS: dict[str | MediaType, dict[str, MediaClass | str]] = {
|
||||
"Favorites": {"item": MediaClass.DIRECTORY, "children": MediaClass.TRACK},
|
||||
"Apps": {"item": MediaClass.DIRECTORY, "children": MediaClass.APP},
|
||||
"Radios": {"item": MediaClass.DIRECTORY, "children": MediaClass.APP},
|
||||
"App": {"item": MediaClass.DIRECTORY, "children": MediaClass.TRACK},
|
||||
"Artists": {"item": MediaClass.DIRECTORY, "children": MediaClass.ARTIST},
|
||||
"Albums": {"item": MediaClass.DIRECTORY, "children": MediaClass.ALBUM},
|
||||
"Tracks": {"item": MediaClass.DIRECTORY, "children": MediaClass.TRACK},
|
||||
"Playlists": {"item": MediaClass.DIRECTORY, "children": MediaClass.PLAYLIST},
|
||||
"Genres": {"item": MediaClass.DIRECTORY, "children": MediaClass.GENRE},
|
||||
"New Music": {"item": MediaClass.DIRECTORY, "children": MediaClass.ALBUM},
|
||||
"Album Artists": {"item": MediaClass.DIRECTORY, "children": MediaClass.ARTIST},
|
||||
"favorites": {"item": MediaClass.DIRECTORY, "children": MediaClass.TRACK},
|
||||
"radios": {"item": MediaClass.DIRECTORY, "children": MediaClass.APP},
|
||||
"artists": {"item": MediaClass.DIRECTORY, "children": MediaClass.ARTIST},
|
||||
"albums": {"item": MediaClass.DIRECTORY, "children": MediaClass.ALBUM},
|
||||
"tracks": {"item": MediaClass.DIRECTORY, "children": MediaClass.TRACK},
|
||||
"playlists": {"item": MediaClass.DIRECTORY, "children": MediaClass.PLAYLIST},
|
||||
"genres": {"item": MediaClass.DIRECTORY, "children": MediaClass.GENRE},
|
||||
"new music": {"item": MediaClass.DIRECTORY, "children": MediaClass.ALBUM},
|
||||
"album artists": {"item": MediaClass.DIRECTORY, "children": MediaClass.ARTIST},
|
||||
MediaType.ALBUM: {"item": MediaClass.ALBUM, "children": MediaClass.TRACK},
|
||||
MediaType.ARTIST: {"item": MediaClass.ARTIST, "children": MediaClass.ALBUM},
|
||||
MediaType.TRACK: {"item": MediaClass.TRACK, "children": ""},
|
||||
@ -91,17 +89,15 @@ CONTENT_TYPE_TO_CHILD_TYPE: dict[
|
||||
MediaType.PLAYLIST: MediaType.PLAYLIST,
|
||||
MediaType.ARTIST: MediaType.ALBUM,
|
||||
MediaType.GENRE: MediaType.ARTIST,
|
||||
"Artists": MediaType.ARTIST,
|
||||
"Albums": MediaType.ALBUM,
|
||||
"Tracks": MediaType.TRACK,
|
||||
"Playlists": MediaType.PLAYLIST,
|
||||
"Genres": MediaType.GENRE,
|
||||
"Favorites": None, # can only be determined after inspecting the item
|
||||
"Apps": MediaClass.APP,
|
||||
"Radios": MediaClass.APP,
|
||||
"App": None, # can only be determined after inspecting the item
|
||||
"New Music": MediaType.ALBUM,
|
||||
"Album Artists": MediaType.ARTIST,
|
||||
"artists": MediaType.ARTIST,
|
||||
"albums": MediaType.ALBUM,
|
||||
"tracks": MediaType.TRACK,
|
||||
"playlists": MediaType.PLAYLIST,
|
||||
"genres": MediaType.GENRE,
|
||||
"favorites": None, # can only be determined after inspecting the item
|
||||
"radios": MediaClass.APP,
|
||||
"new music": MediaType.ALBUM,
|
||||
"album artists": MediaType.ARTIST,
|
||||
MediaType.APPS: MediaType.APP,
|
||||
MediaType.APP: MediaType.TRACK,
|
||||
}
|
||||
@ -173,7 +169,7 @@ def _build_response_known_app(
|
||||
|
||||
|
||||
def _build_response_favorites(item: dict[str, Any]) -> BrowseMedia:
|
||||
"""Build item for Favorites."""
|
||||
"""Build item for favorites."""
|
||||
if "album_id" in item:
|
||||
return BrowseMedia(
|
||||
media_content_id=str(item["album_id"]),
|
||||
@ -183,21 +179,21 @@ def _build_response_favorites(item: dict[str, Any]) -> BrowseMedia:
|
||||
can_expand=True,
|
||||
can_play=True,
|
||||
)
|
||||
if item["hasitems"] and not item["isaudio"]:
|
||||
if item.get("hasitems") and not item.get("isaudio"):
|
||||
return BrowseMedia(
|
||||
media_content_id=item["id"],
|
||||
title=item["title"],
|
||||
media_content_type="Favorites",
|
||||
media_class=CONTENT_TYPE_MEDIA_CLASS["Favorites"]["item"],
|
||||
media_content_type="favorites",
|
||||
media_class=CONTENT_TYPE_MEDIA_CLASS["favorites"]["item"],
|
||||
can_expand=True,
|
||||
can_play=False,
|
||||
)
|
||||
return BrowseMedia(
|
||||
media_content_id=item["id"],
|
||||
title=item["title"],
|
||||
media_content_type="Favorites",
|
||||
media_content_type="favorites",
|
||||
media_class=CONTENT_TYPE_MEDIA_CLASS[MediaType.TRACK]["item"],
|
||||
can_expand=item["hasitems"],
|
||||
can_expand=bool(item.get("hasitems")),
|
||||
can_play=bool(item["isaudio"] and item.get("url")),
|
||||
)
|
||||
|
||||
@ -220,7 +216,7 @@ def _get_item_thumbnail(
|
||||
item_type, item["id"], artwork_track_id
|
||||
)
|
||||
|
||||
elif search_type in ["Apps", "Radios"]:
|
||||
elif search_type in ["apps", "radios"]:
|
||||
item_thumbnail = player.generate_image_url(item["icon"])
|
||||
if item_thumbnail is None:
|
||||
item_thumbnail = item.get("image_url") # will not be proxied by HA
|
||||
@ -265,10 +261,10 @@ async def build_item_response(
|
||||
for item in result["items"]:
|
||||
# Force the item id to a string in case it's numeric from some lms
|
||||
item["id"] = str(item.get("id", ""))
|
||||
if search_type == "Favorites":
|
||||
if search_type == "favorites":
|
||||
child_media = _build_response_favorites(item)
|
||||
|
||||
elif search_type in ["Apps", "Radios"]:
|
||||
elif search_type in ["apps", "radios"]:
|
||||
# item["cmd"] contains the name of the command to use with the cli for the app
|
||||
# add the command to the dictionaries
|
||||
if item["title"] == "Search" or item.get("type") in UNPLAYABLE_TYPES:
|
||||
@ -364,11 +360,11 @@ async def library_payload(
|
||||
assert media_class["children"] is not None
|
||||
library_info["children"].append(
|
||||
BrowseMedia(
|
||||
title=item,
|
||||
title=item.title(),
|
||||
media_class=media_class["children"],
|
||||
media_content_id=item,
|
||||
media_content_type=item,
|
||||
can_play=item not in ["Favorites", "Apps", "Radios"],
|
||||
can_play=item not in ["favorites", "apps", "radios"],
|
||||
can_expand=True,
|
||||
)
|
||||
)
|
||||
|
@ -446,6 +446,9 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
||||
"""Send the play_media command to the media player."""
|
||||
index = None
|
||||
|
||||
if media_type:
|
||||
media_type = media_type.lower()
|
||||
|
||||
enqueue: MediaPlayerEnqueue | None = kwargs.get(ATTR_MEDIA_ENQUEUE)
|
||||
|
||||
if enqueue == MediaPlayerEnqueue.ADD:
|
||||
@ -617,6 +620,9 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
||||
media_content_id,
|
||||
)
|
||||
|
||||
if media_content_type:
|
||||
media_content_type = media_content_type.lower()
|
||||
|
||||
if media_content_type in [None, "library"]:
|
||||
return await library_payload(self.hass, self._player, self._browse_data)
|
||||
|
||||
|
@ -65,21 +65,21 @@ async def test_async_browse_media_root(
|
||||
assert response["success"]
|
||||
result = response["result"]
|
||||
for idx, item in enumerate(result["children"]):
|
||||
assert item["title"] == LIBRARY[idx]
|
||||
assert item["title"].lower() == LIBRARY[idx]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("category", "child_count"),
|
||||
[
|
||||
("Favorites", 4),
|
||||
("Artists", 4),
|
||||
("Albums", 4),
|
||||
("Playlists", 4),
|
||||
("Genres", 4),
|
||||
("New Music", 4),
|
||||
("Album Artists", 4),
|
||||
("Apps", 3),
|
||||
("Radios", 3),
|
||||
("favorites", 4),
|
||||
("artists", 4),
|
||||
("albums", 4),
|
||||
("playlists", 4),
|
||||
("genres", 4),
|
||||
("new music", 4),
|
||||
("album artists", 4),
|
||||
("apps", 3),
|
||||
("radios", 3),
|
||||
],
|
||||
)
|
||||
async def test_async_browse_media_with_subitems(
|
||||
|
Loading…
x
Reference in New Issue
Block a user