diff --git a/README.md b/README.md
index e3c0b0a..327d565 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,7 @@ key | type | description
* stars: The 'stars' recieved on youtube. (This is all reactions both 👍 and 👎 combined)
* views: the number of video views
* stream: If the video was streamed live
+* stream_start: datetime of the start of a live stream
* live: If the video is live now
* channel_is_live: If any video on the channel is live
* channel_image: URL of the channel logo image
diff --git a/custom_components/youtube/sensor.py b/custom_components/youtube/sensor.py
index b0b9f91..4e120ab 100644
--- a/custom_components/youtube/sensor.py
+++ b/custom_components/youtube/sensor.py
@@ -66,6 +66,7 @@ def __init__(self, channel_id, name, session):
self.channel_live = False
self.channel_image = None
self.expiry = parse('01 Jan 1900 00:00:00 UTC')
+ self.stream_start = None
async def async_update(self):
"""Update sensor."""
@@ -83,7 +84,7 @@ async def async_update(self):
info.split('
')[2].split('')[0])
url = info.split('')[0]
if self.live or url != self.url:
- self.stream, self.live = await is_live(url, self._name, self.hass, self.session)
+ self.stream, self.live, self.stream_start = await is_live(url, self._name, self.hass, self.session)
else:
_LOGGER.debug('%s - Skipping live check', self._name)
self.url = url
@@ -127,6 +128,7 @@ def device_state_attributes(self):
'stars': self.stars,
'views': self.views,
'stream': self.stream,
+ 'stream_start': self.stream_start,
'live': self.live,
'channel_is_live': self.channel_live,
'channel_image': self.channel_image}
@@ -135,18 +137,20 @@ async def is_live(url, name, hass, session):
"""Return bool if video is stream and bool if video is live"""
live = False
stream = False
+ start = None
try:
async with async_timeout.timeout(10, loop=hass.loop):
response = await session.get(url, cookies=dict(CONSENT="YES+cb"))
info = await response.text()
if 'isLiveBroadcast' in info:
stream = True
+ start = parse(info.split('startDate" content="')[1].split('"')[0])
if 'endDate' not in info:
live = True
_LOGGER.debug('%s - Latest Video is live', name)
except Exception as error: # pylint: disable=broad-except
_LOGGER.debug('%s - Could not update - %s', name, error)
- return stream, live
+ return stream, live, start
async def is_channel_live(url, name, hass, session):
"""Return bool if channel is live"""
diff --git a/info.md b/info.md
index 309c9b2..5d3f6b4 100644
--- a/info.md
+++ b/info.md
@@ -43,6 +43,7 @@ key | type | description
* stars: The 'stars' recieved on youtube. (This is all reactions both 👍 and 👎 combined)
* views: the number of video views
* stream: If the video was streamed live
+* stream_start: datetime of the start of a live stream
* live: If the video is live now
* channel_is_live: If any video on the channel is live
* channel_image: URL of the channel logo image