mediabunny 1.40.0 → 1.41.0

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.
@@ -837,6 +837,9 @@ var Mediabunny = (() => {
837
837
  timerId: timer.id
838
838
  });
839
839
  };
840
+ var isRecordStringString = (value) => {
841
+ return value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype && Object.values(value).every((x) => typeof x === "string");
842
+ };
840
843
 
841
844
  // src/metadata.ts
842
845
  var RichImageData = class {
@@ -940,9 +943,9 @@ var Mediabunny = (() => {
940
943
  throw new TypeError("tags.raw, when provided, must be an object.");
941
944
  }
942
945
  for (const value of Object.values(tags.raw)) {
943
- if (value !== null && typeof value !== "string" && !(value instanceof Uint8Array) && !(value instanceof RichImageData) && !(value instanceof AttachedFile)) {
946
+ if (value !== null && typeof value !== "string" && !(value instanceof Uint8Array) && !(value instanceof RichImageData) && !(value instanceof AttachedFile) && !isRecordStringString(value)) {
944
947
  throw new TypeError(
945
- "Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, or null."
948
+ "Each value in tags.raw must be a string, Uint8Array, RichImageData, AttachedFile, Record<string, string>, or null."
946
949
  );
947
950
  }
948
951
  }
@@ -11726,7 +11729,9 @@ var Mediabunny = (() => {
11726
11729
  defaultDuration: null,
11727
11730
  defaultDurationNs: null,
11728
11731
  name: null,
11729
- languageCode: UNDETERMINED_LANGUAGE,
11732
+ languageCode: "eng",
11733
+ // The default in Matroska
11734
+ hasLanguageBcp47: false,
11730
11735
  decodingInstructions: [],
11731
11736
  info: null
11732
11737
  };
@@ -11776,7 +11781,7 @@ var Mediabunny = (() => {
11776
11781
  const inputTrack = new InputVideoTrack(this.input, new MatroskaVideoTrackBacking(videoTrack));
11777
11782
  this.currentTrack.inputTrack = inputTrack;
11778
11783
  this.currentSegment.tracks.push(this.currentTrack);
11779
- } else if (this.currentTrack.info.type === "audio" && this.currentTrack.info.numberOfChannels !== -1 && this.currentTrack.info.sampleRate !== -1) {
11784
+ } else if (this.currentTrack.info.type === "audio") {
11780
11785
  if (codecIdWithoutSuffix === CODEC_STRING_MAP.aac) {
11781
11786
  this.currentTrack.info.codec = "aac";
11782
11787
  this.currentTrack.info.aacCodecInfo = {
@@ -11869,8 +11874,10 @@ var Mediabunny = (() => {
11869
11874
  } else if (type === 2) {
11870
11875
  this.currentTrack.info = {
11871
11876
  type: "audio",
11872
- numberOfChannels: -1,
11873
- sampleRate: -1,
11877
+ numberOfChannels: 1,
11878
+ // Default value
11879
+ sampleRate: 8e3,
11880
+ // Default value
11874
11881
  bitDepth: -1,
11875
11882
  codec: null,
11876
11883
  codecDescription: null,
@@ -11963,7 +11970,7 @@ var Mediabunny = (() => {
11963
11970
  case 2274716 /* Language */:
11964
11971
  {
11965
11972
  if (!this.currentTrack) break;
11966
- if (this.currentTrack.languageCode !== UNDETERMINED_LANGUAGE) {
11973
+ if (this.currentTrack.hasLanguageBcp47) {
11967
11974
  break;
11968
11975
  }
11969
11976
  this.currentTrack.languageCode = readAsciiString(slice, size);
@@ -11983,6 +11990,7 @@ var Mediabunny = (() => {
11983
11990
  } else {
11984
11991
  this.currentTrack.languageCode = UNDETERMINED_LANGUAGE;
11985
11992
  }
11993
+ this.currentTrack.hasLanguageBcp47 = true;
11986
11994
  }
11987
11995
  ;
11988
11996
  break;
@@ -19301,7 +19309,13 @@ var Mediabunny = (() => {
19301
19309
  reader.ununsynchronizeRegion(reader.pos, frameEndPos);
19302
19310
  }
19303
19311
  tags.raw ??= {};
19304
- if (frame.id[0] === "T") {
19312
+ if (frame.id === "TXXX") {
19313
+ const txxx = tags.raw["TXXX"] ??= {};
19314
+ const encoding = reader.readId3V2TextEncoding();
19315
+ const description = reader.readId3V2Text(encoding, frameEndPos);
19316
+ const value = reader.readId3V2Text(encoding, frameEndPos);
19317
+ txxx[description] ??= value;
19318
+ } else if (frame.id[0] === "T") {
19305
19319
  tags.raw[frame.id] ??= reader.readId3V2EncodingAndText(frameEndPos);
19306
19320
  } else {
19307
19321
  tags.raw[frame.id] ??= reader.readBytes(frame.size);
@@ -19803,12 +19817,44 @@ var Mediabunny = (() => {
19803
19817
  }
19804
19818
  let bytes2;
19805
19819
  if (typeof value === "string") {
19806
- const encoded = textEncoder.encode(value);
19807
- bytes2 = new Uint8Array(encoded.byteLength + 2);
19808
- bytes2[0] = 3 /* UTF_8 */;
19809
- bytes2.set(encoded, 1);
19820
+ const useIso88591 = isIso88591Compatible(value);
19821
+ if (useIso88591) {
19822
+ bytes2 = new Uint8Array(value.length + 2);
19823
+ bytes2[0] = 0 /* ISO_8859_1 */;
19824
+ for (let i = 0; i < value.length; i++) {
19825
+ bytes2[i + 1] = value.charCodeAt(i);
19826
+ }
19827
+ } else {
19828
+ const encoded = textEncoder.encode(value);
19829
+ bytes2 = new Uint8Array(encoded.byteLength + 2);
19830
+ bytes2[0] = 3 /* UTF_8 */;
19831
+ bytes2.set(encoded, 1);
19832
+ }
19810
19833
  } else if (value instanceof Uint8Array) {
19811
19834
  bytes2 = value;
19835
+ } else if (key === "TXXX" && isRecordStringString(value)) {
19836
+ for (const description in value) {
19837
+ const frameValue = value[description];
19838
+ const useIso88591 = isIso88591Compatible(description) && isIso88591Compatible(frameValue);
19839
+ const descriptionDataLength = useIso88591 ? description.length : textEncoder.encode(description).byteLength;
19840
+ const valueData = useIso88591 ? null : textEncoder.encode(frameValue);
19841
+ const valueDataLength = useIso88591 ? frameValue.length : valueData.byteLength;
19842
+ const frameSize = 1 + descriptionDataLength + 1 + valueDataLength;
19843
+ this.writeAscii("TXXX");
19844
+ this.writeSynchsafeU32(frameSize);
19845
+ this.writeU16(0);
19846
+ this.writeU8(useIso88591 ? 0 /* ISO_8859_1 */ : 3 /* UTF_8 */);
19847
+ if (useIso88591) {
19848
+ this.writeIsoString(description);
19849
+ for (let i = 0; i < frameValue.length; i++) {
19850
+ this.writeU8(frameValue.charCodeAt(i));
19851
+ }
19852
+ } else {
19853
+ this.writeUtf8String(description);
19854
+ this.writer.write(valueData);
19855
+ }
19856
+ }
19857
+ continue;
19812
19858
  } else {
19813
19859
  continue;
19814
19860
  }
@@ -19851,7 +19897,6 @@ var Mediabunny = (() => {
19851
19897
  for (let i = 0; i < text.length; i++) {
19852
19898
  bytes2[i] = text.charCodeAt(i);
19853
19899
  }
19854
- bytes2[text.length] = 0;
19855
19900
  this.writer.write(bytes2);
19856
19901
  }
19857
19902
  writeUtf8String(text) {