如何通过从 YouTube API 创建 blob 文件将 YouTube 视频缩略图下载到我的机器
答案 0 :(得分:1)
你可以这样做来获取它:
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);