如何在 Javascript 中下载 YouTube 视频缩略图

How can I download an YouTube video thumbnail in Javascript

如何通过从 YouTube 创建 blob 文件将 YouTube 视频缩略图下载到我的机器上 API

您可以这样做来获取它:

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);