stefansundin/rssbox

Can I only receive YouTube livestream notifications?

Closed this issue ยท 13 comments

I want to receive only real-time online performances.

I have had troubles finding a reliable way to fetch live streams from the YouTube API. Recently I have started using the RSS feed endpoint to get live streams. However, only one endpoint uses it and it's for an experiment I am running and there is no way to discover it without reading the source code. This endpoint can not be used as an RSS feed.

rssbox/app.rb

Lines 270 to 274 in 8f02186

# The API is really inconsistent in listing scheduled live streams, but the RSS endpoint seems to consistently list them, so experiment with using that
response = HTTP.get("https://www.youtube.com/feeds/videos.xml?channel_id=#{@channel_id}")
raise(GoogleError, response) if !response.success?
doc = Nokogiri::XML(response.body)
ids = doc.xpath("//yt:videoId").map(&:text)

For the normal endpoint you can add ?eventType=live, but it may not be super reliable for the reasons stated above. Example: https://rssbox.herokuapp.com/youtube/UCupvZG-5ko_eiXAupbDfxWw/CNN?eventType=live

I have had troubles finding a reliable way to fetch live streams from the YouTube API. Recently I have started using the RSS feed endpoint to get live streams. However, only one endpoint uses it and it's for an experiment I am running and there is no way to discover it without reading the source code. This endpoint can not be used as an RSS feed.

rssbox/app.rb

Lines 270 to 274 in 8f02186

# The API is really inconsistent in listing scheduled live streams, but the RSS endpoint seems to consistently list them, so experiment with using that
response = HTTP.get("https://www.youtube.com/feeds/videos.xml?channel_id=#{@channel_id}")
raise(GoogleError, response) if !response.success?
doc = Nokogiri::XML(response.body)
ids = doc.xpath("//yt:videoId").map(&:text)

For the normal endpoint you can add ?eventType=live, but it may not be super reliable for the reasons stated above. Example: https://rssbox.herokuapp.com/youtube/UCupvZG-5ko_eiXAupbDfxWw/CNN?eventType=live

Unfortunately, this no longer works. No live stream is listed that should be listed, regardless of whether eventType=live is set or not. ๐Ÿ˜ž

Perhaps Google made some changes to their YouTube API. ๐Ÿค”

@stefansundin Do you still support this endpoint? Because as it is now, seems to no longer function properly, see my previous comment.

RSS Box is simply a pass through to what the YouTube API provides. I can't really change anything. Maybe you should find out how to query the YouTube API in a way that it gives you the data that you want, and then make whatever appropriate changes to RSS Box so that it queries it in that way?

As I wrote in my earlier comment, I don't know why the YouTube API is so inconsistent with regards to live streams. If anyone has the answer then please enlighten me and everyone else here.

P.S. It would be more helpful if you also provided an example. "seems to no longer function properly" is not very helpful. Maybe give us an example of a YouTube channel, what data you expect to see, and what you actually get?

Btw, sometimes I get the following error on page when I try the experimental endpoint:
Sorry, a nasty error occurred: undefined method `>' for nil:NilClass

It would be nice if you could revive the experimental endpoint for YT live streams. ๐Ÿ˜Š

@sn-o-w Can you share a URL that sometimes produces that error? Thanks!

@stefansundin Hmmm, looks like the error disappears after a while, I mean with YT channels that are no longer new to the instance of RSSBox. Not 100% sure exactly.

For example here still appears, most likely will disappear after a while: https://rssbox.up.railway.app/youtube/UCxi19O9ACWp3JSa-topNjPA/Str3sU?eventType=live
Sorry, a nasty error occurred: undefined method `>' for nil:NilClass


https://rssbox.herokuapp.com/youtube/UCxi19O9ACWp3JSa-topNjPA/Str3sU?eventType=live
Interestingly, on your instance it just shows: An unhandled lowlevel error occurred. The application logs may have details.


By the way, I also tried to add @ in the URLs, like @Str3sU because handles have @, no difference at all.


That Str3sU channel is livestreaming right now.

@stefansundin Another example, another YT channel:

https://rssbox.herokuapp.com/youtube/UCwUfX87V6RsbVVRrcrxmJAA/CreativeMonkeyzArmy?eventType=live

https://rssbox.up.railway.app/youtube/UCwUfX87V6RsbVVRrcrxmJAA/CreativeMonkeyzArmy?eventType=live

CreativeMonkeyzArmy just started a few mins ago, they usually stream for 3-4 hours, so you can experiment with different things.

Even if the error will disappear, looks like the live streams won't appear in your experimental endpoint. At least this is what I saw from my own testing.

@sn-o-w Thanks. I had actually seen this error before but I didn't have time to look into it properly. Here's the fix: eca3286

It looks like now it works?! โค๏ธ

https://rssbox.up.railway.app/youtube/UCwUfX87V6RsbVVRrcrxmJAA/CreativeMonkeyzArmy?eventType=live

Just updated my instance and now I can see the live stream entry showing up. ๐Ÿ˜

@stefansundin Thank you, sir. ๐Ÿ˜Š

Awesome, glad it worked. ๐Ÿ‘

Found a tiny bug with my previous fix. 0ceb465