I have written this script for getting thumbnail from vimeo. But getting this result as promise Object. Actually, I want this result a thumbnail.
let url ='https://vimeo.com/535319285';
const getVimeoThumbnail = (url) => {
if (url) {
var video_id, thumbnail, result;
if (url.match(/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/)) {
video_id = url.split('/')[3];
}
else if (url.match(/^vimeo.com\/channels\/[\d\w]+#[0-9]+/)) {
video_id = url.split('#')[1];
}
else if (url.match(/vimeo.com\/groups\/[\d\w]+\/videos\/[0-9]+/)) {
video_id = url.split('/')[4];
}
else if (url.match(/player.vimeo.com\/video\/[0-9]+/)) {
video_id = url.split('/')[2];
}
result = new Promise((resolve, reject) => {
fetch('https://vimeo.com/api/oembed.json?url=https%3A//vimeo.com/' + video_id)
.then(response => {
response.json().then((jsonData) => {
thumbnail = jsonData.thumbnail_url;
resolve(thumbnail);
}).catch((error) => {
console.error(error);
reject(false);
})
});
});
console.log("Result ::", result);
return result;
}
}