Skip to content

Adding Etag Support to Yt RubyGem

Published: at 08:27 PM

Managing YouTube playlists is kind of a chore so I sat down and wrote an app to make it easier for me. Integrating an app with the YouTube API isn’t all that difficult but I didn’t really want to reinvent the wheel if I didn’t need to.

There is an official Google YouTube RubyGem but it’s for every Google API service under the sun and I found it a bit too bloated for my current project. I found an alternative in the Yt RubyGem and it did exactly what I needed it to do… with one exception; having support for etags.

The YouTube API gives you an quota allocation of 10k requests in a 24 hour period. All API requests, including invalid requests, incur a quota cost of at least one point. I don’t make that many requests usually but I did run into that limit a few times doing some testing.

That’s where etags come in. An etag (short for entity tag), put simply is a unique identifier for a specific version of a resource. So when a playlist gets changed (and that includes adding and removing a video) then the etag changes. The goal here is pretty simple, record the etag for the resource and compare them to what is on the YouTube API. If it’s changed then I know the contents of a playlist or a video have changed. If it’s the same then I don’t need to issue any more requests.

I forked the gem, added support for ingesting etags from the YouTube API and added a PR to hopefully get merged into the main project.

So now I can use something this in my project:

account.playlists.where(title: 'ai').first.etag
=> "WNE9J7gFaSlUwmSLDA51uDt8SKk"

# Playlist hasn't changed
account.playlists.where(title: 'ai').first.etag
=> "WNE9J7gFaSlUwmSLDA51uDt8SKk"

# Adding a new video to the playlist changes the etag
account.playlists.where(title: 'ai').first.etag
=> "ktDqBk_076qJIGpFgBOWboMyXHs"

Next Post
Apple Drops Containerization Framework at WWDC 2025