VLC Telnet to sign all HASS URLs (#66123)
parent
f2843283bf
commit
e6e49dcb07
|
@ -10,6 +10,7 @@ from urllib.parse import quote
|
||||||
from aiovlc.client import Client
|
from aiovlc.client import Client
|
||||||
from aiovlc.exceptions import AuthError, CommandError, ConnectError
|
from aiovlc.exceptions import AuthError, CommandError, ConnectError
|
||||||
from typing_extensions import Concatenate, ParamSpec
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
|
import yarl
|
||||||
|
|
||||||
from homeassistant.components import media_source
|
from homeassistant.components import media_source
|
||||||
from homeassistant.components.http.auth import async_sign_path
|
from homeassistant.components.http.auth import async_sign_path
|
||||||
|
@ -32,10 +33,11 @@ from homeassistant.components.media_player.const import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
from homeassistant.const import CONF_NAME, STATE_IDLE, STATE_PAUSED, STATE_PLAYING
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.network import get_url
|
from homeassistant.helpers.network import get_url, is_hass_url
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from .const import DATA_AVAILABLE, DATA_VLC, DEFAULT_NAME, DOMAIN, LOGGER
|
from .const import DATA_AVAILABLE, DATA_VLC, DEFAULT_NAME, DOMAIN, LOGGER
|
||||||
|
@ -305,28 +307,30 @@ class VlcDevice(MediaPlayerEntity):
|
||||||
# Handle media_source
|
# Handle media_source
|
||||||
if media_source.is_media_source_id(media_id):
|
if media_source.is_media_source_id(media_id):
|
||||||
sourced_media = await media_source.async_resolve_media(self.hass, media_id)
|
sourced_media = await media_source.async_resolve_media(self.hass, media_id)
|
||||||
media_type = MEDIA_TYPE_MUSIC
|
media_type = sourced_media.mime_type
|
||||||
media_id = sourced_media.url
|
media_id = sourced_media.url
|
||||||
|
|
||||||
# Sign and prefix with URL if playing a relative URL
|
if media_type != MEDIA_TYPE_MUSIC and not media_type.startswith("audio/"):
|
||||||
if media_id[0] == "/":
|
raise HomeAssistantError(
|
||||||
media_id = async_sign_path(
|
f"Invalid media type {media_type}. Only {MEDIA_TYPE_MUSIC} is supported"
|
||||||
self.hass,
|
|
||||||
quote(media_id),
|
|
||||||
timedelta(seconds=media_source.DEFAULT_EXPIRY_TIME),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Sign and prefix with URL if playing a relative URL
|
||||||
|
if media_id[0] == "/" or is_hass_url(self.hass, media_id):
|
||||||
|
parsed = yarl.URL(media_id)
|
||||||
|
|
||||||
|
if parsed.query:
|
||||||
|
LOGGER.debug("Not signing path for content with query param")
|
||||||
|
else:
|
||||||
|
media_id = async_sign_path(
|
||||||
|
self.hass,
|
||||||
|
quote(media_id),
|
||||||
|
timedelta(seconds=media_source.DEFAULT_EXPIRY_TIME),
|
||||||
|
)
|
||||||
|
|
||||||
# prepend external URL
|
# prepend external URL
|
||||||
hass_url = get_url(self.hass)
|
if media_id[0] == "/":
|
||||||
media_id = f"{hass_url}{media_id}"
|
media_id = f"{get_url(self.hass)}{media_id}"
|
||||||
|
|
||||||
if media_type != MEDIA_TYPE_MUSIC:
|
|
||||||
LOGGER.error(
|
|
||||||
"Invalid media type %s. Only %s is supported",
|
|
||||||
media_type,
|
|
||||||
MEDIA_TYPE_MUSIC,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
await self._vlc.add(media_id)
|
await self._vlc.add(media_id)
|
||||||
self._state = STATE_PLAYING
|
self._state = STATE_PLAYING
|
||||||
|
|
Loading…
Reference in New Issue