How can I download YouTube video Thumbnail to my machine by creating a blob file from the YouTube API
1 Answer
You can do this to fetch it:
const youtube = (function () {
let video, results;
const getThumbnail = function (url, size) {
if (url == null) {
return '';
}
size = (size == null) ? 'big' : size;
results = url.match('[\\?&]v=([^&#]*)');
video = (results == null) ? url : results[1];
if (size == 'small') {
return `http://img.youtube.com/vi/${video}/2.jpg`;
}
return `http://img.youtube.com/vi/${video}/0.jpg`;
};
return {
thumbnail: getThumbnail
};
}());
//Example of usage:
const thumbnail = youtube.thumbnail("http://www.youtube.com/watch?v=Tn6-PIqc4UM", "small")
console.log(thumbnail);
4 Comments
virendra parade
Hey Alen can u please let me know what wrong in stackoverflow.com/questions/67265422/…
Alen Vlahovljak
@virendraparade Page not found. I cannot open it.
virendra parade
can you try out this link: stackoverflow.com/questions/67269963/…
Alen Vlahovljak
@virendraparade I think the problem is because you're trying to fetch this from localhost, if you try to do that from production, it will work. Can you try to solve your problem with this extension