@openclaw/matrix 2026.9.34 → 2026.9.36

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.
Files changed (113) hide show
  1. package/dist/.setup/{channel-C0oyQ_i7.mjs → channel-BrgqoNpg.mjs} +3 -3
  2. package/dist/.setup/{channel.runtime-rboo2n9O.mjs → channel.runtime-DY4jJxW5.mjs} +1 -1
  3. package/dist/.setup/{monitor-BqBMKRwe.mjs → monitor-Ck8bkvK8.mjs} +11 -9
  4. package/dist/.setup/{outbound-BfgLFAJj.mjs → outbound-DfkxX7Z8.mjs} +1 -1
  5. package/dist/.setup/{reaction-events-CbRb1mUg.mjs → reaction-events-DmXtH5hh.mjs} +2 -2
  6. package/dist/.setup/{tool-actions-CdltFa1G.mjs → tool-actions-BsbYNn27.mjs} +1 -1
  7. package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -0
  8. package/dist/api.js +1 -1
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/node_modules/music-metadata/README.md +35 -32
  11. package/node_modules/music-metadata/lib/ParserFactory.d.ts +1 -1
  12. package/node_modules/music-metadata/lib/ParserFactory.js +17 -13
  13. package/node_modules/music-metadata/lib/aiff/AiffParser.js +19 -12
  14. package/node_modules/music-metadata/lib/aiff/AiffToken.d.ts +1 -1
  15. package/node_modules/music-metadata/lib/aiff/AiffToken.js +2 -1
  16. package/node_modules/music-metadata/lib/apev2/APEv2Parser.d.ts +4 -3
  17. package/node_modules/music-metadata/lib/apev2/APEv2Parser.js +59 -16
  18. package/node_modules/music-metadata/lib/apev2/APEv2TagMapper.js +1 -0
  19. package/node_modules/music-metadata/lib/apev2/APEv2Token.d.ts +1 -1
  20. package/node_modules/music-metadata/lib/apev2/APEv2Token.js +1 -1
  21. package/node_modules/music-metadata/lib/asf/AsfGuid.js +56 -50
  22. package/node_modules/music-metadata/lib/asf/AsfObject.d.ts +1 -1
  23. package/node_modules/music-metadata/lib/asf/AsfObject.js +3 -2
  24. package/node_modules/music-metadata/lib/asf/AsfParser.js +15 -7
  25. package/node_modules/music-metadata/lib/asf/AsfTagMapper.d.ts +3 -2
  26. package/node_modules/music-metadata/lib/asf/AsfTagMapper.js +21 -4
  27. package/node_modules/music-metadata/lib/common/CaseInsensitiveTagMap.d.ts +1 -1
  28. package/node_modules/music-metadata/lib/common/CombinedTagMapper.d.ts +2 -2
  29. package/node_modules/music-metadata/lib/common/CombinedTagMapper.js +6 -6
  30. package/node_modules/music-metadata/lib/common/FourCC.js +3 -2
  31. package/node_modules/music-metadata/lib/common/GenericTagMapper.d.ts +1 -1
  32. package/node_modules/music-metadata/lib/common/GenericTagTypes.js +1 -1
  33. package/node_modules/music-metadata/lib/common/MetadataCollector.d.ts +3 -1
  34. package/node_modules/music-metadata/lib/common/MetadataCollector.js +28 -9
  35. package/node_modules/music-metadata/lib/common/Util.js +25 -17
  36. package/node_modules/music-metadata/lib/core.d.ts +4 -4
  37. package/node_modules/music-metadata/lib/core.js +18 -11
  38. package/node_modules/music-metadata/lib/dsdiff/DsdiffParser.js +29 -16
  39. package/node_modules/music-metadata/lib/dsf/DsfChunk.d.ts +1 -1
  40. package/node_modules/music-metadata/lib/dsf/DsfParser.js +3 -5
  41. package/node_modules/music-metadata/lib/ebml/EbmlIterator.d.ts +1 -1
  42. package/node_modules/music-metadata/lib/ebml/EbmlIterator.js +35 -6
  43. package/node_modules/music-metadata/lib/ebml/types.d.ts +1 -1
  44. package/node_modules/music-metadata/lib/ebml/types.js +1 -1
  45. package/node_modules/music-metadata/lib/flac/FlacParser.d.ts +1 -1
  46. package/node_modules/music-metadata/lib/flac/FlacParser.js +6 -5
  47. package/node_modules/music-metadata/lib/flac/FlacToken.d.ts +1 -1
  48. package/node_modules/music-metadata/lib/flac/FlacToken.js +1 -1
  49. package/node_modules/music-metadata/lib/id3v1/ID3v1Parser.d.ts +1 -1
  50. package/node_modules/music-metadata/lib/id3v1/ID3v1Parser.js +212 -42
  51. package/node_modules/music-metadata/lib/id3v2/AbstractID3Parser.js +5 -5
  52. package/node_modules/music-metadata/lib/id3v2/FrameHeader.d.ts +1 -1
  53. package/node_modules/music-metadata/lib/id3v2/FrameHeader.js +8 -5
  54. package/node_modules/music-metadata/lib/id3v2/FrameParser.d.ts +2 -1
  55. package/node_modules/music-metadata/lib/id3v2/FrameParser.js +53 -22
  56. package/node_modules/music-metadata/lib/id3v2/ID3v22TagMapper.d.ts +1 -1
  57. package/node_modules/music-metadata/lib/id3v2/ID3v22TagMapper.js +1 -1
  58. package/node_modules/music-metadata/lib/id3v2/ID3v24TagMapper.js +3 -3
  59. package/node_modules/music-metadata/lib/id3v2/ID3v2ChapterToken.js +2 -2
  60. package/node_modules/music-metadata/lib/id3v2/ID3v2Parser.d.ts +1 -1
  61. package/node_modules/music-metadata/lib/id3v2/ID3v2Parser.js +32 -16
  62. package/node_modules/music-metadata/lib/id3v2/ID3v2Token.d.ts +2 -2
  63. package/node_modules/music-metadata/lib/id3v2/ID3v2Token.js +2 -3
  64. package/node_modules/music-metadata/lib/index.js +6 -3
  65. package/node_modules/music-metadata/lib/lrc/LyricsParser.js +3 -5
  66. package/node_modules/music-metadata/lib/matroska/MatroskaDtd.js +7 -3
  67. package/node_modules/music-metadata/lib/matroska/MatroskaParser.js +22 -11
  68. package/node_modules/music-metadata/lib/matroska/types.d.ts +2 -2
  69. package/node_modules/music-metadata/lib/mp4/Atom.d.ts +4 -3
  70. package/node_modules/music-metadata/lib/mp4/Atom.js +44 -11
  71. package/node_modules/music-metadata/lib/mp4/AtomToken.d.ts +1 -1
  72. package/node_modules/music-metadata/lib/mp4/AtomToken.js +30 -8
  73. package/node_modules/music-metadata/lib/mp4/MP4Parser.d.ts +2 -0
  74. package/node_modules/music-metadata/lib/mp4/MP4Parser.js +79 -54
  75. package/node_modules/music-metadata/lib/mp4/MP4TagMapper.d.ts +2 -2
  76. package/node_modules/music-metadata/lib/mpeg/MpegLoader.js +1 -1
  77. package/node_modules/music-metadata/lib/mpeg/MpegParser.js +41 -19
  78. package/node_modules/music-metadata/lib/mpeg/ReplayGainDataFormat.d.ts +2 -2
  79. package/node_modules/music-metadata/lib/mpeg/ReplayGainDataFormat.js +1 -1
  80. package/node_modules/music-metadata/lib/mpeg/XingTag.d.ts +1 -1
  81. package/node_modules/music-metadata/lib/musepack/MusepackParser.js +2 -2
  82. package/node_modules/music-metadata/lib/musepack/sv7/BitReader.js +1 -1
  83. package/node_modules/music-metadata/lib/musepack/sv7/MpcSv7Parser.js +4 -3
  84. package/node_modules/music-metadata/lib/musepack/sv7/StreamVersion7.js +3 -3
  85. package/node_modules/music-metadata/lib/musepack/sv8/MpcSv8Parser.js +7 -5
  86. package/node_modules/music-metadata/lib/musepack/sv8/StreamVersion8.js +2 -2
  87. package/node_modules/music-metadata/lib/ogg/OggParser.js +16 -12
  88. package/node_modules/music-metadata/lib/ogg/OggToken.js +1 -1
  89. package/node_modules/music-metadata/lib/ogg/flac/FlacStream.d.ts +2 -2
  90. package/node_modules/music-metadata/lib/ogg/flac/FlacStream.js +2 -2
  91. package/node_modules/music-metadata/lib/ogg/opus/OpusStream.d.ts +2 -2
  92. package/node_modules/music-metadata/lib/ogg/opus/OpusStream.js +8 -4
  93. package/node_modules/music-metadata/lib/ogg/speex/SpeexStream.d.ts +2 -2
  94. package/node_modules/music-metadata/lib/ogg/speex/SpeexStream.js +2 -1
  95. package/node_modules/music-metadata/lib/ogg/theora/TheoraStream.d.ts +2 -2
  96. package/node_modules/music-metadata/lib/ogg/vorbis/Vorbis.d.ts +1 -1
  97. package/node_modules/music-metadata/lib/ogg/vorbis/VorbisDecoder.js +1 -1
  98. package/node_modules/music-metadata/lib/ogg/vorbis/VorbisStream.d.ts +3 -3
  99. package/node_modules/music-metadata/lib/ogg/vorbis/VorbisStream.js +14 -9
  100. package/node_modules/music-metadata/lib/ogg/vorbis/VorbisTagMapper.js +4 -0
  101. package/node_modules/music-metadata/lib/riff/RiffChunk.d.ts +3 -1
  102. package/node_modules/music-metadata/lib/riff/RiffChunk.js +3 -2
  103. package/node_modules/music-metadata/lib/riff/RiffInfoTagMap.d.ts +1 -1
  104. package/node_modules/music-metadata/lib/type.d.ts +3 -3
  105. package/node_modules/music-metadata/lib/type.js +1 -1
  106. package/node_modules/music-metadata/lib/wav/WaveChunk.d.ts +1 -1
  107. package/node_modules/music-metadata/lib/wav/WaveChunk.js +3 -2
  108. package/node_modules/music-metadata/lib/wav/WaveParser.d.ts +6 -2
  109. package/node_modules/music-metadata/lib/wav/WaveParser.js +75 -22
  110. package/node_modules/music-metadata/lib/wavpack/WavPackParser.js +22 -13
  111. package/node_modules/music-metadata/lib/wavpack/WavPackToken.js +3 -2
  112. package/node_modules/music-metadata/package.json +3 -2
  113. package/package.json +5 -5
@@ -1,13 +1,25 @@
1
- import { TrackTypeValueToKeyMap, } from '../type.js';
2
1
  import initDebug from 'debug';
3
- import { isSingleton, isUnique } from './GenericTagTypes.js';
2
+ import { fileTypeFromBuffer } from 'file-type';
3
+ import { parseLyrics } from '../lrc/LyricsParser.js';
4
+ import { TrackTypeValueToKeyMap } from '../type.js';
4
5
  import { CombinedTagMapper } from './CombinedTagMapper.js';
5
6
  import { CommonTagMapper } from './GenericTagMapper.js';
7
+ import { isSingleton, isUnique } from './GenericTagTypes.js';
6
8
  import { toRatio } from './Util.js';
7
- import { fileTypeFromBuffer } from 'file-type';
8
- import { parseLyrics } from '../lrc/LyricsParser.js';
9
9
  const debug = initDebug('music-metadata:collector');
10
- const TagPriority = ['matroska', 'APEv2', 'vorbis', 'ID3v2.4', 'ID3v2.3', 'ID3v2.2', 'exif', 'asf', 'iTunes', 'AIFF', 'ID3v1'];
10
+ const TagPriority = [
11
+ 'matroska',
12
+ 'APEv2',
13
+ 'vorbis',
14
+ 'ID3v2.4',
15
+ 'ID3v2.3',
16
+ 'ID3v2.2',
17
+ 'exif',
18
+ 'asf',
19
+ 'iTunes',
20
+ 'AIFF',
21
+ 'ID3v1'
22
+ ];
11
23
  /**
12
24
  * Provided to the parser to uodate the metadata result.
13
25
  * Responsible for triggering async updates
@@ -65,10 +77,15 @@ export class MetadataCollector {
65
77
  this.setFormat('hasAudio', true);
66
78
  this.setFormat('hasVideo', false);
67
79
  }
80
+ registerTagType(tagType) {
81
+ if (!this.format.tagTypes.includes(tagType)) {
82
+ this.format.tagTypes.push(tagType);
83
+ }
84
+ }
68
85
  async addTag(tagType, tagId, value) {
69
86
  debug(`tag ${tagType}.${tagId} = ${value}`);
70
87
  if (!this.native[tagType]) {
71
- this.format.tagTypes.push(tagType);
88
+ this.registerTagType(tagType);
72
89
  this.native[tagType] = [];
73
90
  }
74
91
  this.native[tagType].push({ id: tagId, value });
@@ -158,10 +175,12 @@ export class MetadataCollector {
158
175
  case 'showMovement':
159
176
  tag.value = tag.value === '1' || tag.value === 1; // boolean
160
177
  break;
161
- case 'isrc': { // Only keep unique values
178
+ case 'isrc': {
179
+ // Only keep unique values
162
180
  const commonTag = this.common[tag.id];
163
- if (commonTag && commonTag.indexOf(tag.value) !== -1)
181
+ if (commonTag && commonTag.indexOf(tag.value) !== -1) {
164
182
  return;
183
+ }
165
184
  break;
166
185
  }
167
186
  case 'comment':
@@ -246,7 +265,7 @@ export class MetadataCollector {
246
265
  }
247
266
  return picture;
248
267
  }
249
- this.addWarning("Empty picture tag found");
268
+ this.addWarning('Empty picture tag found');
250
269
  return null;
251
270
  }
252
271
  /**
@@ -1,6 +1,6 @@
1
1
  import { StringType } from 'token-types';
2
- import { FieldDecodingError } from '../ParseError.js';
3
2
  import { getUintBE } from 'uint8array-extras';
3
+ import { FieldDecodingError } from '../ParseError.js';
4
4
  export function getBit(buf, off, bit) {
5
5
  return (buf[off] & (1 << bit)) !== 0;
6
6
  }
@@ -15,15 +15,17 @@ export function findZero(uint8Array, encoding) {
15
15
  if (encoding === 'utf-16le' || encoding === 'utf-16be') {
16
16
  // Look for 0x00 0x00 on 2-byte boundary
17
17
  for (let i = 0; i + 1 < len; i += 2) {
18
- if (uint8Array[i] === 0 && uint8Array[i + 1] === 0)
18
+ if (uint8Array[i] === 0 && uint8Array[i + 1] === 0) {
19
19
  return i;
20
+ }
20
21
  }
21
22
  return len;
22
23
  }
23
24
  // latin1 / utf8 / utf16be (caller typically handles utf16be separately or via decode)
24
25
  for (let i = 0; i < len; i++) {
25
- if (uint8Array[i] === 0)
26
+ if (uint8Array[i] === 0) {
26
27
  return i;
28
+ }
27
29
  }
28
30
  return len;
29
31
  }
@@ -33,8 +35,9 @@ export function trimRightNull(x) {
33
35
  }
34
36
  function swapBytes(uint8Array) {
35
37
  const l = uint8Array.length;
36
- if ((l & 1) !== 0)
38
+ if ((l & 1) !== 0) {
37
39
  throw new FieldDecodingError('Buffer length must be even');
40
+ }
38
41
  for (let i = 0; i < l; i += 2) {
39
42
  const a = uint8Array[i];
40
43
  uint8Array[i] = uint8Array[i + 1];
@@ -48,19 +51,22 @@ function swapBytes(uint8Array) {
48
51
  export function decodeString(uint8Array, encoding) {
49
52
  // annoying workaround for a double BOM issue
50
53
  // https://github.com/leetreveil/musicmetadata/issues/84
51
- if (uint8Array[0] === 0xFF && uint8Array[1] === 0xFE) { // little endian
54
+ if (uint8Array[0] === 0xff && uint8Array[1] === 0xfe) {
55
+ // little endian
52
56
  return decodeString(uint8Array.subarray(2), encoding);
53
57
  }
54
- if (encoding === 'utf-16le' && uint8Array[0] === 0xFE && uint8Array[1] === 0xFF) {
58
+ if (encoding === 'utf-16le' && uint8Array[0] === 0xfe && uint8Array[1] === 0xff) {
55
59
  // BOM, indicating big endian decoding
56
- if ((uint8Array.length & 1) !== 0)
60
+ if ((uint8Array.length & 1) !== 0) {
57
61
  throw new FieldDecodingError('Expected even number of octets for 16-bit unicode string');
62
+ }
58
63
  return decodeString(swapBytes(uint8Array), encoding);
59
64
  }
60
65
  if (encoding === 'utf-16be') {
61
66
  // There is no native UTF-16BE decoder; swap to UTF-16LE and decode that.
62
- if ((uint8Array.length & 1) !== 0)
67
+ if ((uint8Array.length & 1) !== 0) {
63
68
  throw new FieldDecodingError('Expected even number of octets for 16-bit unicode string');
69
+ }
64
70
  return new StringType(uint8Array.length, 'utf-16le').get(swapBytes(Uint8Array.from(uint8Array)), 0);
65
71
  }
66
72
  return new StringType(uint8Array.length, encoding).get(uint8Array, 0);
@@ -87,7 +93,7 @@ export function getBitAllignedNumber(source, byteOffset, bitOffset, len) {
87
93
  const bitsRead = 8 - bitOff;
88
94
  const bitsLeft = len - bitsRead;
89
95
  if (bitsLeft < 0) {
90
- value >>= (8 - bitOff - len);
96
+ value >>= 8 - bitOff - len;
91
97
  }
92
98
  else if (bitsLeft > 0) {
93
99
  value <<= bitsLeft;
@@ -136,13 +142,15 @@ export function toRatio(value) {
136
142
  const ps = value.split(' ').map(p => p.trim().toLowerCase());
137
143
  if (ps.length >= 1) {
138
144
  const v = Number.parseFloat(ps[0]);
139
- return ps.length === 2 && ps[1] === 'db' ? {
140
- dB: v,
141
- ratio: dbToRatio(v)
142
- } : {
143
- dB: ratioToDb(v),
144
- ratio: v
145
- };
145
+ return ps.length === 2 && ps[1] === 'db'
146
+ ? {
147
+ dB: v,
148
+ ratio: dbToRatio(v)
149
+ }
150
+ : {
151
+ dB: ratioToDb(v),
152
+ ratio: v
153
+ };
146
154
  }
147
155
  }
148
156
  /**
@@ -151,7 +159,7 @@ export function toRatio(value) {
151
159
  */
152
160
  export function decodeUintBE(uint8Array) {
153
161
  if (uint8Array.length === 0) {
154
- throw new Error("decodeUintBE: empty Uint8Array");
162
+ throw new Error('decodeUintBE: empty Uint8Array');
155
163
  }
156
164
  const view = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength);
157
165
  return getUintBE(view);
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Primary entry point, Node.js specific entry point is MusepackParser.ts
3
3
  */
4
- import { type AnyWebByteStream, type IFileInfo, type ITokenizer, type IRandomAccessTokenizer } from 'strtok3';
5
- import type { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions, ITag } from './type.js';
6
4
  import type { Readable } from 'node:stream';
5
+ import { type AnyWebByteStream, type IFileInfo, type IRandomAccessTokenizer, type ITokenizer } from 'strtok3';
6
+ import type { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions, ITag } from './type.js';
7
7
  export type { IFileInfo } from 'strtok3';
8
- export { type IAudioMetadata, type IOptions, type ITag, type INativeTagDict, type ICommonTagsResult, type IFormat, type IPicture, type IRatio, type IChapter, type ILyricsTag, LyricsContentType, TimestampFormat, IMetadataEventTag, IMetadataEvent } from './type.js';
9
- export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
10
8
  export * from './ParseError.js';
9
+ export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
10
+ export { type IAudioMetadata, type IChapter, type ICommonTagsResult, type IFormat, type ILyricsTag, type IMetadataEvent, type IMetadataEventTag, type INativeTagDict, type IOptions, type IPicture, type IRatio, type ITag, LyricsContentType, TimestampFormat } from './type.js';
11
11
  /**
12
12
  * Parse Web API File
13
13
  * Requires Blob to be able to stream using a ReadableStreamBYOBReader, only available since Node.js ≥ 20
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * Primary entry point, Node.js specific entry point is MusepackParser.ts
3
3
  */
4
- import { fromWebStream, fromBuffer, fromBlob } from 'strtok3';
5
- import { ParserFactory } from './ParserFactory.js';
4
+ import { fromBlob, fromBuffer, fromWebStream } from 'strtok3';
6
5
  import { APEv2Parser } from './apev2/APEv2Parser.js';
7
6
  import { hasID3v1Header } from './id3v1/ID3v1Parser.js';
8
7
  import { getLyricsHeaderLength } from './lyrics3/Lyrics3.js';
9
- export { LyricsContentType, TimestampFormat } from './type.js';
10
- export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
8
+ import { ParserFactory } from './ParserFactory.js';
11
9
  export * from './ParseError.js';
10
+ export { CouldNotDetermineFileTypeError, UnsupportedFileTypeError } from './ParseError.js';
11
+ export { LyricsContentType, TimestampFormat } from './type.js';
12
12
  /**
13
13
  * Parse Web API File
14
14
  * Requires Blob to be able to stream using a ReadableStreamBYOBReader, only available since Node.js ≥ 20
@@ -33,7 +33,9 @@ export async function parseBlob(blob, options = {}) {
33
33
  * @returns Metadata
34
34
  */
35
35
  export async function parseWebStream(webStream, fileInfo, options = {}) {
36
- const tokenizer = fromWebStream(webStream, { fileInfo: typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo });
36
+ const tokenizer = fromWebStream(webStream, {
37
+ fileInfo: typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo
38
+ });
37
39
  try {
38
40
  return await parseFromTokenizer(tokenizer, options);
39
41
  }
@@ -50,7 +52,9 @@ export async function parseWebStream(webStream, fileInfo, options = {}) {
50
52
  * Ref: https://github.com/Borewit/strtok3/blob/e6938c81ff685074d5eb3064a11c0b03ca934c1d/src/index.ts#L15
51
53
  */
52
54
  export async function parseBuffer(uint8Array, fileInfo, options = {}) {
53
- const tokenizer = fromBuffer(uint8Array, { fileInfo: typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo });
55
+ const tokenizer = fromBuffer(uint8Array, {
56
+ fileInfo: typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo
57
+ });
54
58
  return parseFromTokenizer(tokenizer, options);
55
59
  }
56
60
  /**
@@ -89,11 +93,14 @@ export function ratingToStars(rating) {
89
93
  * @return Cover image, if any, otherwise null
90
94
  */
91
95
  export function selectCover(pictures) {
92
- return pictures ? pictures.reduce((acc, cur) => {
93
- if (cur.name && cur.name.toLowerCase() in ['front', 'cover', 'cover (front)'])
94
- return cur;
95
- return acc;
96
- }) : null;
96
+ return pictures
97
+ ? pictures.reduce((acc, cur) => {
98
+ if (cur.name && cur.name.toLowerCase() in ['front', 'cover', 'cover (front)']) {
99
+ return cur;
100
+ }
101
+ return acc;
102
+ })
103
+ : null;
97
104
  }
98
105
  export async function scanAppendingHeaders(tokenizer, options = {}) {
99
106
  let apeOffset = tokenizer.fileInfo.size;
@@ -1,11 +1,11 @@
1
- import * as Token from 'token-types';
2
1
  import initDebug from 'debug';
3
2
  import * as strtok3 from 'strtok3';
4
- import { FourCcToken } from '../common/FourCC.js';
3
+ import * as Token from 'token-types';
5
4
  import { BasicParser } from '../common/BasicParser.js';
5
+ import { FourCcToken } from '../common/FourCC.js';
6
6
  import { ID3v2Parser } from '../id3v2/ID3v2Parser.js';
7
- import { ChunkHeader64 } from './DsdiffToken.js';
8
7
  import { makeUnexpectedFileContentError } from '../ParseError.js';
8
+ import { ChunkHeader64 } from './DsdiffToken.js';
9
9
  const debug = initDebug('music-metadata:parser:aiff');
10
10
  export class DsdiffContentParseError extends makeUnexpectedFileContentError('DSDIFF') {
11
11
  }
@@ -18,8 +18,9 @@ export class DsdiffContentParseError extends makeUnexpectedFileContentError('DSD
18
18
  export class DsdiffParser extends BasicParser {
19
19
  async parse() {
20
20
  const header = await this.tokenizer.readToken(ChunkHeader64);
21
- if (header.chunkID !== 'FRM8')
21
+ if (header.chunkID !== 'FRM8') {
22
22
  throw new DsdiffContentParseError('Unexpected chunk-ID');
23
+ }
23
24
  this.metadata.setAudioOnly();
24
25
  const type = (await this.tokenizer.readToken(FourCcToken)).trim();
25
26
  switch (type) {
@@ -37,26 +38,30 @@ export class DsdiffParser extends BasicParser {
37
38
  // If the data is an odd number of bytes in length, a pad byte must be added at the end
38
39
  debug(`Chunk id=${chunkHeader.chunkID}`);
39
40
  await this.readData(chunkHeader);
40
- remainingSize -= (BigInt(ChunkHeader64.len) + chunkHeader.chunkSize);
41
+ remainingSize -= BigInt(ChunkHeader64.len) + chunkHeader.chunkSize;
41
42
  }
42
43
  }
43
44
  async readData(header) {
44
45
  debug(`Reading data of chunk[ID=${header.chunkID}, size=${header.chunkSize}]`);
45
46
  const p0 = this.tokenizer.position;
46
47
  switch (header.chunkID.trim()) {
47
- case 'FVER': { // 3.1 FORMAT VERSION CHUNK
48
+ case 'FVER': {
49
+ // 3.1 FORMAT VERSION CHUNK
48
50
  const version = await this.tokenizer.readToken(Token.UINT32_LE);
49
51
  debug(`DSDIFF version=${version}`);
50
52
  break;
51
53
  }
52
- case 'PROP': { // 3.2 PROPERTY CHUNK
54
+ case 'PROP': {
55
+ // 3.2 PROPERTY CHUNK
53
56
  const propType = await this.tokenizer.readToken(FourCcToken);
54
- if (propType !== 'SND ')
57
+ if (propType !== 'SND ') {
55
58
  throw new DsdiffContentParseError('Unexpected PROP-chunk ID');
59
+ }
56
60
  await this.handleSoundPropertyChunks(header.chunkSize - BigInt(FourCcToken.len));
57
61
  break;
58
62
  }
59
- case 'ID3': { // Unofficial ID3 tag support
63
+ case 'ID3': {
64
+ // Unofficial ID3 tag support
60
65
  const id3_data = await this.tokenizer.readToken(new Token.Uint8ArrayType(Number(header.chunkSize)));
61
66
  const rst = strtok3.fromBuffer(id3_data);
62
67
  await new ID3v2Parser().parse(this.metadata, rst, this.options);
@@ -64,7 +69,7 @@ export class DsdiffParser extends BasicParser {
64
69
  }
65
70
  case 'DSD':
66
71
  if (this.metadata.format.numberOfChannels) {
67
- this.metadata.setFormat('numberOfSamples', Number(header.chunkSize * BigInt(8) / BigInt(this.metadata.format.numberOfChannels)));
72
+ this.metadata.setFormat('numberOfSamples', Number((header.chunkSize * BigInt(8)) / BigInt(this.metadata.format.numberOfChannels)));
68
73
  }
69
74
  if (this.metadata.format.numberOfSamples && this.metadata.format.sampleRate) {
70
75
  this.metadata.setFormat('duration', this.metadata.format.numberOfSamples / this.metadata.format.sampleRate);
@@ -87,18 +92,21 @@ export class DsdiffParser extends BasicParser {
87
92
  debug(`Sound-property-chunk[ID=${sndPropHeader.chunkID}, size=${sndPropHeader.chunkSize}]`);
88
93
  const p0 = this.tokenizer.position;
89
94
  switch (sndPropHeader.chunkID.trim()) {
90
- case 'FS': { // 3.2.1 Sample Rate Chunk
95
+ case 'FS': {
96
+ // 3.2.1 Sample Rate Chunk
91
97
  const sampleRate = await this.tokenizer.readToken(Token.UINT32_BE);
92
98
  this.metadata.setFormat('sampleRate', sampleRate);
93
99
  break;
94
100
  }
95
- case 'CHNL': { // 3.2.2 Channels Chunk
101
+ case 'CHNL': {
102
+ // 3.2.2 Channels Chunk
96
103
  const numChannels = await this.tokenizer.readToken(Token.UINT16_BE);
97
104
  this.metadata.setFormat('numberOfChannels', numChannels);
98
105
  await this.handleChannelChunks(sndPropHeader.chunkSize - BigInt(Token.UINT16_BE.len));
99
106
  break;
100
107
  }
101
- case 'CMPR': { // 3.2.3 Compression Type Chunk
108
+ case 'CMPR': {
109
+ // 3.2.3 Compression Type Chunk
102
110
  const compressionIdCode = (await this.tokenizer.readToken(FourCcToken)).trim();
103
111
  const count = await this.tokenizer.readToken(Token.UINT8);
104
112
  const compressionName = await this.tokenizer.readToken(new Token.StringType(count, 'ascii'));
@@ -109,7 +117,8 @@ export class DsdiffParser extends BasicParser {
109
117
  this.metadata.setFormat('codec', `${compressionIdCode} (${compressionName})`);
110
118
  break;
111
119
  }
112
- case 'ABSS': { // 3.2.4 Absolute Start Time Chunk
120
+ case 'ABSS': {
121
+ // 3.2.4 Absolute Start Time Chunk
113
122
  const hours = await this.tokenizer.readToken(Token.UINT16_BE);
114
123
  const minutes = await this.tokenizer.readToken(Token.UINT8);
115
124
  const seconds = await this.tokenizer.readToken(Token.UINT8);
@@ -117,7 +126,8 @@ export class DsdiffParser extends BasicParser {
117
126
  debug(`ABSS ${hours}:${minutes}:${seconds}.${samples}`);
118
127
  break;
119
128
  }
120
- case 'LSCO': { // 3.2.5 Loudspeaker Configuration Chunk
129
+ case 'LSCO': {
130
+ // 3.2.5 Loudspeaker Configuration Chunk
121
131
  const lsConfig = await this.tokenizer.readToken(Token.UINT16_BE);
122
132
  debug(`LSCO lsConfig=${lsConfig}`);
123
133
  break;
@@ -134,7 +144,10 @@ export class DsdiffParser extends BasicParser {
134
144
  remainingSize -= BigInt(ChunkHeader64.len) + sndPropHeader.chunkSize;
135
145
  debug(`Parsing sound-property-chunks, remainingSize=${remainingSize}`);
136
146
  }
137
- if (this.metadata.format.lossless && this.metadata.format.sampleRate && this.metadata.format.numberOfChannels && this.metadata.format.bitsPerSample) {
147
+ if (this.metadata.format.lossless &&
148
+ this.metadata.format.sampleRate &&
149
+ this.metadata.format.numberOfChannels &&
150
+ this.metadata.format.bitsPerSample) {
138
151
  const bitrate = this.metadata.format.sampleRate * this.metadata.format.numberOfChannels * this.metadata.format.bitsPerSample;
139
152
  this.metadata.setFormat('bitrate', bitrate);
140
153
  }
@@ -43,7 +43,7 @@ export declare const ChannelType: {
43
43
  '5 channels': number;
44
44
  '5.1 channels': number;
45
45
  };
46
- export type ChannelType = typeof ChannelType[keyof typeof ChannelType];
46
+ export type ChannelType = (typeof ChannelType)[keyof typeof ChannelType];
47
47
  /**
48
48
  * Interface to format chunk payload chunk
49
49
  */
@@ -1,9 +1,9 @@
1
1
  import initDebug from 'debug';
2
2
  import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
3
- import { ChunkHeader, DsdChunk, FormatChunk } from './DsfChunk.js';
4
3
  import { ID3v2Parser } from '../id3v2/ID3v2Parser.js';
5
- import { makeUnexpectedFileContentError } from '../ParseError.js';
6
4
  import { ID3v2Header } from '../id3v2/ID3v2Token.js';
5
+ import { makeUnexpectedFileContentError } from '../ParseError.js';
6
+ import { ChunkHeader, DsdChunk, FormatChunk } from './DsfChunk.js';
7
7
  const debug = initDebug('music-metadata:parser:DSF');
8
8
  export class DsdContentParseError extends makeUnexpectedFileContentError('DSD') {
9
9
  }
@@ -66,9 +66,7 @@ export class DsfParser extends AbstractID3Parser {
66
66
  this.metadata.setFormat('bitsPerSample', formatChunk.bitsPerSample);
67
67
  this.metadata.setFormat('numberOfSamples', formatChunk.sampleCount);
68
68
  this.metadata.setFormat('duration', Number(formatChunk.sampleCount) / formatChunk.samplingFrequency);
69
- const bitrate = formatChunk.bitsPerSample *
70
- formatChunk.samplingFrequency *
71
- formatChunk.channelNum;
69
+ const bitrate = formatChunk.bitsPerSample * formatChunk.samplingFrequency * formatChunk.channelNum;
72
70
  this.metadata.setFormat('bitrate', bitrate);
73
71
  return; // We got what we want, stop further processing of chunks
74
72
  }
@@ -28,7 +28,7 @@ export declare const ParseAction: {
28
28
  readonly TerminateParsing: 4;
29
29
  readonly SkipElement: 5;
30
30
  };
31
- export type ParseAction = typeof ParseAction[keyof typeof ParseAction];
31
+ export type ParseAction = (typeof ParseAction)[keyof typeof ParseAction];
32
32
  /**
33
33
  * @return true, to quit the parser
34
34
  */
@@ -1,9 +1,9 @@
1
- import { Float32_BE, Float64_BE, StringType, UINT8 } from 'token-types';
2
1
  import initDebug from 'debug';
3
2
  import { EndOfStreamError } from 'strtok3';
4
- import { DataType } from './types.js';
5
3
  import * as Token from 'token-types';
4
+ import { Float32_BE, Float64_BE, StringType, UINT8 } from 'token-types';
6
5
  import { makeUnexpectedFileContentError } from '../ParseError.js';
6
+ import { DataType } from './types.js';
7
7
  const debug = initDebug('music-metadata:parser:ebml');
8
8
  export class EbmlContentError extends makeUnexpectedFileContentError('EBML') {
9
9
  }
@@ -61,14 +61,15 @@ export class EbmlIterator {
61
61
  switch (action) {
62
62
  case ParseAction.ReadNext:
63
63
  {
64
- if (element.id === 0x1F43B675) {
64
+ if (element.id === 0x1f43b675) {
65
65
  // Hack to ignore remaining segment, when cluster element received
66
66
  // await this.tokenizer.ignore(posDone - this.tokenizer.position);
67
67
  // break;
68
68
  }
69
69
  debug(`Read element: name=${getElementPath(child)}{id=0x${element.id.toString(16)}, container=${!!child.container}} at position=${elementPosition}`);
70
70
  if (child.container) {
71
- const res = await this.parseContainer(child, element.len >= 0 ? this.tokenizer.position + element.len : -1, listener);
71
+ const childEnd = Math.min(posDone, this.tokenizer.fileInfo.size ?? Number.POSITIVE_INFINITY, element.len >= 0 ? this.tokenizer.position + element.len : posDone);
72
+ const res = await this.parseContainer(child, childEnd, listener);
72
73
  if (child.multiple) {
73
74
  if (!tree[child.name]) {
74
75
  tree[child.name] = [];
@@ -83,6 +84,13 @@ export class EbmlIterator {
83
84
  else {
84
85
  const parser = this.parserMap.get(child.value);
85
86
  if (typeof parser === 'function') {
87
+ // Validate before leaf readers allocate buffers or string tokens from the declared length.
88
+ const end = Math.min(posDone, this.tokenizer.fileInfo.size ?? Number.POSITIVE_INFINITY);
89
+ if (!Number.isSafeInteger(element.len) ||
90
+ element.len < 0 ||
91
+ element.len > end - this.tokenizer.position) {
92
+ throw new EbmlContentError(`Invalid element length: ${element.len}`);
93
+ }
86
94
  const value = await parser(element);
87
95
  tree[child.name] = value;
88
96
  await listener.elementValue(child, value, elementPosition);
@@ -166,10 +174,30 @@ export class EbmlIterator {
166
174
  return readUIntBE(buf, e.len);
167
175
  }
168
176
  async readString(e) {
169
- const rawString = await this.tokenizer.readToken(new StringType(e.len, 'utf-8'));
177
+ const buf = await this.readBuffer(e);
178
+ const rawString = new StringType(e.len, 'utf-8').get(buf, 0);
170
179
  return rawString.replace(/\x00.*$/g, '');
171
180
  }
172
181
  async readBuffer(e) {
182
+ const chunkSize = 64 * 1024;
183
+ if ((!this.tokenizer.supportsRandomAccess() || this.tokenizer.fileInfo.size === undefined) && e.len > chunkSize) {
184
+ // Neither a declared container size nor an advertised stream size proves these bytes exist.
185
+ // Allocate incrementally, and only assemble the leaf after reading its payload.
186
+ const chunks = [];
187
+ for (let remaining = e.len; remaining > 0;) {
188
+ const chunk = new Uint8Array(Math.min(remaining, chunkSize));
189
+ await this.tokenizer.readBuffer(chunk);
190
+ chunks.push(chunk);
191
+ remaining -= chunk.length;
192
+ }
193
+ const buf = new Uint8Array(e.len);
194
+ let offset = 0;
195
+ for (const chunk of chunks) {
196
+ buf.set(chunk, offset);
197
+ offset += chunk.length;
198
+ }
199
+ return buf;
200
+ }
173
201
  const buf = new Uint8Array(e.len);
174
202
  await this.tokenizer.readBuffer(buf);
175
203
  return buf;
@@ -202,7 +230,8 @@ function linkParents(element) {
202
230
  const child = element.container[id];
203
231
  child.id = Number.parseInt(id, 10);
204
232
  return child;
205
- }).forEach(child => {
233
+ })
234
+ .forEach(child => {
206
235
  child.parent = element;
207
236
  linkParents(child);
208
237
  });
@@ -9,7 +9,7 @@ export declare const DataType: {
9
9
  readonly binary: 4;
10
10
  readonly float: 5;
11
11
  };
12
- export type DataType = typeof DataType[keyof typeof DataType];
12
+ export type DataType = (typeof DataType)[keyof typeof DataType];
13
13
  export type ValueType = string | number | Uint8Array | boolean | ITree | ITree[];
14
14
  export interface IHeader {
15
15
  id: number;
@@ -4,5 +4,5 @@ export const DataType = {
4
4
  uid: 2,
5
5
  bool: 3,
6
6
  binary: 4,
7
- float: 5,
7
+ float: 5
8
8
  };
@@ -1,5 +1,5 @@
1
- import { type IVorbisPicture } from '../ogg/vorbis/Vorbis.js';
2
1
  import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
2
+ import { type IVorbisPicture } from '../ogg/vorbis/Vorbis.js';
3
3
  import type { IBlockStreamInfo } from './FlacToken.js';
4
4
  export declare class FlacParser extends AbstractID3Parser {
5
5
  private vorbisParser;
@@ -1,10 +1,10 @@
1
1
  import initDebug from 'debug';
2
2
  import { Uint8ArrayType } from 'token-types';
3
- import { VorbisPictureToken } from '../ogg/vorbis/Vorbis.js';
4
- import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
5
3
  import { FourCcToken } from '../common/FourCC.js';
6
- import { VorbisStream } from '../ogg/vorbis/VorbisStream.js';
4
+ import { AbstractID3Parser } from '../id3v2/AbstractID3Parser.js';
5
+ import { VorbisPictureToken } from '../ogg/vorbis/Vorbis.js';
7
6
  import { VorbisDecoder } from '../ogg/vorbis/VorbisDecoder.js';
7
+ import { VorbisStream } from '../ogg/vorbis/VorbisStream.js';
8
8
  import { makeUnexpectedFileContentError } from '../ParseError.js';
9
9
  import * as Flac from './FlacToken.js';
10
10
  const debug = initDebug('music-metadata:parser:FLAC');
@@ -29,7 +29,7 @@ export class FlacParser extends AbstractID3Parser {
29
29
  } while (!blockHeader.lastBlock);
30
30
  if (this.tokenizer.fileInfo.size && this.metadata.format.duration) {
31
31
  const dataSize = this.tokenizer.fileInfo.size - this.tokenizer.position;
32
- this.metadata.setFormat('bitrate', 8 * dataSize / this.metadata.format.duration);
32
+ this.metadata.setFormat('bitrate', (8 * dataSize) / this.metadata.format.duration);
33
33
  }
34
34
  }
35
35
  async parseDataBlock(blockHeader) {
@@ -60,8 +60,9 @@ export class FlacParser extends AbstractID3Parser {
60
60
  * Parse STREAMINFO
61
61
  */
62
62
  async readBlockStreamInfo(dataLen) {
63
- if (dataLen !== Flac.BlockStreamInfo.len)
63
+ if (dataLen !== Flac.BlockStreamInfo.len) {
64
64
  throw new FlacContentError('Unexpected block-stream-info length');
65
+ }
65
66
  const streamInfo = await this.tokenizer.readToken(Flac.BlockStreamInfo);
66
67
  this.metadata.setFormat('container', 'FLAC');
67
68
  this.processsStreamInfo(streamInfo);
@@ -12,7 +12,7 @@ export declare const BlockType: {
12
12
  CUESHEET: number;
13
13
  PICTURE: number;
14
14
  };
15
- export type BlockType = typeof BlockType[keyof typeof BlockType];
15
+ export type BlockType = (typeof BlockType)[keyof typeof BlockType];
16
16
  /**
17
17
  * METADATA_BLOCK_DATA
18
18
  * Ref: https://xiph.org/flac/format.html#metadata_block_streaminfo
@@ -1,5 +1,5 @@
1
- import * as util from '../common/Util.js';
2
1
  import { UINT16_BE, UINT24_BE, Uint8ArrayType } from 'token-types';
2
+ import * as util from '../common/Util.js';
3
3
  /**
4
4
  * FLAC supports up to 128 kinds of metadata blocks; currently the following are defined:
5
5
  * ref: https://xiph.org/flac/format.html#metadata_block
@@ -1,7 +1,7 @@
1
1
  import type { IRandomAccessTokenizer, ITokenizer } from 'strtok3';
2
2
  import { BasicParser } from '../common/BasicParser.js';
3
- import type { IPrivateOptions } from '../type.js';
4
3
  import type { INativeMetadataCollector } from '../common/MetadataCollector.js';
4
+ import type { IPrivateOptions } from '../type.js';
5
5
  /**
6
6
  * ID3v1 Genre mappings
7
7
  * Ref: https://de.wikipedia.org/wiki/Liste_der_ID3v1-Genres