Fighting with YouTube to show a preview image
shaneosullivan.wordpress.com
Fighting with YouTube to show a preview image
1–10 of 24 posts
Re: Fighting with YouTube to show a preview image
#2Re: Fighting with YouTube to show a preview image
#3Author here, hi all. There are a number of ways to skin this cat. This is my preferred method. What's yours?
Re: Fighting with YouTube to show a preview image
#4 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//thumbnail.webp as the image source or adapt the location regex as needed. This can be chained with yet more fallback URLs.Re: Fighting with YouTube to show a preview image
#5Author here, hi all. There are a number of ways to skin this cat. This is my preferred method. What's yours?
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/
Re: Fighting with YouTube to show a preview image
#6Re: Fighting with YouTube to show a preview image
#7If you're designing the website, why depend on a YT thumbnail? Can't you just use your own image that you have control over, and then load the actual YT when clicked? So many image gallery style components do this. Even if you don't need a gallery, it shows it is clearly possible. It's not like you're trying to work when JS is blocked
Re: Fighting with YouTube to show a preview image
#8As 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.
Re: Fighting with YouTube to show a preview image
#9If you're designing the website, why depend on a YT thumbnail? Can't you just use your own image that you have control over, and then load the actual YT when clicked? So many image gallery style components do this. Even if you don't need a gallery, it shows it is clearly possible. It's not like you're trying to work when JS is blocked
You’d probably want it to match YouTube’s preview image, so if your reader sees the video on YouTube proper at a later date, they’ll recognize it. I’m not sure of a good way to do that, since it’s not necessarily a screengrab from the middle of the video.
Re: Fighting with YouTube to show a preview image
#10Author here, hi all. There are a number of ways to skin this cat. This is my preferred method. What's yours?
iurl: "default.jpg",
iurlmq: "mqdefault.jpg",
iurlhq: "hqdefault.jpg",
iurlsd: "sddefault.jpg",
iurlpop1: "pop1.jpg",
iurlpop2: "pop2.jpg",
iurlhq720: "hq720.jpg",
iurlmaxres: "maxresdefault.jpg"
120: "default.jpg",
320: "mqdefault.jpg",
480: "hqdefault.jpg",
560: "pop1.jpg",
640: "sddefault.jpg",
854: "pop2.jpg",
1280: "hq720.jpg"