Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live attribute not working again! #18

Closed
sp7dpt opened this issue Jan 6, 2021 · 31 comments · Fixed by #19
Closed

Live attribute not working again! #18

sp7dpt opened this issue Jan 6, 2021 · 31 comments · Fixed by #19

Comments

@sp7dpt
Copy link

sp7dpt commented Jan 6, 2021

Version of the custom_component

0.3.3

Describe the bug

Live attribute return always false but stream is live

@chairman2s
Copy link

I just noticed the same thing and was going to post on the forum but then I thought I should check here first...

@sp7dpt
Copy link
Author

sp7dpt commented Jan 10, 2021

I found this relationship at https://www.youtube.com/channel/[channel_ID]/live html code returns a response "isLive":true
Maybe this will help repair the component.

@pinkywafer
Copy link
Collaborator

The live attribute is still working for me.
It should be noted that the sensor reports on the most recent video... It is possible that a channel is live, but there is a video which has been updated since the stream started.
It may be possible to add an additional 'channel_live' attribute as an extra.
Thoughts please @ludeeus

@ludeeus
Copy link
Collaborator

ludeeus commented Jan 12, 2021

Without sensor attributes and configuration there is no way to tell

@sp7dpt
Copy link
Author

sp7dpt commented Jan 12, 2021

In this moment on the Kreator channel is stream live.

My sensor return:
url: https://www.youtube.com/watch?v=8Ut1S1fka_w
published: 2021-01-12T15:52:25+00:00
live: false
friendly_name: Kreator
icon: mdi:youtube
entity_picture: https://i1.ytimg.com/vi/8Ut1S1fka_w/hqdefault.jpg

Sensor are defined:

#Kreator

  • platform: youtube
    channel_id: UC1SHj5QU7AHPVHpLe0UGJ7Q

What else should I do?

@ludeeus
Copy link
Collaborator

ludeeus commented Jan 12, 2021

I can't even get it to start, something changed with Python 3.9 with html it seems, if I fix that it will break for everyone else.

@pinkywafer
Copy link
Collaborator

Shows as live on mine
IMG_20210112_225554

@sp7dpt
Copy link
Author

sp7dpt commented Jan 12, 2021

image
it doesn't work for me. Why?
What is your Home Assistant configuration?
My Home Assistant version is 2021.1.1 and supervisor version 2020.12.7
What can I check or set more?

@pinkywafer
Copy link
Collaborator

I'm running full home assistant (home assistant os, supervisor + core) in a proxmox vm.
YouTube s sensor integration v0.3.3 installed through hacs.

This is strange though as it shouldn't make a difference that I can see, unless you are running core on a different version of python.

Unless... I'm just wondering if YouTube generates the page differently depending on country for example. This is however only a speculation
For reference, I'm in uk

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

The script looks for the string in https://www.youtube.com/feeds/videos.xml?channel_id=
This is my xml

Copy link
Collaborator

ludeeus commented Jan 13, 2021

I wonder if it's a language thing, where YT serves the page that is scraped with a different language based on IP

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

Maybe this is it. That's why I included my xml.

I am currently using YouTube API to check live streams, but there is a query limit of up to 10,000 per day. One search costs 100 units.

Copy link
Collaborator

ludeeus commented Jan 13, 2021

enable debug for the integration, see example in .devcontainer/configuration.yaml

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

I enabled debug and this is result:

2021-01-13 12:44:02 DEBUG (MainThread) [custom_components.youtube.sensor] Kreator - Running update
2021-01-13 12:44:02 DEBUG (MainThread) [custom_components.youtube.sensor] Kreator - Skipping live check

@pinkywafer
Copy link
Collaborator

OK, the "Started streaming" is NOT scraped from the channel's videos.xml page.
The url of the latest video is scraped from that page, and then the latest video page source is scraped for "Started streaming"
If you are able to save the source of a live video page and upload it, I should be able to compare.
Can you please also let us know what country you are in.
I expect that as @ludeeus suggested, this may be being auto generated based on country IP, so I'd expect to find "Started streaming" in your local default language.

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

Yes, the latest video is scraped.
This is my xml when streaming was live. I did not find any keywords for a live stream. I'm from Poland

@pinkywafer
Copy link
Collaborator

That XML is the channel videos.xml which is only scraped for the link to the latest video.
In that example, the video URL (and page which is scraped for live) is https://www.youtube.com/watch?v=8Ut1S1fka_w

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

I don't understand now how to get you what you need.
This channel is live all the time, that would be a good example https://www.youtube.com/watch?v=L9Sum_pL7m4
What file format should I download for you, HTML or else?

@pinkywafer
Copy link
Collaborator

yes, the html page of any live video.

Note that while I can use the channel you just linked to work out what is going on, it is not the most recent video, so the sensor would still report the latest video as not live

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

ok, I saved this page in the browser as HTML. This is the file. You have inside two examples,
Is it what you want?

@pinkywafer
Copy link
Collaborator

thanks, that is more than I need. I really only needed the html, but this is the html complete, but no matter, I can get the info from this.

It looks like the scraped text is indeed automatically translated into the local language. I'll look if there are alternative options

@pinkywafer
Copy link
Collaborator

Ok, I think I've found something I can use. Can you please save a page from the browser of a live stream which has finished so that I can verify.
Thanks

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

ok, I saved one of the channels wherein strem is offline. This is the file

@pinkywafer
Copy link
Collaborator

That's great, thanks

I think I've found a fix, I'll get back to you!

@pinkywafer
Copy link
Collaborator

Are you able to test the sensor.py located in the live-attribute-global-fix branch please

@sp7dpt
Copy link
Author

sp7dpt commented Jan 13, 2021

I replaced the sensor.py file and now it works fine. I will test a little and give feedback.

@pinkywafer
Copy link
Collaborator

great, thanks.
@ludeeus I'll do PR and merge in. Please don't release yet as I have a few extras up my sleeve!!

@ludeeus
Copy link
Collaborator

ludeeus commented Jan 13, 2021

I think you should have permissions to release, if you do, go ahead when you are ready, if not ping me and I'll adjust 👍

@sp7dpt
Copy link
Author

sp7dpt commented Jan 14, 2021

I checked few channels and sometimes detection not worked. This is a file HTML when detection not worked. Maybe it will help.
Strange because the word "isLiveBroadcast" occurs in HTML

@pinkywafer
Copy link
Collaborator

The first video in the zip shows a start date of back in November. If there has been a more recent video published, the sensor would not show live for this. I can't see any other reason why this does not show as live.
The second html actually has an end listed in the html, indicating that the video was streamed live, but is no longer live.
I've just added additional attributes that you can see in my pull requests #20 and #21 which should go some way to addressing this. If you install the current master, you should be able to test

@sp7dpt
Copy link
Author

sp7dpt commented Jan 15, 2021

I tested and it looks like the attributes are working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants