music-metadata 10.0.1 → 10.1.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.
Files changed (122) hide show
  1. package/LICENSE.txt +9 -9
  2. package/README.md +520 -520
  3. package/lib/ParserFactory.d.ts +20 -28
  4. package/lib/ParserFactory.js +204 -207
  5. package/lib/aiff/AiffParser.js +20 -18
  6. package/lib/aiff/AiffToken.d.ts +14 -2
  7. package/lib/aiff/AiffToken.js +12 -0
  8. package/lib/apev2/APEv2Parser.d.ts +4 -4
  9. package/lib/apev2/APEv2Parser.js +12 -10
  10. package/lib/apev2/APEv2Token.d.ts +2 -4
  11. package/lib/apev2/APEv2Token.js +0 -3
  12. package/lib/asf/AsfObject.d.ts +7 -16
  13. package/lib/asf/AsfObject.js +8 -34
  14. package/lib/asf/AsfParser.js +17 -10
  15. package/lib/asf/AsfTagMapper.d.ts +1 -1
  16. package/lib/asf/AsfTagMapper.js +3 -2
  17. package/lib/asf/AsfUtil.d.ts +3 -11
  18. package/lib/asf/AsfUtil.js +29 -30
  19. package/lib/asf/GUID.js +6 -9
  20. package/lib/common/BasicParser.d.ts +4 -4
  21. package/lib/common/BasicParser.js +6 -0
  22. package/lib/common/CaseInsensitiveTagMap.d.ts +1 -1
  23. package/lib/common/CombinedTagMapper.d.ts +5 -5
  24. package/lib/common/CombinedTagMapper.js +1 -1
  25. package/lib/common/FourCC.d.ts +1 -1
  26. package/lib/common/GenericTagMapper.d.ts +8 -8
  27. package/lib/common/GenericTagMapper.js +4 -4
  28. package/lib/common/GenericTagTypes.d.ts +5 -4
  29. package/lib/common/GenericTagTypes.js +2 -2
  30. package/lib/common/MetadataCollector.d.ts +9 -9
  31. package/lib/common/MetadataCollector.js +24 -17
  32. package/lib/common/RandomFileReader.d.ts +1 -1
  33. package/lib/common/RandomFileReader.js +1 -1
  34. package/lib/common/RandomUint8ArrayReader.d.ts +1 -1
  35. package/lib/common/Util.d.ts +2 -6
  36. package/lib/common/Util.js +9 -11
  37. package/lib/core.d.ts +7 -9
  38. package/lib/core.js +10 -7
  39. package/lib/dsdiff/DsdiffParser.js +26 -14
  40. package/lib/dsdiff/DsdiffToken.d.ts +2 -2
  41. package/lib/dsdiff/DsdiffToken.js +1 -0
  42. package/lib/dsf/DsfChunk.js +1 -0
  43. package/lib/dsf/DsfParser.js +4 -2
  44. package/lib/flac/FlacParser.d.ts +3 -3
  45. package/lib/flac/FlacParser.js +9 -12
  46. package/lib/id3v1/ID3v1Parser.d.ts +1 -1
  47. package/lib/id3v1/ID3v1Parser.js +7 -4
  48. package/lib/id3v2/AbstractID3Parser.d.ts +1 -1
  49. package/lib/id3v2/AbstractID3Parser.js +2 -1
  50. package/lib/id3v2/FrameParser.d.ts +28 -3
  51. package/lib/id3v2/FrameParser.js +50 -28
  52. package/lib/id3v2/ID3v22TagMapper.d.ts +1 -1
  53. package/lib/id3v2/ID3v24TagMapper.d.ts +2 -1
  54. package/lib/id3v2/ID3v24TagMapper.js +23 -16
  55. package/lib/id3v2/ID3v2Parser.d.ts +2 -2
  56. package/lib/id3v2/ID3v2Parser.js +19 -8
  57. package/lib/iff/index.js +1 -0
  58. package/lib/index.d.ts +5 -6
  59. package/lib/index.js +7 -8
  60. package/lib/lyrics3/Lyrics3.d.ts +1 -1
  61. package/lib/lyrics3/Lyrics3.js +1 -1
  62. package/lib/matroska/MatroskaDtd.d.ts +1 -1
  63. package/lib/matroska/MatroskaDtd.js +139 -138
  64. package/lib/matroska/MatroskaParser.d.ts +4 -4
  65. package/lib/matroska/MatroskaParser.js +12 -12
  66. package/lib/matroska/types.d.ts +6 -4
  67. package/lib/mp4/Atom.d.ts +3 -3
  68. package/lib/mp4/Atom.js +4 -7
  69. package/lib/mp4/AtomToken.js +2 -1
  70. package/lib/mp4/MP4Parser.js +29 -20
  71. package/lib/mp4/MP4TagMapper.d.ts +2 -2
  72. package/lib/mp4/MP4TagMapper.js +1 -1
  73. package/lib/mpeg/ExtendedLameHeader.d.ts +4 -4
  74. package/lib/mpeg/ExtendedLameHeader.js +2 -1
  75. package/lib/mpeg/MpegParser.d.ts +1 -1
  76. package/lib/mpeg/MpegParser.js +145 -96
  77. package/lib/mpeg/ReplayGainDataFormat.d.ts +1 -1
  78. package/lib/mpeg/ReplayGainDataFormat.js +1 -0
  79. package/lib/mpeg/XingTag.d.ts +4 -4
  80. package/lib/mpeg/XingTag.js +5 -4
  81. package/lib/musepack/index.js +1 -0
  82. package/lib/musepack/sv7/BitReader.js +14 -17
  83. package/lib/musepack/sv7/MpcSv7Parser.js +6 -1
  84. package/lib/musepack/sv7/StreamVersion7.js +1 -0
  85. package/lib/musepack/sv8/MpcSv8Parser.js +6 -2
  86. package/lib/musepack/sv8/StreamVersion8.d.ts +1 -1
  87. package/lib/musepack/sv8/StreamVersion8.js +1 -0
  88. package/lib/ogg/Ogg.d.ts +1 -1
  89. package/lib/ogg/Ogg.js +1 -0
  90. package/lib/ogg/OggParser.d.ts +3 -3
  91. package/lib/ogg/OggParser.js +25 -16
  92. package/lib/ogg/opus/Opus.d.ts +1 -1
  93. package/lib/ogg/opus/Opus.js +1 -0
  94. package/lib/ogg/opus/OpusParser.d.ts +4 -4
  95. package/lib/ogg/opus/OpusParser.js +2 -0
  96. package/lib/ogg/speex/Speex.js +1 -0
  97. package/lib/ogg/speex/SpeexParser.d.ts +4 -4
  98. package/lib/ogg/speex/SpeexParser.js +1 -0
  99. package/lib/ogg/theora/Theora.js +1 -0
  100. package/lib/ogg/theora/TheoraParser.d.ts +4 -4
  101. package/lib/ogg/theora/TheoraParser.js +1 -0
  102. package/lib/ogg/vorbis/Vorbis.d.ts +3 -3
  103. package/lib/ogg/vorbis/Vorbis.js +22 -11
  104. package/lib/ogg/vorbis/VorbisDecoder.d.ts +1 -1
  105. package/lib/ogg/vorbis/VorbisDecoder.js +1 -0
  106. package/lib/ogg/vorbis/VorbisParser.d.ts +4 -4
  107. package/lib/ogg/vorbis/VorbisParser.js +3 -2
  108. package/lib/ogg/vorbis/VorbisTagMapper.d.ts +2 -2
  109. package/lib/ogg/vorbis/VorbisTagMapper.js +2 -2
  110. package/lib/riff/RiffChunk.d.ts +3 -3
  111. package/lib/riff/RiffChunk.js +1 -0
  112. package/lib/riff/RiffInfoTagMap.d.ts +1 -1
  113. package/lib/type.d.ts +35 -25
  114. package/lib/wav/BwfChunk.js +1 -0
  115. package/lib/wav/WaveChunk.d.ts +1 -1
  116. package/lib/wav/WaveChunk.js +1 -0
  117. package/lib/wav/WaveParser.js +27 -17
  118. package/lib/wavpack/WavPackParser.d.ts +1 -1
  119. package/lib/wavpack/WavPackParser.js +22 -13
  120. package/lib/wavpack/WavPackToken.d.ts +13 -17
  121. package/lib/wavpack/WavPackToken.js +22 -23
  122. package/package.json +139 -150
package/lib/mp4/Atom.js CHANGED
@@ -23,7 +23,7 @@ export class Atom {
23
23
  this.extended = extended;
24
24
  this.parent = parent;
25
25
  this.children = [];
26
- this.atomPath = (this.parent ? this.parent.atomPath + '.' : '') + this.header.name;
26
+ this.atomPath = (this.parent ? `${this.parent.atomPath}.` : '') + this.header.name;
27
27
  }
28
28
  getHeaderLength() {
29
29
  return this.extended ? 16 : 8;
@@ -51,19 +51,16 @@ export class Atom {
51
51
  case 'ilst':
52
52
  case 'tref':
53
53
  return this.readAtoms(tokenizer, dataHandler, this.getPayloadLength(remaining));
54
- case 'meta': // Metadata Atom, ref: https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW8
54
+ case 'meta': { // Metadata Atom, ref: https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW8
55
55
  // meta has 4 bytes of padding, ignore
56
56
  const peekHeader = await tokenizer.peekToken(Header);
57
57
  const paddingLength = peekHeader.name === 'hdlr' ? 0 : 4;
58
58
  await tokenizer.ignore(paddingLength);
59
59
  return this.readAtoms(tokenizer, dataHandler, this.getPayloadLength(remaining) - paddingLength);
60
- case 'mdhd': // Media header atom
61
- case 'mvhd': // 'movie' => 'mvhd': movie header atom; child of Movie Atom
62
- case 'tkhd':
63
- case 'stsz':
64
- case 'mdat':
60
+ }
65
61
  default:
66
62
  return dataHandler(this, remaining);
67
63
  }
68
64
  }
69
65
  }
66
+ //# sourceMappingURL=Atom.js.map
@@ -68,7 +68,7 @@ export class FixedLengthAtom {
68
68
  if (len < expLen) {
69
69
  throw new Error(`Atom ${atomId} expected to be ${expLen}, but specifies ${len} bytes long.`);
70
70
  }
71
- else if (len > expLen) {
71
+ if (len > expLen) {
72
72
  debug(`Warning: atom ${atomId} expected to be ${expLen}, but was actually ${len} bytes long.`);
73
73
  }
74
74
  }
@@ -390,3 +390,4 @@ function readTokenTable(buf, token, off, remainingLen, numberOfEntries) {
390
390
  }
391
391
  return entries;
392
392
  }
393
+ //# sourceMappingURL=AtomToken.js.map
@@ -91,6 +91,7 @@ function distinct(value, index, self) {
91
91
  export class MP4Parser extends BasicParser {
92
92
  constructor() {
93
93
  super(...arguments);
94
+ this.tracks = [];
94
95
  this.atomParsers = {
95
96
  /**
96
97
  * Parse movie header (mvhd) atom
@@ -208,13 +209,13 @@ export class MP4Parser extends BasicParser {
208
209
  const integerType = (signed ? 'INT' : 'UINT') + array.length * 8 + (array.length > 1 ? '_BE' : '');
209
210
  const token = Token[integerType];
210
211
  if (!token) {
211
- throw new Error('Token for integer type not found: "' + integerType + '"');
212
+ throw new Error(`Token for integer type not found: "${integerType}"`);
212
213
  }
213
214
  return Number(token.get(array, 0));
214
215
  }
215
216
  async parse() {
216
217
  this.tracks = [];
217
- let remainingFileSize = this.tokenizer.fileInfo.size;
218
+ let remainingFileSize = this.tokenizer.fileInfo.size || 0;
218
219
  while (!this.tokenizer.fileInfo.size || remainingFileSize > 0) {
219
220
  try {
220
221
  const token = await this.tokenizer.peekToken(AtomToken.Header);
@@ -226,9 +227,13 @@ export class MP4Parser extends BasicParser {
226
227
  }
227
228
  }
228
229
  catch (error) {
229
- const errMsg = `Error at offset=${this.tokenizer.position}: ${error.message}`;
230
- debug(errMsg);
231
- this.addWarning(errMsg);
230
+ if (error instanceof Error) {
231
+ const errMsg = `Error at offset=${this.tokenizer.position}: ${error.message}`;
232
+ debug(errMsg);
233
+ this.addWarning(errMsg);
234
+ }
235
+ else
236
+ throw error;
232
237
  break;
233
238
  }
234
239
  const rootAtom = await Atom.readAtom(this.tokenizer, (atom, remaining) => this.handleAtom(atom, remaining), null, remainingFileSize);
@@ -309,10 +314,8 @@ export class MP4Parser extends BasicParser {
309
314
  if (this.atomParsers[atom.header.name]) {
310
315
  return this.atomParsers[atom.header.name](remaining);
311
316
  }
312
- else {
313
- debug(`No parser for atom path=${atom.atomPath}, payload-len=${remaining}, ignoring atom`);
314
- await this.tokenizer.ignore(remaining);
315
- }
317
+ debug(`No parser for atom path=${atom.atomPath}, payload-len=${remaining}, ignoring atom`);
318
+ await this.tokenizer.ignore(remaining);
316
319
  }
317
320
  getTrackDescription() {
318
321
  return this.tracks[this.tracks.length - 1];
@@ -326,7 +329,7 @@ export class MP4Parser extends BasicParser {
326
329
  await this.metadata.addTag(tagFormat, id, value);
327
330
  }
328
331
  addWarning(message) {
329
- debug('Warning: ' + message);
332
+ debug(`Warning: ${message}`);
330
333
  this.metadata.addWarning(message);
331
334
  }
332
335
  /**
@@ -343,20 +346,22 @@ export class MP4Parser extends BasicParser {
343
346
  return this.parseValueAtom(tagKey, child);
344
347
  case 'name': // name atom (optional)
345
348
  case 'mean':
346
- case 'rate':
349
+ case 'rate': {
347
350
  const name = await this.tokenizer.readToken(new AtomToken.NameAtom(payLoadLength));
348
- tagKey += ':' + name.name;
351
+ tagKey += `:${name.name}`;
349
352
  break;
350
- default:
353
+ }
354
+ default: {
351
355
  const uint8Array = await this.tokenizer.readToken(new Token.Uint8ArrayType(payLoadLength));
352
- this.addWarning('Unsupported meta-item: ' + tagKey + '[' + child.header.name + '] => value=' + uint8ArrayToHex(uint8Array) + ' ascii=' + uint8ArrayToString(uint8Array, 'ascii'));
356
+ this.addWarning(`Unsupported meta-item: ${tagKey}[${child.header.name}] => value=${uint8ArrayToHex(uint8Array)} ascii=${uint8ArrayToString(uint8Array, 'ascii')}`);
357
+ }
353
358
  }
354
359
  }, metaAtom.getPayloadLength(0));
355
360
  }
356
361
  async parseValueAtom(tagKey, metaAtom) {
357
362
  const dataAtom = await this.tokenizer.readToken(new AtomToken.DataAtom(Number(metaAtom.header.length) - AtomToken.Header.len));
358
363
  if (dataAtom.type.set !== 0) {
359
- throw new Error('Unsupported type-set != 0: ' + dataAtom.type.set);
364
+ throw new Error(`Unsupported type-set != 0: ${dataAtom.type.set}`);
360
365
  }
361
366
  // Use well-known-type table
362
367
  // Ref: https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW35
@@ -364,24 +369,27 @@ export class MP4Parser extends BasicParser {
364
369
  case 0: // reserved: Reserved for use where no type needs to be indicated
365
370
  switch (tagKey) {
366
371
  case 'trkn':
367
- case 'disk':
372
+ case 'disk': {
368
373
  const num = Token.UINT8.get(dataAtom.value, 3);
369
374
  const of = Token.UINT8.get(dataAtom.value, 5);
370
375
  // console.log(" %s[data] = %s/%s", tagKey, num, of);
371
- await this.addTag(tagKey, num + '/' + of);
376
+ await this.addTag(tagKey, `${num}/${of}`);
372
377
  break;
373
- case 'gnre':
378
+ }
379
+ case 'gnre': {
374
380
  const genreInt = Token.UINT8.get(dataAtom.value, 1);
375
381
  const genreStr = Genres[genreInt - 1];
376
382
  // console.log(" %s[data] = %s", tagKey, genreStr);
377
383
  await this.addTag(tagKey, genreStr);
378
384
  break;
379
- case 'rate':
385
+ }
386
+ case 'rate': {
380
387
  const rate = new TextDecoder('ascii').decode(dataAtom.value);
381
388
  await this.addTag(tagKey, rate);
382
389
  break;
390
+ }
383
391
  default:
384
- debug('unknown proprietary value type for: ' + metaAtom.atomPath);
392
+ debug(`unknown proprietary value type for: ${metaAtom.atomPath}`);
385
393
  }
386
394
  break;
387
395
  case 1: // UTF-8: Without any count or NULL terminator
@@ -515,3 +523,4 @@ export class MP4Parser extends BasicParser {
515
523
  return stcTable[stcTable.length - 1].samplesPerChunk;
516
524
  }
517
525
  }
526
+ //# sourceMappingURL=MP4Parser.js.map
@@ -1,6 +1,6 @@
1
1
  import { CaseInsensitiveTagMap } from '../common/CaseInsensitiveTagMap.js';
2
- import { ITag } from "../type.js";
3
- import { INativeMetadataCollector } from "../common/MetadataCollector.js";
2
+ import type { ITag } from "../type.js";
3
+ import type { INativeMetadataCollector } from "../common/MetadataCollector.js";
4
4
  export declare const tagType = "iTunes";
5
5
  export declare class MP4TagMapper extends CaseInsensitiveTagMap {
6
6
  constructor();
@@ -115,7 +115,7 @@ export class MP4TagMapper extends CaseInsensitiveTagMap {
115
115
  case 'rate':
116
116
  tag.value = {
117
117
  source: undefined,
118
- rating: parseFloat(tag.value) / 100
118
+ rating: Number.parseFloat(tag.value) / 100
119
119
  };
120
120
  break;
121
121
  }
@@ -2,7 +2,7 @@
2
2
  * Extended Lame Header
3
3
  */
4
4
  import type { IGetToken } from 'strtok3';
5
- import { IReplayGain } from './ReplayGainDataFormat.js';
5
+ import { type IReplayGain } from './ReplayGainDataFormat.js';
6
6
  /**
7
7
  * LAME Tag, extends the Xing header format
8
8
  * First added in LAME 3.12 for VBR
@@ -12,9 +12,9 @@ export interface IExtendedLameHeader {
12
12
  revision: number;
13
13
  vbr_method: number;
14
14
  lowpass_filter: number;
15
- track_peak?: number;
16
- track_gain: IReplayGain;
17
- album_gain: IReplayGain;
15
+ track_peak?: number | null;
16
+ track_gain?: IReplayGain;
17
+ album_gain?: IReplayGain;
18
18
  music_length: number;
19
19
  music_crc: number;
20
20
  header_crc: number;
@@ -17,7 +17,7 @@ export const ExtendedLameHeader = {
17
17
  revision: common.getBitAllignedNumber(buf, off, 0, 4),
18
18
  vbr_method: common.getBitAllignedNumber(buf, off, 4, 4),
19
19
  lowpass_filter: 100 * Token.UINT8.get(buf, off + 1),
20
- track_peak: track_peak === 0 ? undefined : track_peak / Math.pow(2, 23),
20
+ track_peak: track_peak === 0 ? null : track_peak / 2 ** 23,
21
21
  track_gain: ReplayGain.get(buf, 6),
22
22
  album_gain: ReplayGain.get(buf, 8),
23
23
  music_length: Token.UINT32_BE.get(buf, off + 20),
@@ -26,3 +26,4 @@ export const ExtendedLameHeader = {
26
26
  };
27
27
  }
28
28
  };
29
+ //# sourceMappingURL=ExtendedLameHeader.js.map
@@ -4,7 +4,7 @@ export declare class MpegParser extends AbstractID3Parser {
4
4
  private syncFrameCount;
5
5
  private countSkipFrameData;
6
6
  private totalDataLength;
7
- private audioFrameHeader;
7
+ private audioFrameHeader?;
8
8
  private bitrates;
9
9
  private offset;
10
10
  private frame_size;