How can I download YouTube video Thumbnail to my machine by creating a blob file from the YouTube API
Asked
Active
Viewed 753 times
1
-
You can use online tool to get YouTube thumbnail https://www.workversatile.com/youtube-thumbnail-downloader – Arshad Shaikh Aug 23 '22 at 18:25
1 Answers
2
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);

Alen Vlahovljak
- 542
- 3
- 16
-
Hey Alen can u please let me know what wrong in https://stackoverflow.com/questions/67265422/youtube-thumbnail-download-cors-error-on-firefox-and-safari-works-fine-on-chrom – virendra parade Apr 26 '21 at 13:26
-
-
can you try out this link: https://stackoverflow.com/questions/67269963/works-fine-in-chrome-but-access-control-allow-origin-missing-issues-in-firefox – virendra parade Apr 27 '21 at 03:31
-
@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](https://addons.mozilla.org/en-US/firefox/addon/cors-everywhere/) extension – Alen Vlahovljak Apr 27 '21 at 08:35