Support episode and track browse thumbnails and skip empty folder headers in Kodi (#195116)

This commit is contained in:
David Wood
2026-11-29 10:54:03 +00:00
committed by GitHub
parent bbcdafe3d0
commit 4bf42dfd99
2 changed files with 173 additions and 4 deletions
+34 -3
View File
@@ -50,12 +50,15 @@ async def build_item_response(media_library, payload, get_thumbnail_url=None):
search_id = payload["search_id"]
search_type = payload["search_type"]
_, title, media = await get_media_info(media_library, search_id, search_type)
thumbnail = await get_thumbnail_url(search_type, search_id)
thumbnail, title, media = await get_media_info(
media_library, search_id, search_type
)
if media is None:
return None
if thumbnail is not None and get_thumbnail_url is not None:
thumbnail = await get_thumbnail_url(search_type, search_id)
children = await asyncio.gather(
*(item_payload(item, get_thumbnail_url) for item in media)
)
@@ -350,6 +353,34 @@ async def get_media_info(media_library, search_id, search_type):
)
title = season["seasondetails"]["label"]
elif search_type == MediaType.EPISODE:
if search_id:
episode = await media_library.call_method(
"VideoLibrary.GetEpisodeDetails",
episodeid=int(search_id),
properties=properties,
)
thumbnail = media_library.thumbnail_url(
episode["episodedetails"]["art"].get(
"poster", episode["episodedetails"].get("thumbnail")
)
)
title = episode["episodedetails"]["label"]
elif search_type == MediaType.TRACK:
if search_id:
song = await media_library.call_method(
"AudioLibrary.GetSongDetails",
songid=int(search_id),
properties=properties,
)
thumbnail = media_library.thumbnail_url(
song["songdetails"]["art"].get(
"poster", song["songdetails"].get("thumbnail")
)
)
title = song["songdetails"]["label"]
elif search_type == MediaType.CHANNEL:
# A channel is asked for by id when its thumbnail is fetched through the
# media player proxy, the route an external client takes. There is no
+139 -1
View File
@@ -2,7 +2,10 @@
from unittest.mock import AsyncMock, MagicMock
from homeassistant.components.kodi.browse_media import get_media_info
from homeassistant.components.kodi.browse_media import (
build_item_response,
get_media_info,
)
from homeassistant.components.media_player import MediaType
CHANNELS = {
@@ -101,3 +104,138 @@ async def test_single_channel_asks_for_no_more_than_the_thumbnail() -> None:
await get_media_info(library, "902", MediaType.CHANNEL)
assert library.get_channels.call_args.kwargs["properties"] == ["thumbnail"]
async def test_episode_asked_for_by_id_carries_its_thumbnail() -> None:
"""An episode requested through the browse image proxy returns its art."""
library = create_media_library()
library.call_method = AsyncMock(
return_value={
"episodedetails": {
"label": "Pilot",
"art": {"poster": "image://episode_poster/"},
"thumbnail": "image://episode_thumb/",
}
}
)
thumbnail, title, media = await get_media_info(library, "42", MediaType.EPISODE)
library.call_method.assert_awaited_once_with(
"VideoLibrary.GetEpisodeDetails",
episodeid=42,
properties=["thumbnail", "art"],
)
assert thumbnail == "http://1.1.1.1:8080/image/image://episode_poster/"
assert title == "Pilot"
assert media is None
async def test_track_asked_for_by_id_carries_its_thumbnail() -> None:
"""A track requested through the browse image proxy returns its art."""
library = create_media_library()
library.call_method = AsyncMock(
return_value={
"songdetails": {
"label": "Opening Theme",
"art": {},
"thumbnail": "image://song_thumb/",
}
}
)
thumbnail, title, media = await get_media_info(library, "7", MediaType.TRACK)
library.call_method.assert_awaited_once_with(
"AudioLibrary.GetSongDetails",
songid=7,
properties=["thumbnail", "art"],
)
assert thumbnail == "http://1.1.1.1:8080/image/image://song_thumb/"
assert title == "Opening Theme"
assert media is None
async def test_folder_without_thumbnail_leaves_header_unset() -> None:
"""Top-level category folders do not ask for a proxy URL when they have no art."""
library = create_media_library()
library.get_movies = AsyncMock(
return_value={
"movies": [
{
"movieid": 1,
"label": "Movie With Art",
"art": {"poster": "image://movie_1/"},
},
{
"movieid": 2,
"label": "Movie Without Art",
"art": {},
},
]
}
)
get_thumbnail_url = AsyncMock(
side_effect=lambda content_type, content_id, thumbnail_url=None: (
f"/api/media_player_proxy/media_player.kodi/browse_media/{content_type}/{content_id}"
)
)
response = await build_item_response(
library,
{"search_type": MediaType.MOVIE, "search_id": ""},
get_thumbnail_url,
)
assert response is not None
assert response.thumbnail is None
assert [child.thumbnail for child in response.children] == [
"/api/media_player_proxy/media_player.kodi/browse_media/movie/1",
None,
]
async def test_container_with_thumbnail_sets_header_url() -> None:
"""A browsed show with artwork requests its header proxy URL."""
library = create_media_library()
library.get_seasons = AsyncMock(
return_value={
"seasons": [
{
"seasonid": 3,
"tvshowid": 10,
"season": 1,
"label": "Season 1",
"art": {"poster": "image://season_1/"},
}
]
}
)
library.get_tv_show_details = AsyncMock(
return_value={
"tvshowdetails": {
"label": "Example Show",
"art": {"poster": "image://show_10/"},
}
}
)
get_thumbnail_url = AsyncMock(
side_effect=lambda content_type, content_id, thumbnail_url=None: (
f"/api/media_player_proxy/media_player.kodi/browse_media/{content_type}/{content_id}"
)
)
response = await build_item_response(
library,
{"search_type": MediaType.TVSHOW, "search_id": "10"},
get_thumbnail_url,
)
assert response is not None
assert (
response.thumbnail
== "/api/media_player_proxy/media_player.kodi/browse_media/tvshow/10"
)
assert [child.thumbnail for child in response.children] == [
"/api/media_player_proxy/media_player.kodi/browse_media/season/10/1"
]