Random YouTube video URL fetch

Hi all, I was hoping you could help me with something. I’d like to make nightbot pick a random video from the channel we’re streaming on on YouTube. Using the Decapi API I already made a command for the most recent upload, but I’d like a command that fetches a random URL from the channel, ideally with a restriction in place so the very oldest don’t get picked, but that’s not absolutely necessary.

I suspect it would be a combination of eval and fetchurl, but I can’t quite figure it out. Thanks in advance, gals and guys!

The latest video API supports a ‘skip’ parameter, which will ignore the latest X videos.
If you specify skip=3, then it will skip the last three videos and show the info for the fourth one.

Make skip specify a random number, and you’re basically golden. Here’s an example:

$(urlfetch https://decapi.me/youtube/latest_video?skip=$(eval Math.floor(Math.random() * 50))&user=monstercatmedia)

Replace user=monstercatmedia with whatever you’re currently using (either user= or id= ) for your channel.

skip supports a maximum of 50 (for reasons I don’t remember anymore), so if you have more than 50 videos then this solution isn’t perfect, as it will only consider the last 50 videos uploaded to the channel.

If you have less than 50 videos, then make sure to change the 50 to whatever amount of videos you have.

We have thousands, but that’s fine. It doesn’t need to be older than the last 50. Thanks a lot!

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