Skip to main content

YouTube

Blocks for YouTube: read public videos, channels and playlists, and get notified when a channel uploads or goes live. Almost everything works without an API key. Search, comments and exact statistics need a free YouTube API key, and they have their own section at the bottom of the flyout.

Wherever a block asks for a channel, you can give it an @handle (like @YouTube), a channel link, or a channel ID (the one starting with UC). Wherever it asks for a video, you can give it any YouTube link (watch, youtu.be, Shorts or live) or the 11-character video ID.

Show the whole YouTube flyout

The YouTube subcategory

Videos​

These run the blocks inside them with a video. Inside, get ... of YouTube video reads from it.

BlockWhat it does
get videoLooks up one video by link or ID.
get latestGets a channel's newest upload. The dropdown picks any upload, only videos, or only Shorts.
for each uploadRuns once for each of a channel's latest uploads (up to 15), newest first.
for each in playlistRuns once for each video in a public playlist (the first 15).

Video info

get ... of YouTube video reads the title, description, link, ID, channel name, channel ID and link, views, likes, upload date, length in seconds, thumbnail URL, whether it is a Short, whether it is live, its category and its tags.

Not every block knows everything. Videos from a channel's uploads or a playlist come from YouTube's public feed, which has likes but no length or tags. Videos you get by link have length and tags but no likes. Anything missing is null.

Upload and live notifications​

These two blocks go on their own in the workspace, not inside an event. They check the channel every few minutes (at least 1) and run the blocks inside when something new happens.

BlockRuns when
on new videoThe channel posts a new upload, video or Short. It runs once for each new one.
on liveThe channel starts a livestream.

Use get ... of YouTube video inside them. Nothing runs for videos that were already there when the bot started, so restarting the bot does not repeat old notifications.

Channels​

Get channel

get YouTube channel ... then ... looks up a channel.

Channel info

get ... of YouTube channel reads its name, @handle, description, ID, link, subscriber count, video count, creation date, profile picture, banner and whether it is family safe. YouTube rounds public subscriber counts, so 1.23M becomes 1230000. The "text" options give the count the way YouTube shows it.

Quick info​

These do not need anything fetched first:

BlockReturns
latest linkA link to the channel's newest upload.
subscribersThe subscriber count as YouTube shows it, like 1.23M.
is liveTrue while the channel is livestreaming.
channel idThe channel ID of a handle or link.
existsTrue when a link or ID points to a public or unlisted video.
video idThe video ID taken out of any YouTube link.
thumbnailA link to the video's thumbnail image, in the quality you pick. Great in embeds. Not every video has a max quality thumbnail.

With an API key​

Searching, reading comments and exact numbers are only available through the YouTube Data API, which needs a key. It is free:

  1. Go to console.cloud.google.com, create a project, and enable YouTube Data API v3.
  2. Under Credentials, create an API key.
  3. Save it as a secret named YOUTUBE_API_KEY. The blocks come with get secret with name YOUTUBE_API_KEY already plugged in.
BlockWhat it does
searchSearches YouTube and runs once for each video found. Use get ... of YouTube video inside it.
video statsThe exact views, likes or comment count of a video.
channel statsA channel's subscribers, total views or video count.
commentsRuns once for each top-level comment on a video.
comment infoInside that, reads the comment's text, author, likes, reply count, date or link.

Google gives every key a daily quota. A search uses far more of it than the other blocks, so add a cooldown to search commands.

Notes​

  • Every block here goes over the network, so defer reply first inside an interaction.
  • The blocks without a key read YouTube's public pages. If YouTube refuses a request, they give null (or false) rather than an error.

A worked example: upload notifications​

  1. Drag when YouTube channel ... posts a new ... into the workspace, on its own.
  2. Type the channel's @handle, and pick upload (video or Short).
  3. Inside it, send a message to your announcements channel: New video: joined with get title of YouTube video, then get link of YouTube video on a new line.