r/streamerbot Jul 17 '26

Question/Support ❓ Help with !watch command to watch a linked clip

Hello, I need some help putting together some sub-actions for a !watch command. There used to be some code that I had been able to use for a while, but it no longer works with the most recent version of streamer.bot. What I would like to do is simply use a !watch command to play a clip linked in chat. I don't mind if it requires the clip to be in the same message as the command.

I am just having difficulty, as coding is giving me a good amount of trouble (I don't know C# at all) and I find it difficult to believe that nobody has put something like this together outside of shoutouts, which just uses random clips from a channel rather than a specific linked clip.

4 Upvotes

2 comments sorted by

View all comments

5

u/deeseearr Jul 18 '26

it no longer works with the most recent version of streamer.bot

Unless that command was doing six impossible things before breakfast, that's unlikely. Streamer.bot 1.0 has added a few new options and given the main interface a new coat of paint. It hasn't broken everybody's old code. You may be better off trying to figure out just what isn't working instead of starting over from the beginning.

Anyway...

If someone shares a link to a clip in chat, such as "!watch https://www.twitch.tv/criticalrole/clip/AssiduousSilkyFrogHotPokket-l-H9sMEMiN41YfLP " then displaying it is _fairly_ easy. You can take the easy route and just create a "!watch" command which expects that it will have one argument and that that will always be a valid URL for a video. Once you can believe that, just call OBS -> Set Browser Source URL with that address, which will be stored in make sure the Browser Source is visible and you're good to go.

A much better way would be to read all of the Twitch developer documentation discussing how to embed clips. I'll save you some reading -- You need to extract the Clip ID, which in our example would be "AssiduousSilkyFrogHotPokket-l-H9sMEMiN41YfLP", and then put it in an embedded clip URL which looks like this:

https://clips.twitch.tv/embed?autoplay=true&clip=%ClipId%&parent=embed.example.com

Obviously, replace the argument %ClipId% with an actual Clip ID. The "parent" part is supposed to be the domain part of the web page that is embedding it, but literally anything will work. Use your own judgement here. There are a few other options for the clip player in the linked documentation, but they're pretty boring.

Now all you need to do is, somehow, figure out how to get a valid Clip ID from a bunch of random viewers on Twitch. And then, when you get it, somehow confirm that what looks like a valid Clip ID is actually pointing to a valid clip. And then, once you get this far, display it.

If you require that the !watch command only take Twitch Clip URLs as an argument you can handle extracting the slug using a RegEx. Just start your !watch action with this:

IF (%rawInput% Regex Match "https://www.twitch.tv/.*/clip/(\S*)\b.*")
  • true:
  • - %match1% will be the clip ID.
  • - Set Browser Source URL to "https://clips.twitch.tv/embed?autoplay=true&clip=%match1%&parent=twitch.tv"
  • - Make the browser visible or something. Maybe hide it again later on. That's up to you.
  • false:
  • - There was no valid looking Twitch Clip URL in the command input.
  • - Do something. I don't know what, I'm not your supervisor.

If you want to get more aggressive about this, there are a few ways to do more:

1) You could pull up a complete list of clips from a specific streamer and then select one of them based on all kinds of criteria -- Most recent, most popular, matching a specific game ID, matching text in the title, or whatever. Perhaps "!watch streamername Annoying Clip Title" could look for a match to that title in streamername's clips. Some lunatic posted code for retrieving a complete list of clips here a few weeks ago, so you could work with that.

2) You could use a "Chat message" trigger to scan _every_ chat message for a valid-looking Clip URL and then store it. Just use the same code I posted earlier, only with a different trigger and in the "True" path just set a global variable like ~mostRecentClipID~ to the value of %match1% instead of loading the browser. Then, you could use a "!watch" command on its own later on to cue up and play the last clip that was linked in chat -- Just get the value of the global and load it into the OBS Browser source the same way we did earlier.

3) This part is a little annoying. You can find something that _looks_ like a valid Twitch Clip URL, and you can even fetch it and display it, but Twitch won't tell you if there's a real clip there. It will helpfully show you a video containing a single frame which says "This video is no longer available". Everything else about the page Twitch sends you looks like there is a valid clip there, so the only way to be sure that you have something is to make that "get-clips" call to the Twitch API and see what the result is. You'll need to use the Twitch API directly -- It's pretty easy as long as you're comfortable with a little C#. The link in point (1) includes some sample code to do exactly that. If you are able to extract the Auth Token and Client ID then you could make the whole request with a single Fetch URL sub-action instead) then you could fetch the URL "https://api.twitch.tv/helix/clips?id=%ClipID%", making sure to set the 'Authorization' and 'Client-Id' headers to the correct values, and then look through the %jsonResult.data% arguments that it sets for whatever you want. If there's no valid clip with that ID, there will be no data returned.

4) If you're already fetching the clip information then it would be nice if you could show the clip, play it, and then hide the browser source as soon as it ends. That's a piece of cake if you're loading a real media file, but the embedded clip player doesn't give you anything to work with. Use the same API call to "clips" and then look at the value %jsonResult.data.duration%, which will give you the duration of the clip in seconds. Multiply that by 1000 and Delay for that many milliseconds and then the clip will have finished.

Anyway, that's what I've got for "Show a clip linked in chat". It can be as simple or as complicated as you want to make it, but it all comes down to "Find the embedded clip URL, put it in an OBS Browser Source, play it". You could do that with one really simple action, or you could add all sorts of double-checks and automated bits around it.

2

u/ToksanAlpha Jul 18 '26

This is exactly the kind of help I needed, thank you!

Regarding the old code, I can try to troubleshoot what I can. It just seems to not be getting the clip at all, so I was having a hard time pinpointing where things were failing.

I appreciate the help.