mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Jellyfin: display album primary art instead of artist backdrop (#141246)
* Jellyfin: Properly display album primary art instead of artist backdrop when playing music * add test for album art urls, fix existing tests that broke because they have extraneous "album*" fields for non-album items. * fix snapshot test
This commit is contained in:
parent
0e6d72dcc8
commit
61a76b4064
@ -97,16 +97,27 @@ def get_artwork_url(
|
|||||||
client: JellyfinClient, item: dict[str, Any], max_width: int = 600
|
client: JellyfinClient, item: dict[str, Any], max_width: int = 600
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Find a suitable thumbnail for an item."""
|
"""Find a suitable thumbnail for an item."""
|
||||||
artwork_id: str = item["Id"]
|
artwork_id: str | None = None
|
||||||
artwork_type = "Primary"
|
artwork_type: str | None = None
|
||||||
parent_backdrop_id: str | None = item.get("ParentBackdropItemId")
|
parent_backdrop_id: str | None = item.get("ParentBackdropItemId")
|
||||||
|
|
||||||
if "Backdrop" in item[ITEM_KEY_IMAGE_TAGS]:
|
if "AlbumPrimaryImageTag" in item:
|
||||||
|
# jellyfin_apiclient_python doesn't support passing a specific tag to `.artwork`,
|
||||||
|
# so we don't use the actual value of AlbumPrimaryImageTag.
|
||||||
|
# However, its mere presence tells us that the album does have primary artwork,
|
||||||
|
# and the resulting URL will pull the primary album art even if the tag is not specified.
|
||||||
|
artwork_type = "Primary"
|
||||||
|
artwork_id = item["AlbumId"]
|
||||||
|
elif "Backdrop" in item[ITEM_KEY_IMAGE_TAGS]:
|
||||||
artwork_type = "Backdrop"
|
artwork_type = "Backdrop"
|
||||||
|
artwork_id = item["Id"]
|
||||||
elif parent_backdrop_id:
|
elif parent_backdrop_id:
|
||||||
artwork_type = "Backdrop"
|
artwork_type = "Backdrop"
|
||||||
artwork_id = parent_backdrop_id
|
artwork_id = parent_backdrop_id
|
||||||
elif "Primary" not in item[ITEM_KEY_IMAGE_TAGS]:
|
elif "Primary" in item[ITEM_KEY_IMAGE_TAGS]:
|
||||||
|
artwork_type = "Primary"
|
||||||
|
artwork_id = item["Id"]
|
||||||
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return str(client.jellyfin.artwork(artwork_id, artwork_type, max_width))
|
return str(client.jellyfin.artwork(artwork_id, artwork_type, max_width))
|
||||||
|
@ -302,8 +302,6 @@
|
|||||||
"Album": "string",
|
"Album": "string",
|
||||||
"CollectionType": "tvshows",
|
"CollectionType": "tvshows",
|
||||||
"DisplayOrder": "string",
|
"DisplayOrder": "string",
|
||||||
"AlbumId": "21af9851-8e39-43a9-9c47-513d3b9e99fc",
|
|
||||||
"AlbumPrimaryImageTag": "string",
|
|
||||||
"SeriesPrimaryImageTag": "string",
|
"SeriesPrimaryImageTag": "string",
|
||||||
"AlbumArtist": "string",
|
"AlbumArtist": "string",
|
||||||
"AlbumArtists": [
|
"AlbumArtists": [
|
||||||
|
@ -4346,6 +4346,7 @@
|
|||||||
],
|
],
|
||||||
"Album": "ALBUM",
|
"Album": "ALBUM",
|
||||||
"AlbumId": "ALBUM-UUID",
|
"AlbumId": "ALBUM-UUID",
|
||||||
|
"AlbumPrimaryImageTag": "ALBUM-PRIMARY-IMAGE-TAG",
|
||||||
"AlbumArtist": "Album Artist",
|
"AlbumArtist": "Album Artist",
|
||||||
"AlbumArtists": [
|
"AlbumArtists": [
|
||||||
{ "Name": "Album Artist", "Id": "9a65b2c222ddb34e51f5cae360fad3a1" }
|
{ "Name": "Album Artist", "Id": "9a65b2c222ddb34e51f5cae360fad3a1" }
|
||||||
|
@ -302,8 +302,6 @@
|
|||||||
"Album": "string",
|
"Album": "string",
|
||||||
"CollectionType": "string",
|
"CollectionType": "string",
|
||||||
"DisplayOrder": "string",
|
"DisplayOrder": "string",
|
||||||
"AlbumId": "21af9851-8e39-43a9-9c47-513d3b9e99fc",
|
|
||||||
"AlbumPrimaryImageTag": "string",
|
|
||||||
"SeriesPrimaryImageTag": "string",
|
"SeriesPrimaryImageTag": "string",
|
||||||
"AlbumArtist": "string",
|
"AlbumArtist": "string",
|
||||||
"AlbumArtists": [
|
"AlbumArtists": [
|
||||||
|
@ -1707,6 +1707,7 @@
|
|||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
'AlbumId': 'ALBUM-UUID',
|
'AlbumId': 'ALBUM-UUID',
|
||||||
|
'AlbumPrimaryImageTag': 'ALBUM-PRIMARY-IMAGE-TAG',
|
||||||
'ArtistItems': list([
|
'ArtistItems': list([
|
||||||
dict({
|
dict({
|
||||||
'Id': '1d864900526d9a9513b489f1cc28f8ca',
|
'Id': '1d864900526d9a9513b489f1cc28f8ca',
|
||||||
|
@ -27,6 +27,7 @@ from homeassistant.components.media_player import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
ATTR_ENTITY_PICTURE,
|
||||||
ATTR_FRIENDLY_NAME,
|
ATTR_FRIENDLY_NAME,
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
)
|
)
|
||||||
@ -124,6 +125,10 @@ async def test_media_player_music(
|
|||||||
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
|
assert state.attributes.get(ATTR_MEDIA_SERIES_TITLE) is None
|
||||||
assert state.attributes.get(ATTR_MEDIA_SEASON) is None
|
assert state.attributes.get(ATTR_MEDIA_SEASON) is None
|
||||||
assert state.attributes.get(ATTR_MEDIA_EPISODE) is None
|
assert state.attributes.get(ATTR_MEDIA_EPISODE) is None
|
||||||
|
assert (
|
||||||
|
state.attributes.get(ATTR_ENTITY_PICTURE)
|
||||||
|
== "http://localhost/Items/ALBUM-UUID/Images/Primary.jpg"
|
||||||
|
)
|
||||||
|
|
||||||
entry = entity_registry.async_get(state.entity_id)
|
entry = entity_registry.async_get(state.entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user