Kang-Kyu Lee

February 6, 2026

How to use Yt (for sanitizing playlist)

I started a series about coding to remove private / deleted video from your playlists. And it's time to officially tell you how to use Yt gem (gem roughly means someone else's Ruby code)

https://world.hey.com/kangkyu/youtube-api-tool-1-5b21e532

playlist = Yt::Playlist.new id: id, auth: auth
video_id = "..."

playlist.playlist_items.each do |item|
  item.delete if item.video_id == video_id
end

There are variations, but this is the code. You can read it if you know Ruby - actually you can read it even if you don't know Ruby programming language, I dare say. A playlist object initialized with its id, has its multiple playlist items (plural), and check if video id of for each playlist item (if you want to remove that video from the playlist) then delete.

If you remember, I spent some time to "how to find playlist item id" earlier but it turns out now what you need is just your playlist and a video. And they are easily found in the URL, in the browser.

playlist = Yt::Playlist.new url: url, auth: auth

This is valid code too.

playlist.playlist_items.each do |item|
  item.delete if item.video.private?
end

And you can also check if the video has "private" visibility, and remove all of them under the given playlist.

That's it for today. Next time, I will show you internal of the gem, by trying to add a new feature to the gem. Thank you!

About Kang-Kyu Lee

I love hamburgers. I will share my experiences with Ruby and YouTube