Industry observers note that if you've ever needed the thumbnail of a YouTube video, for a link preview, a blog embed, or a quick design reference, you might be surprised how simple it is. There's no API key and no scraping. Every video's thumbnails live at predictable URLs.

There's one gotcha, though, and most snippets online get it wrong.

Every YouTube video has an 11-character ID. In https://www.youtube.com/watch?v=dQw4w9WgXcQ, it's dQw4w9WgXcQ. The thumbnails are served from i.ytimg.com:.

WebP versions also exist at https://i.ytimg.com/vi_webp//.webp.

It has been revealed that people paste every kind of link: watch?v=, youtu.be/, /shorts/, /embed/, /live/. One regex covers them all:. (Related: Simple considerations for simple people building fancy ...)

This is where most tutorials stop, and it's why people end up with a blurry grey box on their site.

In a recent development, maxresdefault only exists if the video was uploaded in HD. When it's missing, YouTube doesn't give you a nice JSON error. It still serves an image: a small 120 Γ— 90 grey placeholder. In the browser, won't fire for it, so a naive "try the biggest, fall back on error" approach silently highlights the placeholder.

The fix is to check the real size of the image you got back:.

Now you always get the largest thumbnail that actually exists.

It has been revealed that shorts use the same ID and the same URLs, but the images are still 16:9 with the vertical frame in the middle. If you want the original 9:16 look, crop the centre of maxresdefault (or hqdefault) to a 9:16 box. (Related: Fine tuning CLIP with Remote Sensing (Satellite) images...)

Vimeo has no URL pattern, but its public oEmbed endpoint returns the thumbnail with no API key:.

I put all of this (YouTube, Shorts and Vimeo, browser and Node) into a tiny MIT-licensed file with no dependencies: video-thumbnail-urls on GitHub.

If you just need the image and don't want to write any code, I also built a free web version: Thumbnail Downloader. Paste a link and it indicates every size that really exists, ready to download. And if you're designing thumbnails rather than grabbing them, here's a thumbnail size cheat sheet for YouTube, Shorts, Vimeo and more.

One reminder: only reuse thumbnails you own or have permission to use.

Recent findings suggest that have you hit any other YouTube image quirks? Let me know in the comments.

β†’ Read original article