var e=`en-US`;function t(e){try{let t=new URL(e).hostname.toLowerCase();return t===`youtu.be`||t.endsWith(`.youtu.be`)||t===`youtube.com`||t.endsWith(`.youtube.com`)}catch{return!1}}function n(e,t){if(e.length===0)return null;let n=e[0],r=t(n);for(let i=1;i<e.length;i++){let a=t(e[i]);a>r&&(n=e[i],r=a)}return n}function r(e){return(e??``).toLowerCase().split(`-`)[0]}function i(e,t){return e?e.toLowerCase()===t.toLowerCase()?2:+(r(e)===r(t)):0}function a(e,t,r=()=>0){if(e.length===0)return null;let a=n(e,r);if(!a)return null;let o=r(a),s=e.filter(e=>r(e)===o),c=s[0],l=i(c.language,t);for(let e=1;e<s.length;e++){let n=i(s[e].language,t);n>l&&(c=s[e],l=n)}return c}function o(n,r=e){let i=n.stats?.streamLinks??[];if(i.length===0)return null;let o=(n.status??``).toLowerCase();if(o===`live`){let e=a(i.filter(e=>e.kind===`live-official`),r);if(e)return e;let n=a(i.filter(e=>e.kind===`live-co-stream`),r,e=>e.concurrentViewers??0);if(n)return n;let o=i.filter(e=>e.kind!==`vod-official`&&e.kind!==`vod-co-stream`);return o.find(e=>t(e.url))||(o[0]??null)}return o===`completed`?a(i.filter(e=>e.kind===`vod-official`),r)||a(i.filter(e=>e.kind===`vod-co-stream`),r,e=>e.viewCount??0)||i.find(e=>t(e.url))||i[0]:o===`scheduled`?a(i.filter(e=>e.kind===`live-official`),r)??null:null}function s(e){try{let t=new URL(e);if(t.hostname.includes(`youtu.be`))return t.pathname.slice(1).split(`/`)[0]||null;if(t.hostname.includes(`youtube.com`)){if(t.pathname===`/watch`||t.pathname===`/watch/`)return t.searchParams.get(`v`);if(t.pathname.startsWith(`/live/`)||t.pathname.startsWith(`/embed/`))return t.pathname.split(`/`)[2]||null}return null}catch{return null}}export{s as i,i as n,o as r,e as t};