UNPKG

@7sage/vidstack

Version:

UI component library for building high-quality, accessible video and audio experiences on the web.

2 lines (1 loc) 798 B
const p=/(?:https:\/\/)?(?:player\.)?vimeo(?:\.com)?\/(?:video\/)?(\d+)(?:(?:\?hash=|\?h=|\/)(.*))?/,c=new Map,o=new Map;function u(e){const n=e.match(p);return{videoId:n?.[1],hash:n?.[2]}}async function f(e,n,s){if(c.has(e))return c.get(e);if(o.has(e))return o.get(e);let i=`https://vimeo.com/api/oembed.json?url=https://player.vimeo.com/video/${e}`;s&&(i=i.concat(`?h=${s}`));const r=window.fetch(i,{mode:"cors",signal:n.signal}).then(t=>t.json()).then(t=>{const a=/vimeocdn.com\/video\/(.*)?_/,h=t?.thumbnail_url?.match(a)?.[1],l=h?`https://i.vimeocdn.com/video/${h}_1920x1080.webp`:"",m={title:t?.title??"",duration:t?.duration??0,poster:l,pro:t.account_type!=="basic"};return c.set(e,m),m}).finally(()=>o.delete(e));return o.set(e,r),r}export{f as getVimeoVideoInfo,u as resolveVimeoVideoId};