Open a Random Video from a Specific YouTube Channel

I created a Script to open a random video from a specific YouTube Channel. The script prompts user for the name of the channel, uses the scrapeSelector to get videos from the channel and then selects a random one to open.

https://user-images.githubusercontent.com/6998954/148695801-f5607143-265b-4fd5-aa48-de0182d36791.mov

Future enhancements: I'd like to add some error logging to help users if they enter an invalid channel name that returns a 404 or if a given channel exists but doesn't return any videos. I tried adding some console.logs but wasn't sure how to output helpful logs to ScriptKit users.

// Name: Random Video From YouTube Channel
// Description: Open a random video from a specific YouTube Channel
// Author: Monica Powell
// Twitter: @indigitalcolor
// GitHub: @m0nica
``
import "@johnlindquist/kit"
let channelName = await arg("YouTube Channel Name (e.g, yogawithadriene):")
let videos = await scrapeSelector(
`https://www.youtube.com/c/${channelName}/videos`,
"a#video-title",
el => ({
name: el.innerText,
value: el.href,
})
)
let randomVideo = videos[Math.floor(Math.random() * videos.length)]
exec(`open "${randomVideo.value}"`)

View gist: https://gist.github.com/M0nica/939bd4c3dfb2bf6fed08afb17ab16d19