Skip to content

Commit

Permalink
feat: use Vimeo API directly. starting to cost me
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Nov 23, 2023
1 parent cef4c56 commit 1c033d2
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lite-vimeo-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,11 @@ class LiteVimeo extends (globalThis.HTMLElement ?? class {}) {
width = Math.round(width * devicePixelRatio);
height = Math.round(height * devicePixelRatio);

const oEmbedUrl = new URL('https://api.playerx.io/oembed');
oEmbedUrl.searchParams.set('url', `https://vimeo.com/${this.videoId}`);
oEmbedUrl.searchParams.set('fields', 'thumbnail_url');

fetch(oEmbedUrl)
fetch(`https://vimeo.com/api/v2/video/${this.videoId}.json`)
.then(response => response.json())
.then(data => {
let thumbnailUrl = data.thumbnail_url;
let thumbnailUrl = data[0].thumbnail_large;
thumbnailUrl = thumbnailUrl.replace(/-d_[\dx]+$/i, `-d_${width}x${height}`);

this.style.backgroundImage = `url("${thumbnailUrl}")`;
});

Expand Down

0 comments on commit 1c033d2

Please sign in to comment.