UNPKG

@ktt45678/vidstack

Version:

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

2 lines (1 loc) 698 B
const f=/(?:youtu\.be|youtube|youtube\.com|youtube-nocookie\.com)\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|)((?:\w|-){11})/,s=new Map,t=new Map;function d(e){return e.match(f)?.[1]}async function l(e,n){if(s.has(e))return s.get(e);if(t.has(e))return t.get(e);const o=new Promise(async c=>{const a=["maxresdefault","sddefault","hqdefault"];for(const r of a)for(const i of[!0,!1]){const u=b(e,r,i);if((await fetch(u,{mode:"no-cors",signal:n.signal})).status<400){s.set(e,u),c(u);return}}}).catch(()=>"").finally(()=>t.delete(e));return t.set(e,o),o}function b(e,n,o){return`https://i.ytimg.com/${o?"vi_webp":"vi"}/${e}/${n}.${o?"webp":"jpg"}`}export{l as findYouTubePoster,d as resolveYouTubeVideoId};