Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ async def ws_camera_stream(hass, connection, msg):
fmt=fmt,
keepalive=camera_prefs.preload_stream,
options=camera.stream_options,
master_playlist=msg.get("master_playlist") is False,
)
connection.send_result(msg["id"], {"url": url})
except HomeAssistantError as ex:
Expand Down
23 changes: 19 additions & 4 deletions homeassistant/components/stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,26 @@


@bind_hass
def request_stream(hass, stream_source, *, fmt="hls", keepalive=False, options=None):
def request_stream(
hass,
stream_source,
*,
fmt="hls",
keepalive=False,
options=None,
master_playlist=True,
):
"""Set up stream with token."""
if DOMAIN not in hass.config.components:
raise HomeAssistantError("Stream integration is not set up.")

if not master_playlist: # request for regular playlist, stream should already exist
Comment thread
uvjustin marked this conversation as resolved.
Outdated
try:
stream = hass.data[DOMAIN][ATTR_STREAMS].get(stream_source)
return hass.data[DOMAIN][ATTR_ENDPOINTS][fmt][1].format(stream.access_token)
except Exception as err:
raise HomeAssistantError("Unable to get stream") from err

if options is None:
options = {}

Expand Down Expand Up @@ -73,7 +88,7 @@ def request_stream(hass, stream_source, *, fmt="hls", keepalive=False, options=N
if not stream.access_token:
stream.access_token = secrets.token_hex()
stream.start()
return hass.data[DOMAIN][ATTR_ENDPOINTS][fmt].format(stream.access_token)
return hass.data[DOMAIN][ATTR_ENDPOINTS][fmt][0].format(stream.access_token)
Comment thread
uvjustin marked this conversation as resolved.
Outdated
except Exception as err:
raise HomeAssistantError("Unable to get stream") from err

Expand All @@ -93,8 +108,8 @@ async def async_setup(hass, config):
hass.data[DOMAIN][ATTR_STREAMS] = {}

# Setup HLS
hls_endpoint = async_setup_hls(hass)
hass.data[DOMAIN][ATTR_ENDPOINTS]["hls"] = hls_endpoint
hls_endpoints = async_setup_hls(hass)
hass.data[DOMAIN][ATTR_ENDPOINTS]["hls"] = hls_endpoints

# Setup Recorder
async_setup_recorder(hass)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/stream/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def async_setup_hls(hass):
hass.http.register_view(HlsSegmentView())
hass.http.register_view(HlsInitView())
hass.http.register_view(HlsMasterPlaylistView())
return "/api/hls/{}/master_playlist.m3u8"
return ("/api/hls/{}/master_playlist.m3u8", "/api/hls/{}/playlist.m3u8")


class HlsMasterPlaylistView(StreamView):
Expand Down