How to know which "stream/segment" is live?

Is there a way to know if a stream segment is currently live?

I only found the channel “online” event to get notified when a channel is currently live, but it does not contain any info about what “video/segment” is live.

My goal would be to share on my platform that a twitch channel is currently with a video (title, description, etc.)

Is there a way to do this? I couldn’t find it in the API docs.

To get title, game, that sort of thing you can either use the EventSub channel.update topic https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelupdate which will notify you of changes to a channels title or category that you could cache so when they do go live you refer to your cache.

Or you can use the Get Streams endpoint https://dev.twitch.tv/docs/api/reference#get-streams which will also contain data such as title and category if the stream is live.

Hey @Dist, thanks for your replay.

  1. Regarding the channel update, I’m not sure how that helps me, since I’m interested in the title of the stream which is live.

  2. That looks interesting, cause it contains the title of the stream indeed.

So I guess I can:

  • subscribe to the channel.online event to get notified if a channel is live
  • then I use the streams endpoint to find the stream of a channel which is currently live

This should give me then the title of the stream as well. I think this will do it, thanks a lot.

For an “eventsub only” solution"

The order of operations is this

  • streamer, before going live, will change the title (and/or category) - this raises a channel.update event
  • you collect the title and category from this message and store it
  • the streamer (later) goes live triggering a stream.online
  • you use the previously collected title/game to do whatever you need

then during a strimg the streamer may

  • change the title (and/or category) - this raises a channel.update event

You know the streamer is already live from the earier stream.online event retained in your system

later

  • the streamer ends the stream and this sends a stream.offline event

So this would involve retaining “state”.
But if you can’t retain state then yes you would call the API after you get a stream.online event

Hey @BarryCarlyon, thanks for your reply.

I don’t use Twitch myself that much, so I’m a bit new to how Twitch handle streams. (it is quite different from YouTube)

Does the channel title “always” change when a streamer goes live?

No. It’s a different operation.

YouTube is “create a stream on day x with title y and category y” which generates basically a completely different channel (well URL for the live stream).

Title/category changes when the streamer/user changes it.
It’s not connected to the live event.

Yesterday, for example, the main streamer I work for, did three streams.
For stream 2 they did not file a title/category update.

Twitch has titles/categories persist after a stream ends. So you’ll find that some streamers, who go on vacation, will update the title to say “away till x” (which’ll trigger a channel.update)

The problem with

is that there is a slim chance you get the wrong title/category, as the streamer goes live, then goes “dammit forgot to update the title/category” so they’ll change the title and streams might return cached information.

So if you intent is to

You need the real time updates that EventSub gives you. Just in case

Thanks @BarryCarlyon, things are now more clear to me. The thing with the title is indeed an issue or could be.

Here is a more detailed view of what I want to achieve:

I have a platform https://larastreamers.com/ where I show upcoming streams from streamers. This currently only works for YouTube streams, but I want to support twitch too.

The way it currently works is

  • streamer submits the URL of an already schedule YT stream
  • I regularly check if this stream is live, if it is, I set it to “live”, later than to “finished”

The question for me is, since Twitch works quite differently, if I can integrate Twitch here too, so I can list upcoming Twitch “streams”, and also mark them as “live” when they are live.

My initial idea was:

  • user submits his twitch channel
  • I get the broadcaster id and then get the schedule
  • then store the streams of the schedule as “streams”
  • add subscribe to the channel “online” and “offline” events
  • when the channel goes live, I want to find the right stream (current issue) and set it to live
  • when the channel goes offline, I want to find the right stream (current issue) and set it to finished.

After that, the stream is only shown on the archive.

It is pretty clear now to me that my platform is built for YouTube, but it would be cool if I find a way to support Twitch somehow too.

There is not “right stream” really.

When it comes to streams
YouTube is strict and formal.
Twitch is not.

You can’t easily pair a Twitch stream schedule item to a Stream as quite often streamers start late or early. And there just isn’t a correlation to a stream schedule item an a stream on Twitch.

On Twitch a channel being live is a property of a channel.
II’s not a property of a scheduled event.

You should be saying here

Channel of ID xxxx has gone live
Channel of ID xxxx is live

Not

Calendar Item of ID yyy on the schedule of Channel of ID xxx has gone live

if you are trying to tie a stream on a channel to a schedule item of a channel, the only way to do that is to compare start times.

But you can’t as a streamer could go live an hour early for a totallty different reason. Or plays a different game to what is on the calendar.

Twitch streamers are not “formal and strucuted” like this.

So your best bet here is to not mark a calendar item as live, just mark the channel as live.

I see, thanks a lot for the clarification.

I could indeed just create a stream in my app when a channel is live and just show that the channel is live (inside my stream item).

I guess also when a stream is finished, I can’t get directly get a link to this stream to show that stream in my archive?

Correct.

There is no correlation betwen the stream schedule and VODs.

So you’d have to assume the most recent vod is for the stream that just ended. (And compare start times, and lengths)

Alterantively, if you are trying to show past broadcasts, just show everything from Get Videos - Reference | Twitch Developers using a type param of archive to filter the results.

And this only works if the target channel has Vod Retention enabled

Thanks @BarryCarlyon and also @Dist , that helped a lot :+1:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.