@geekapps/silo-elements-nextjs 0.3.24 → 0.3.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,14 +107,23 @@ var CHANNEL_LABELS = {
107
107
  };
108
108
  function friendlyAudioLabel(rawName, lang, codec, channels) {
109
109
  const langKey = (lang ?? "").toLowerCase();
110
- const langLabel = LANG_NAMES[langKey] ?? (lang ? lang.toUpperCase() : null);
111
- const codecKey = Object.keys(CODEC_LABELS).find((k) => codec.toLowerCase().includes(k));
110
+ const langLabel = LANG_NAMES[langKey] ?? (lang && lang.toLowerCase() !== "und" ? lang.toUpperCase() : "Original");
111
+ const chNum = typeof channels === "string" ? parseInt(channels, 10) : channels ?? 0;
112
+ const searchIn = [codec, rawName ?? ""].join(" ").toLowerCase();
113
+ const codecKey = Object.keys(CODEC_LABELS).find((k) => searchIn.includes(k));
112
114
  const codecLabel = codecKey ? CODEC_LABELS[codecKey] : null;
113
- const chLabel = channels ? CHANNEL_LABELS[channels] ?? `${channels}ch` : null;
114
- const looksHuman = rawName && !/^(und|dts|ac3|eac3|aac|opus|truehd|atmos|\w{2,3}-\d+ch|\w{2})/i.test(rawName) && rawName.length > 1;
115
- const baseName = looksHuman ? rawName : langLabel ?? "\xC1udio";
115
+ let resolvedCh = chNum > 0 ? chNum : 0;
116
+ if (!resolvedCh && rawName) {
117
+ const m = rawName.match(/(\d+)\.(\d+)/) ?? rawName.match(/(\d+)\s*ch/i);
118
+ if (m) {
119
+ if (m[2] !== void 0) resolvedCh = parseInt(m[1], 10) + (parseInt(m[2], 10) > 0 ? 1 : 0);
120
+ else resolvedCh = parseInt(m[1], 10);
121
+ } else if (/stereo/i.test(rawName)) resolvedCh = 2;
122
+ else if (/mono/i.test(rawName)) resolvedCh = 1;
123
+ }
124
+ const chLabel = resolvedCh ? CHANNEL_LABELS[resolvedCh] ?? `${resolvedCh}ch` : null;
116
125
  const suffix = [codecLabel, chLabel].filter(Boolean).join(" ");
117
- return suffix ? `${baseName} \u2014 ${suffix}` : baseName;
126
+ return suffix ? `${langLabel} \u2014 ${suffix}` : langLabel;
118
127
  }
119
128
  function isHdrLevel(level) {
120
129
  const range = level?.videoRange ?? level?.video_range ?? "";
@@ -776,6 +785,54 @@ function Video({
776
785
  try {
777
786
  const response = await fetch(parsed.storyboard.src);
778
787
  if (!response.ok) throw new Error("Storyboard not found");
788
+ const contentType = response.headers.get("content-type") ?? "";
789
+ if (contentType.includes("application/json")) {
790
+ const json = await response.json();
791
+ if (json.resolutions && Object.keys(json.resolutions).length > 0) {
792
+ storyboardCacheRef.current.clear();
793
+ preloadedSpritesRef.current.clear();
794
+ const RES_ORDER = ["180p", "240p", "360p", "480p", "default"];
795
+ const keys = Object.keys(json.resolutions).sort((a, b) => {
796
+ const ai = RES_ORDER.indexOf(a);
797
+ const bi = RES_ORDER.indexOf(b);
798
+ return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi);
799
+ });
800
+ const loadResFromApi = async (key) => {
801
+ if (cancelled) return;
802
+ const res = json.resolutions[key];
803
+ if (!res) return;
804
+ const vttResp = await fetch(res.vttUrl);
805
+ if (!vttResp.ok) return;
806
+ const vttText = await vttResp.text();
807
+ const cues2 = parseStoryboardVtt(vttText, res.vttUrl);
808
+ storyboardCacheRef.current.set(key, cues2);
809
+ const firstSprite = cues2[0]?.image;
810
+ if (firstSprite && !preloadedSpritesRef.current.has(firstSprite)) {
811
+ preloadedSpritesRef.current.add(firstSprite);
812
+ const img = new window.Image();
813
+ img.src = firstSprite;
814
+ }
815
+ return cues2;
816
+ };
817
+ const firstCues = await loadResFromApi(keys[0]);
818
+ if (!cancelled && firstCues) {
819
+ setStoryboardCues(firstCues);
820
+ setActiveStoryboardRes(keys[0]);
821
+ }
822
+ for (const key of keys.slice(1)) await loadResFromApi(key);
823
+ return;
824
+ }
825
+ if (json.url) {
826
+ const vttResp = await fetch(json.url);
827
+ if (vttResp.ok) {
828
+ const text2 = await vttResp.text();
829
+ const spriteUrl = json.url.replace(/\/vtt(\?|$)/, "/sprite$1");
830
+ const cues2 = parseStoryboardVtt(text2, spriteUrl);
831
+ if (!cancelled) setStoryboardCues(cues2);
832
+ }
833
+ }
834
+ return;
835
+ }
779
836
  const text = await response.text();
780
837
  const cues = parseStoryboardVtt(text, new URL(parsed.storyboard.src, window.location.href).href);
781
838
  if (!cancelled) setStoryboardCues(cues);