Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions homeassistant/components/squeezebox/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_TRACK,
)
from homeassistant.helpers.network import is_internal_request

LIBRARY = ["Artists", "Albums", "Tracks", "Playlists", "Genres"]

Expand Down Expand Up @@ -67,6 +68,8 @@

async def build_item_response(entity, player, payload):
"""Create response payload for search described by payload."""
internal_request = is_internal_request(entity.hass)

search_id = payload["search_id"]
search_type = payload["search_type"]

Expand Down Expand Up @@ -96,9 +99,14 @@ async def build_item_response(entity, player, payload):

artwork_track_id = item.get("artwork_track_id")
if artwork_track_id:
item_thumbnail = entity.get_browse_image_url(
item_type, item_id, artwork_track_id
)
if internal_request:
item_thumbnail = player.generate_image_url_from_track_id(
artwork_track_id
)
else:
item_thumbnail = entity.get_browse_image_url(
item_type, item_id, artwork_track_id
)

children.append(
BrowseMedia(
Expand Down
10 changes: 10 additions & 0 deletions homeassistant/helpers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ class NoURLAvailableError(HomeAssistantError):
"""An URL to the Home Assistant instance is not available."""


@bind_hass
def is_internal_request(hass: HomeAssistant) -> bool:
"""Test if the current request is internal."""
try:
_get_internal_url(hass, require_current_request=True)
return True
except NoURLAvailableError:
return False


@bind_hass
def get_url(
hass: HomeAssistant,
Expand Down