-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update youtube placeholder default image url #235
base: main
Are you sure you want to change the base?
Conversation
@serkodev is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
Hey, thanks for the work! I think this is a reasonable solution however we need to be mindful as this may break the look and feel of current users videos given the size difference, the current is 640x480 with this change it becomes 480x360. Do you have any ideas on how to workaround this? I think the ideal case is probably two things:
|
Also I'd still go with the |
If we provide props to choose the thumbnail size or WebP format, I believe we don't have a perfect solution to detect if a YouTube video doesn't support these options.
There's a somewhat hacky method that involves detecting the image size. The only drawback is that if the original image request (e.g., However, if we only provide props for thumbnail size or WebP format and let users determine whether the image is supported, then we might not need to detect if it's a 404 at all. That's all I can think of for now. π€£ |
I think the dimension heuristic is good enough and is free compared to doing extra requests manually. <img src="https://i.ytimg.com/vi_webp/jNQXAC9IVRw/sddefault.webp" onload="if (this.naturalWidth == 120 && this.naturalHeight == 90) { (this.src = `https://i.ytimg.com/vi/jNQXAC9IVRw/hqdefault.jpg`) }" /> We should warn the developer in development that they should use the props when this fallback occurs. |
Thanks for the feedback. How about the behavior of the
As discussed previously, we can pass all formats of thumbnail links for the user to choose from. If we directly turn
|
const placeholder = computed(() => `https://i.ytimg.com/vi_webp/${props.videoId}/sddefault.webp`) | ||
const isFallbackPlaceHolder = ref(false) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type YouTubeThumbnailType = | |
// 120x90 | |
'1' | '2' | '3' | 'default' | | |
// 320x180 | |
'mq1' | 'mq2' | 'mq3' | 'mqdefault' | | |
// 480x360 | |
'0' | 'hq1' | 'hq2' | 'hq3' | 'hqdefault' | | |
// 640x480 | |
'sd1' | 'sd2' | 'sd3' | 'sddefault' | | |
// 1280x720 | |
'hq720' | | |
// 1920x1080 | |
'maxresdefault' | |
function getYouTubeThumbnail(type: YouTubeThumbnailType, webp = false) { | |
return `https://i.ytimg.com/${webp ? 'vi_webp' : 'vi'}/${props.videoId}/${type}.${webp ? 'webp' : 'jpg'}` | |
} |
Just draft a function to get YouTube thumbnail here. I think we can use this for placeholder
or provide for user to use?
π Linked issue
Fix #234
β Type of change
π Description
Update the youtube placeholder url to
https://i.ytimg.com/vi/${props.videoId}/hqdefault.jpg
.This thumbnail image url is guaranteed to exist. (Reference)