mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Use internal url for Squeezebox if possible (#43089)
This commit is contained in:
parent
1061f78f12
commit
560afc31ad
@ -13,6 +13,7 @@ from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_PLAYLIST,
|
||||
MEDIA_TYPE_TRACK,
|
||||
)
|
||||
from homeassistant.helpers.network import is_internal_request
|
||||
|
||||
LIBRARY = ["Artists", "Albums", "Tracks", "Playlists", "Genres"]
|
||||
|
||||
@ -67,6 +68,8 @@ BROWSE_LIMIT = 1000
|
||||
|
||||
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"]
|
||||
|
||||
@ -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(
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user