Luke Davis

Morsel #13: YouTube max thumbnail grabber

Filed under: JavaScript | tech | the Internet | utils

A while back, I made a YouTube thumbnail grabber for my Terminal using Python. Here’s a command example:

py yt.py -u "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

But I’m lazy and wanted something I could just access online. Boing Boing already has a thumbnail grabber but it displays all thumbnail sizes. I just need the biggest (as I used them for featured images on my blogs) so rather than copy, I decided to use Google’s Gemini to generate the code.

_Please note: I looked through the code, tested it, and rewrote some of it to be more efficient (e.g. removing unnecessary code and changing values the structure).

Update: 21st Dec 2024: it looks like YouTube has killed the maxresdefault image so I’ve replaced it with hqdefault. If it comes back, I’ll change it back.

Update: 27th Feb 2025: maxresdefault is baaaaaack!

How the code works

I have a standard form with a text input and a submit button. When I enter a valid YouTube URL and click submit, the script checks for validity (and ensures no attempts at XSS attacks get through), extracts the video ID and creates the thumbnail URL to display.

If an invalid YouTube URL is submitted, you get an error message (try it and see!). You also can’t submit an empty field either as it will warn you.

The reason I used AI for this is because I was trying to recreate code that I’d written elsewhere and it wasn’t working and I could foresee losing hours and hours of my life when I could just get a large language model to do it and check the work.

Morsel #12: styling a WordPress post to look like a Bluesky post Morsel #14: Textlist to array