location ~ /vi/(.*)/thumbnail($|\..*) {
error_page 404 = @hqdefault;
proxy_intercept_errors on;
proxy_pass https://img.youtube.com/vi/$1/maxresdefault$2;
}
location @hqdefault {
proxy_pass https://img.youtube.com/vi/$1/hqdefault$2;
}
Then simply use /vi/<id>/thumbnail.webp as the image source or adapt the location regex as needed. This can be chained with yet more fallback URLs.It’s tripped me up several times. Although it’s unclear how much it’s the new feature or creators manually trying to game the algorithm by shuffling the title and thumbnail around.
As though there is no way that it could default to the correct thumbnail for any video -- surely it would not just help random hackers like OP, but also be more efficient for internal teams at Google to be able to render a preview for a video knowing only its ID, instead of making an API call to get the correct thumbnail name.
Great example of a 10-minute bug being prioritized at #837,434,212 and never resolved. I'd like to judge harshly, but let's be honest, most codebases older than a month have their share of these embarrassments.
You would think YouTube (owned by Google) would in short order also add such a button to comments. Haha, no. They didn't.
About a decade later, probably more, they finally implemented it, albeit only in desktop mode. Not a big deal, just millions and millions of unreadable comments for millions of users for many years. Was probably prioritized at #837,434,211.
You can have your translate button language different than your account language. (Which is the case for my account)
Thanks for calling out my research on this. Really glad you found it.
https://github.com/paulirish/lite-youtube-embed/pull/167 has my solution. Basically we only attempt the hqdefault.jpg and the sddefault.webp; no other ones. Based on my research this is (probably) the best solution that optimizes for both latency and coverage. Though, I could see switching the order of two in the future.
Pretty sure the oEmbed solutions folks are mentioning are only reasonable if you're doing this work server-side/eagerly. Obviously that changes things quite a bit.
shaneos•2d ago
degamad•16h ago
degamad•12h ago
insin•15h ago
Handling the fallback image has been sitting as an issue in the repo for a while, in favour of just checking it with the Astro dev server when I'm adding new videos, so… yoink‽
[1] https://github.com/insin/astro-lazy-youtube-embed#readme
[2] https://css-tricks.com/lazy-load-embedded-youtube-videos/
[3] https://jbscript.dev/notes/undefined/the-banterbox
degamad•12h ago
schiffern•12h ago
https://developers.google.com/youtube/v3/docs/thumbnails
Maxresdefault is overkill for this purpose IMO. Why waste the data? Incidentally this is why I run an add-on that redirects all youtube thumbnails to mqdefault, it saves me a nice chunk of bandwidth / memory / perf.