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