music-metadata 10.0.0 → 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 (121) hide show
  1. package/README.md +4 -3
  2. package/lib/ParserFactory.d.ts +20 -28
  3. package/lib/ParserFactory.js +204 -207
  4. package/lib/aiff/AiffParser.js +20 -18
  5. package/lib/aiff/AiffToken.d.ts +14 -2
  6. package/lib/aiff/AiffToken.js +12 -0
  7. package/lib/apev2/APEv2Parser.d.ts +4 -4
  8. package/lib/apev2/APEv2Parser.js +20 -12
  9. package/lib/apev2/APEv2Token.d.ts +2 -4
  10. package/lib/apev2/APEv2Token.js +1 -4
  11. package/lib/asf/AsfObject.d.ts +7 -16
  12. package/lib/asf/AsfObject.js +8 -34
  13. package/lib/asf/AsfParser.js +17 -10
  14. package/lib/asf/AsfTagMapper.d.ts +1 -1
  15. package/lib/asf/AsfTagMapper.js +3 -2
  16. package/lib/asf/AsfUtil.d.ts +3 -11
  17. package/lib/asf/AsfUtil.js +29 -30
  18. package/lib/asf/GUID.js +6 -9
  19. package/lib/common/BasicParser.d.ts +4 -4
  20. package/lib/common/BasicParser.js +6 -0
  21. package/lib/common/CaseInsensitiveTagMap.d.ts +1 -1
  22. package/lib/common/CombinedTagMapper.d.ts +5 -5
  23. package/lib/common/CombinedTagMapper.js +1 -1
  24. package/lib/common/FourCC.d.ts +1 -1
  25. package/lib/common/GenericTagMapper.d.ts +8 -8
  26. package/lib/common/GenericTagMapper.js +4 -4
  27. package/lib/common/GenericTagTypes.d.ts +5 -4
  28. package/lib/common/GenericTagTypes.js +2 -2
  29. package/lib/common/MetadataCollector.d.ts +9 -9
  30. package/lib/common/MetadataCollector.js +24 -17
  31. package/lib/common/RandomFileReader.d.ts +1 -1
  32. package/lib/common/RandomFileReader.js +1 -1
  33. package/lib/common/RandomUint8ArrayReader.d.ts +1 -1
  34. package/lib/common/Util.d.ts +2 -6
  35. package/lib/common/Util.js +9 -11
  36. package/lib/core.d.ts +7 -9
  37. package/lib/core.js +10 -7
  38. package/lib/dsdiff/DsdiffParser.js +26 -14
  39. package/lib/dsdiff/DsdiffToken.d.ts +2 -2
  40. package/lib/dsdiff/DsdiffToken.js +1 -0
  41. package/lib/dsf/DsfChunk.js +1 -0
  42. package/lib/dsf/DsfParser.js +4 -2
  43. package/lib/flac/FlacParser.d.ts +3 -3
  44. package/lib/flac/FlacParser.js +9 -12
  45. package/lib/id3v1/ID3v1Parser.d.ts +1 -1
  46. package/lib/id3v1/ID3v1Parser.js +7 -4
  47. package/lib/id3v2/AbstractID3Parser.d.ts +1 -1
  48. package/lib/id3v2/AbstractID3Parser.js +2 -1
  49. package/lib/id3v2/FrameParser.d.ts +28 -3
  50. package/lib/id3v2/FrameParser.js +50 -28
  51. package/lib/id3v2/ID3v22TagMapper.d.ts +1 -1
  52. package/lib/id3v2/ID3v24TagMapper.d.ts +2 -1
  53. package/lib/id3v2/ID3v24TagMapper.js +23 -16
  54. package/lib/id3v2/ID3v2Parser.d.ts +2 -2
  55. package/lib/id3v2/ID3v2Parser.js +19 -8
  56. package/lib/iff/index.js +1 -0
  57. package/lib/index.d.ts +5 -6
  58. package/lib/index.js +7 -8
  59. package/lib/lyrics3/Lyrics3.d.ts +1 -1
  60. package/lib/lyrics3/Lyrics3.js +1 -1
  61. package/lib/matroska/MatroskaDtd.d.ts +1 -1
  62. package/lib/matroska/MatroskaDtd.js +139 -138
  63. package/lib/matroska/MatroskaParser.d.ts +4 -4
  64. package/lib/matroska/MatroskaParser.js +12 -12
  65. package/lib/matroska/types.d.ts +6 -4
  66. package/lib/mp4/Atom.d.ts +3 -3
  67. package/lib/mp4/Atom.js +4 -7
  68. package/lib/mp4/AtomToken.js +2 -1
  69. package/lib/mp4/MP4Parser.js +29 -20
  70. package/lib/mp4/MP4TagMapper.d.ts +2 -2
  71. package/lib/mp4/MP4TagMapper.js +1 -1
  72. package/lib/mpeg/ExtendedLameHeader.d.ts +4 -4
  73. package/lib/mpeg/ExtendedLameHeader.js +2 -1
  74. package/lib/mpeg/MpegParser.d.ts +1 -1
  75. package/lib/mpeg/MpegParser.js +145 -96
  76. package/lib/mpeg/ReplayGainDataFormat.d.ts +1 -1
  77. package/lib/mpeg/ReplayGainDataFormat.js +1 -0
  78. package/lib/mpeg/XingTag.d.ts +4 -4
  79. package/lib/mpeg/XingTag.js +5 -4
  80. package/lib/musepack/index.js +1 -0
  81. package/lib/musepack/sv7/BitReader.js +14 -17
  82. package/lib/musepack/sv7/MpcSv7Parser.js +6 -1
  83. package/lib/musepack/sv7/StreamVersion7.js +1 -0
  84. package/lib/musepack/sv8/MpcSv8Parser.js +6 -2
  85. package/lib/musepack/sv8/StreamVersion8.d.ts +1 -1
  86. package/lib/musepack/sv8/StreamVersion8.js +1 -0
  87. package/lib/ogg/Ogg.d.ts +1 -1
  88. package/lib/ogg/Ogg.js +1 -0
  89. package/lib/ogg/OggParser.d.ts +3 -3
  90. package/lib/ogg/OggParser.js +25 -16
  91. package/lib/ogg/opus/Opus.d.ts +1 -1
  92. package/lib/ogg/opus/Opus.js +1 -0
  93. package/lib/ogg/opus/OpusParser.d.ts +4 -4
  94. package/lib/ogg/opus/OpusParser.js +2 -0
  95. package/lib/ogg/speex/Speex.js +1 -0
  96. package/lib/ogg/speex/SpeexParser.d.ts +4 -4
  97. package/lib/ogg/speex/SpeexParser.js +1 -0
  98. package/lib/ogg/theora/Theora.js +1 -0
  99. package/lib/ogg/theora/TheoraParser.d.ts +4 -4
  100. package/lib/ogg/theora/TheoraParser.js +1 -0
  101. package/lib/ogg/vorbis/Vorbis.d.ts +3 -3
  102. package/lib/ogg/vorbis/Vorbis.js +22 -11
  103. package/lib/ogg/vorbis/VorbisDecoder.d.ts +1 -1
  104. package/lib/ogg/vorbis/VorbisDecoder.js +1 -0
  105. package/lib/ogg/vorbis/VorbisParser.d.ts +4 -4
  106. package/lib/ogg/vorbis/VorbisParser.js +3 -2
  107. package/lib/ogg/vorbis/VorbisTagMapper.d.ts +2 -2
  108. package/lib/ogg/vorbis/VorbisTagMapper.js +2 -2
  109. package/lib/riff/RiffChunk.d.ts +3 -3
  110. package/lib/riff/RiffChunk.js +1 -0
  111. package/lib/riff/RiffInfoTagMap.d.ts +1 -1
  112. package/lib/type.d.ts +35 -25
  113. package/lib/wav/BwfChunk.js +1 -0
  114. package/lib/wav/WaveChunk.d.ts +1 -1
  115. package/lib/wav/WaveChunk.js +1 -0
  116. package/lib/wav/WaveParser.js +27 -17
  117. package/lib/wavpack/WavPackParser.d.ts +1 -1
  118. package/lib/wavpack/WavPackParser.js +22 -13
  119. package/lib/wavpack/WavPackToken.d.ts +13 -17
  120. package/lib/wavpack/WavPackToken.js +22 -23
  121. package/package.json +15 -28
@@ -1,5 +1,17 @@
1
- import * as iff from '../iff/index.js';
1
+ import type * as iff from '../iff/index.js';
2
2
  import type { IGetToken } from 'strtok3';
3
+ export declare const compressionTypes: {
4
+ NONE: string;
5
+ sowt: string;
6
+ fl32: string;
7
+ fl64: string;
8
+ alaw: string;
9
+ ulaw: string;
10
+ ULAW: string;
11
+ ALAW: string;
12
+ FL32: string;
13
+ };
14
+ export type CompressionTypeCode = keyof typeof compressionTypes;
3
15
  /**
4
16
  * The Common Chunk.
5
17
  * Describes fundamental parameters of the waveform data such as sample rate, bit resolution, and how many channels of
@@ -10,7 +22,7 @@ export interface ICommon {
10
22
  numSampleFrames: number;
11
23
  sampleSize: number;
12
24
  sampleRate: number;
13
- compressionType?: string;
25
+ compressionType?: CompressionTypeCode;
14
26
  compressionName?: string;
15
27
  }
16
28
  export declare class Common implements IGetToken<ICommon> {
@@ -1,5 +1,16 @@
1
1
  import * as Token from 'token-types';
2
2
  import { FourCcToken } from '../common/FourCC.js';
3
+ export const compressionTypes = {
4
+ NONE: 'not compressed PCM Apple Computer',
5
+ sowt: 'PCM (byte swapped)',
6
+ fl32: '32-bit floating point IEEE 32-bit float',
7
+ fl64: '64-bit floating point IEEE 64-bit float Apple Computer',
8
+ alaw: 'ALaw 2:1 8-bit ITU-T G.711 A-law',
9
+ ulaw: 'µLaw 2:1 8-bit ITU-T G.711 µ-law Apple Computer',
10
+ ULAW: 'CCITT G.711 u-law 8-bit ITU-T G.711 µ-law',
11
+ ALAW: 'CCITT G.711 A-law 8-bit ITU-T G.711 A-law',
12
+ FL32: 'Float 32 IEEE 32-bit float '
13
+ };
3
14
  export class Common {
4
15
  constructor(header, isAifc) {
5
16
  this.isAifc = isAifc;
@@ -42,3 +53,4 @@ export class Common {
42
53
  return res;
43
54
  }
44
55
  }
56
+ //# sourceMappingURL=AiffToken.js.map
@@ -1,8 +1,8 @@
1
1
  import * as strtok3 from 'strtok3';
2
- import { IOptions, IRandomReader, IApeHeader } from '../type.js';
3
- import { INativeMetadataCollector } from '../common/MetadataCollector.js';
2
+ import type { IOptions, IRandomReader, IApeHeader } from '../type.js';
3
+ import type { INativeMetadataCollector } from '../common/MetadataCollector.js';
4
4
  import { BasicParser } from '../common/BasicParser.js';
5
- import { IFooter, IHeader } from './APEv2Token.js';
5
+ import { type IFooter, type IHeader } from './APEv2Token.js';
6
6
  export declare class APEv2Parser extends BasicParser {
7
7
  static tryParseApeHeader(metadata: INativeMetadataCollector, tokenizer: strtok3.ITokenizer, options: IOptions): Promise<void>;
8
8
  /**
@@ -16,7 +16,7 @@ export declare class APEv2Parser extends BasicParser {
16
16
  * @param reader
17
17
  * @param offset
18
18
  */
19
- static findApeFooterOffset(reader: IRandomReader, offset: number): Promise<IApeHeader>;
19
+ static findApeFooterOffset(reader: IRandomReader, offset: number): Promise<IApeHeader | undefined>;
20
20
  private static parseTagFooter;
21
21
  private ape;
22
22
  /**
@@ -39,8 +39,14 @@ export class APEv2Parser extends BasicParser {
39
39
  await reader.randomRead(apeBuf, 0, TagFooter.len, offset - TagFooter.len);
40
40
  const tagFooter = TagFooter.get(apeBuf, 0);
41
41
  if (tagFooter.ID === 'APETAGEX') {
42
- debug(`APE footer header at offset=${offset}`);
43
- return { footer: tagFooter, offset: offset - tagFooter.size };
42
+ if (tagFooter.flags.isHeader) {
43
+ debug(`APE Header found at offset=${offset - TagFooter.len}`);
44
+ }
45
+ else {
46
+ debug(`APE Footer found at offset=${offset - TagFooter.len}`);
47
+ offset -= tagFooter.size;
48
+ }
49
+ return { footer: tagFooter, offset };
44
50
  }
45
51
  }
46
52
  static parseTagFooter(metadata, buffer, options) {
@@ -57,7 +63,7 @@ export class APEv2Parser extends BasicParser {
57
63
  */
58
64
  async tryParseApeHeader() {
59
65
  if (this.tokenizer.fileInfo.size && this.tokenizer.fileInfo.size - this.tokenizer.position < TagFooter.len) {
60
- debug(`No APEv2 header found, end-of-file reached`);
66
+ debug("No APEv2 header found, end-of-file reached");
61
67
  return;
62
68
  }
63
69
  const footer = await this.tokenizer.peekToken(TagFooter);
@@ -65,15 +71,13 @@ export class APEv2Parser extends BasicParser {
65
71
  await this.tokenizer.ignore(TagFooter.len);
66
72
  return this.parseTags(footer);
67
73
  }
68
- else {
69
- debug(`APEv2 header not found at offset=${this.tokenizer.position}`);
70
- if (this.tokenizer.fileInfo.size) {
71
- // Try to read the APEv2 header using just the footer-header
72
- const remaining = this.tokenizer.fileInfo.size - this.tokenizer.position; // ToDo: take ID3v1 into account
73
- const buffer = new Uint8Array(remaining);
74
- await this.tokenizer.readBuffer(buffer);
75
- return APEv2Parser.parseTagFooter(this.metadata, buffer, this.options);
76
- }
74
+ debug(`APEv2 header not found at offset=${this.tokenizer.position}`);
75
+ if (this.tokenizer.fileInfo.size) {
76
+ // Try to read the APEv2 header using just the footer-header
77
+ const remaining = this.tokenizer.fileInfo.size - this.tokenizer.position; // ToDo: take ID3v1 into account
78
+ const buffer = new Uint8Array(remaining);
79
+ await this.tokenizer.readBuffer(buffer);
80
+ return APEv2Parser.parseTagFooter(this.metadata, buffer, this.options);
77
81
  }
78
82
  }
79
83
  async parse() {
@@ -151,9 +155,13 @@ export class APEv2Parser extends BasicParser {
151
155
  this.metadata.setFormat('sampleRate', header.sampleRate);
152
156
  this.metadata.setFormat('numberOfChannels', header.channel);
153
157
  this.metadata.setFormat('duration', APEv2Parser.calculateDuration(header));
158
+ if (!this.ape.descriptor) {
159
+ throw new Error('Missing APE descriptor');
160
+ }
154
161
  return {
155
162
  forwardBytes: this.ape.descriptor.seekTableBytes + this.ape.descriptor.headerDataBytes +
156
163
  this.ape.descriptor.apeFrameDataBytes + this.ape.descriptor.terminatingDataBytes
157
164
  };
158
165
  }
159
166
  }
167
+ //# sourceMappingURL=APEv2Parser.js.map
@@ -1,4 +1,3 @@
1
- import * as Token from 'token-types';
2
1
  import type { IGetToken } from 'strtok3';
3
2
  /**
4
3
  * APETag versionIndex history / supported formats
@@ -83,7 +82,6 @@ export interface ITagItemHeader {
83
82
  * APE Tag v2.0 Item Header
84
83
  */
85
84
  export declare const TagItemHeader: IGetToken<ITagItemHeader>;
86
- export declare const TagField: (footer: any) => Token.Uint8ArrayType;
87
85
  export interface ITagFlags {
88
86
  containsHeader: boolean;
89
87
  containsFooter: boolean;
@@ -91,10 +89,10 @@ export interface ITagFlags {
91
89
  readOnly: boolean;
92
90
  dataType: DataType;
93
91
  }
94
- export declare function parseTagFlags(flags: any): ITagFlags;
92
+ export declare function parseTagFlags(flags: number): ITagFlags;
95
93
  /**
96
94
  * @param num {number}
97
95
  * @param bit 0 is least significant bit (LSB)
98
96
  * @return {boolean} true if bit is 1; otherwise false
99
97
  */
100
- export declare function isBitSet(num: any, bit: any): boolean;
98
+ export declare function isBitSet(num: number, bit: number): boolean;
@@ -98,14 +98,11 @@ export const TagItemHeader = {
98
98
  };
99
99
  }
100
100
  };
101
- export const TagField = footer => {
102
- return new Token.Uint8ArrayType(footer.size - TagFooter.len);
103
- };
104
101
  export function parseTagFlags(flags) {
105
102
  return {
106
103
  containsHeader: isBitSet(flags, 31),
107
104
  containsFooter: isBitSet(flags, 30),
108
- isHeader: isBitSet(flags, 31),
105
+ isHeader: isBitSet(flags, 29),
109
106
  readOnly: isBitSet(flags, 0),
110
107
  dataType: (flags & 6) >> 1
111
108
  };
@@ -1,5 +1,5 @@
1
1
  import type { IGetToken, ITokenizer } from 'strtok3';
2
- import { IPicture, ITag } from '../type.js';
2
+ import type { AnyTagValue, IPicture, ITag } from '../type.js';
3
3
  import GUID from './GUID.js';
4
4
  /**
5
5
  * Data Type: Specifies the type of information being stored. The following values are recognized.
@@ -64,10 +64,9 @@ export declare abstract class State<T> implements IGetToken<T> {
64
64
  len: number;
65
65
  constructor(header: IAsfObjectHeader);
66
66
  abstract get(buf: Uint8Array, off: number): T;
67
- protected postProcessTag(tags: ITag[], name: string, valueType: number, data: any): void;
67
+ protected postProcessTag(tags: ITag[], name: string, valueType: number, data: AnyTagValue): void;
68
68
  }
69
- export declare class IgnoreObjectState extends State<any> {
70
- constructor(header: IAsfObjectHeader);
69
+ export declare class IgnoreObjectState extends State<unknown> {
71
70
  get(buf: Uint8Array, off: number): null;
72
71
  }
73
72
  /**
@@ -173,7 +172,6 @@ export interface IFilePropertiesObject {
173
172
  */
174
173
  export declare class FilePropertiesObject extends State<IFilePropertiesObject> {
175
174
  static guid: GUID;
176
- constructor(header: IAsfObjectHeader);
177
175
  get(buf: Uint8Array, off: number): IFilePropertiesObject;
178
176
  }
179
177
  /**
@@ -183,7 +181,7 @@ export interface IStreamPropertiesObject {
183
181
  /**
184
182
  * Stream Type
185
183
  */
186
- streamType: string;
184
+ streamType: string | undefined;
187
185
  /**
188
186
  * Error Correction Type
189
187
  */
@@ -195,7 +193,6 @@ export interface IStreamPropertiesObject {
195
193
  */
196
194
  export declare class StreamPropertiesObject extends State<IStreamPropertiesObject> {
197
195
  static guid: GUID;
198
- constructor(header: IAsfObjectHeader);
199
196
  get(buf: Uint8Array, off: number): IStreamPropertiesObject;
200
197
  }
201
198
  export interface IHeaderExtensionObject {
@@ -234,7 +231,6 @@ export declare function readCodecEntries(tokenizer: ITokenizer): Promise<ICodecE
234
231
  export declare class ContentDescriptionObjectState extends State<ITag[]> {
235
232
  static guid: GUID;
236
233
  private static contentDescTags;
237
- constructor(header: IAsfObjectHeader);
238
234
  get(buf: Uint8Array, off: number): ITag[];
239
235
  }
240
236
  /**
@@ -243,7 +239,6 @@ export declare class ContentDescriptionObjectState extends State<ITag[]> {
243
239
  */
244
240
  export declare class ExtendedContentDescriptionObjectState extends State<ITag[]> {
245
241
  static guid: GUID;
246
- constructor(header: IAsfObjectHeader);
247
242
  get(buf: Uint8Array, off: number): ITag[];
248
243
  }
249
244
  export interface IStreamName {
@@ -275,7 +270,7 @@ export interface IExtendedStreamPropertiesObject {
275
270
  streamNameCount: number;
276
271
  payloadExtensionSystems: number;
277
272
  streamNames: IStreamName[];
278
- streamPropertiesObject: number;
273
+ streamPropertiesObject: number | null;
279
274
  }
280
275
  /**
281
276
  * 4.1 Extended Stream Properties Object (optional, 1 per media stream)
@@ -283,7 +278,6 @@ export interface IExtendedStreamPropertiesObject {
283
278
  */
284
279
  export declare class ExtendedStreamPropertiesObjectState extends State<IExtendedStreamPropertiesObject> {
285
280
  static guid: GUID;
286
- constructor(header: IAsfObjectHeader);
287
281
  get(buf: Uint8Array, off: number): IExtendedStreamPropertiesObject;
288
282
  }
289
283
  /**
@@ -292,12 +286,10 @@ export declare class ExtendedStreamPropertiesObjectState extends State<IExtended
292
286
  */
293
287
  export declare class MetadataObjectState extends State<ITag[]> {
294
288
  static guid: GUID;
295
- constructor(header: IAsfObjectHeader);
296
289
  get(uint8Array: Uint8Array, off: number): ITag[];
297
290
  }
298
291
  export declare class MetadataLibraryObjectState extends MetadataObjectState {
299
292
  static guid: GUID;
300
- constructor(header: IAsfObjectHeader);
301
293
  }
302
294
  export interface IWmPicture extends IPicture {
303
295
  type: string;
@@ -310,9 +302,8 @@ export interface IWmPicture extends IPicture {
310
302
  * Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/dd757977(v=vs.85).aspx
311
303
  */
312
304
  export declare class WmPictureToken implements IGetToken<IWmPicture> {
313
- len: any;
314
- static fromBase64(base64str: string): IPicture;
305
+ len: number;
315
306
  static fromBuffer(buffer: Uint8Array): IWmPicture;
316
- constructor(len: any);
307
+ constructor(len: number);
317
308
  get(buffer: Uint8Array, offset: number): IWmPicture;
318
309
  }
@@ -2,9 +2,8 @@
2
2
  import * as Token from 'token-types';
3
3
  import * as util from '../common/Util.js';
4
4
  import GUID from './GUID.js';
5
- import { AsfUtil } from './AsfUtil.js';
5
+ import { getParserForAttr, parseUnicodeAttr } from './AsfUtil.js';
6
6
  import { AttachedPictureType } from '../id3v2/ID3v2Token.js';
7
- import { base64ToUint8Array } from 'uint8array-extras';
8
7
  /**
9
8
  * Data Type: Specifies the type of information being stored. The following values are recognized.
10
9
  */
@@ -72,9 +71,9 @@ export class State {
72
71
  tags.push({ id: name, value: WmPictureToken.fromBuffer(data) });
73
72
  }
74
73
  else {
75
- const parseAttr = AsfUtil.getParserForAttr(valueType);
74
+ const parseAttr = getParserForAttr(valueType);
76
75
  if (!parseAttr) {
77
- throw new Error('unexpected value headerType: ' + valueType);
76
+ throw new Error(`unexpected value headerType: ${valueType}`);
78
77
  }
79
78
  tags.push({ id: name, value: parseAttr(data) });
80
79
  }
@@ -82,9 +81,6 @@ export class State {
82
81
  }
83
82
  // ToDo: use ignore type
84
83
  export class IgnoreObjectState extends State {
85
- constructor(header) {
86
- super(header);
87
- }
88
84
  get(buf, off) {
89
85
  return null;
90
86
  }
@@ -94,9 +90,6 @@ export class IgnoreObjectState extends State {
94
90
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/03_asf_top_level_header_object.html#3_2
95
91
  */
96
92
  export class FilePropertiesObject extends State {
97
- constructor(header) {
98
- super(header);
99
- }
100
93
  get(buf, off) {
101
94
  return {
102
95
  fileId: GUID.fromBin(buf, off),
@@ -123,9 +116,6 @@ FilePropertiesObject.guid = GUID.FilePropertiesObject;
123
116
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/03_asf_top_level_header_object.html#3_3
124
117
  */
125
118
  export class StreamPropertiesObject extends State {
126
- constructor(header) {
127
- super(header);
128
- }
129
119
  get(buf, off) {
130
120
  return {
131
121
  streamType: GUID.decodeMediaType(GUID.fromBin(buf, off)),
@@ -209,9 +199,6 @@ async function readCodecEntry(tokenizer) {
209
199
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/03_asf_top_level_header_object.html#3_10
210
200
  */
211
201
  export class ContentDescriptionObjectState extends State {
212
- constructor(header) {
213
- super(header);
214
- }
215
202
  get(buf, off) {
216
203
  const tags = [];
217
204
  const view = new DataView(buf.buffer, off);
@@ -221,7 +208,7 @@ export class ContentDescriptionObjectState extends State {
221
208
  if (length > 0) {
222
209
  const tagName = ContentDescriptionObjectState.contentDescTags[i];
223
210
  const end = pos + length;
224
- tags.push({ id: tagName, value: AsfUtil.parseUnicodeAttr(buf.slice(off + pos, off + end)) });
211
+ tags.push({ id: tagName, value: parseUnicodeAttr(buf.slice(off + pos, off + end)) });
225
212
  pos = end;
226
213
  }
227
214
  }
@@ -235,9 +222,6 @@ ContentDescriptionObjectState.contentDescTags = ['Title', 'Author', 'Copyright',
235
222
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/03_asf_top_level_header_object.html#3_11
236
223
  */
237
224
  export class ExtendedContentDescriptionObjectState extends State {
238
- constructor(header) {
239
- super(header);
240
- }
241
225
  get(buf, off) {
242
226
  const tags = [];
243
227
  const view = new DataView(buf.buffer, off);
@@ -246,7 +230,7 @@ export class ExtendedContentDescriptionObjectState extends State {
246
230
  for (let i = 0; i < attrCount; i += 1) {
247
231
  const nameLen = view.getUint16(pos, true);
248
232
  pos += 2;
249
- const name = AsfUtil.parseUnicodeAttr(buf.slice(off + pos, off + pos + nameLen));
233
+ const name = parseUnicodeAttr(buf.slice(off + pos, off + pos + nameLen));
250
234
  pos += nameLen;
251
235
  const valueType = view.getUint16(pos, true);
252
236
  pos += 2;
@@ -265,9 +249,6 @@ ExtendedContentDescriptionObjectState.guid = GUID.ExtendedContentDescriptionObje
265
249
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/04_objects_in_the_asf_header_extension_object.html#4_1
266
250
  */
267
251
  export class ExtendedStreamPropertiesObjectState extends State {
268
- constructor(header) {
269
- super(header);
270
- }
271
252
  get(buf, off) {
272
253
  const view = new DataView(buf.buffer, off);
273
254
  return {
@@ -302,9 +283,6 @@ ExtendedStreamPropertiesObjectState.guid = GUID.ExtendedStreamPropertiesObject;
302
283
  * Ref: http://drang.s4.xrea.com/program/tips/id3tag/wmp/04_objects_in_the_asf_header_extension_object.html#4_7
303
284
  */
304
285
  export class MetadataObjectState extends State {
305
- constructor(header) {
306
- super(header);
307
- }
308
286
  get(uint8Array, off) {
309
287
  const tags = [];
310
288
  const view = new DataView(uint8Array.buffer, off);
@@ -318,7 +296,7 @@ export class MetadataObjectState extends State {
318
296
  pos += 2;
319
297
  const dataLen = view.getUint32(pos, true);
320
298
  pos += 4;
321
- const name = AsfUtil.parseUnicodeAttr(uint8Array.slice(off + pos, off + pos + nameLen));
299
+ const name = parseUnicodeAttr(uint8Array.slice(off + pos, off + pos + nameLen));
322
300
  pos += nameLen;
323
301
  const data = uint8Array.slice(off + pos, off + pos + dataLen);
324
302
  pos += dataLen;
@@ -329,19 +307,14 @@ export class MetadataObjectState extends State {
329
307
  }
330
308
  MetadataObjectState.guid = GUID.MetadataObject;
331
309
  // 4.8 Metadata Library Object (optional, 0 or 1)
310
+ // biome-ignore lint/complexity/noStaticOnlyClass: Extends a non-static class
332
311
  export class MetadataLibraryObjectState extends MetadataObjectState {
333
- constructor(header) {
334
- super(header);
335
- }
336
312
  }
337
313
  MetadataLibraryObjectState.guid = GUID.MetadataLibraryObject;
338
314
  /**
339
315
  * Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/dd757977(v=vs.85).aspx
340
316
  */
341
317
  export class WmPictureToken {
342
- static fromBase64(base64str) {
343
- return this.fromBuffer(base64ToUint8Array(base64str));
344
- }
345
318
  static fromBuffer(buffer) {
346
319
  const pic = new WmPictureToken(buffer.length);
347
320
  return pic.get(buffer, 0);
@@ -371,3 +344,4 @@ export class WmPictureToken {
371
344
  };
372
345
  }
373
346
  }
347
+ //# sourceMappingURL=AsfObject.js.map
@@ -19,7 +19,7 @@ export class AsfParser extends BasicParser {
19
19
  async parse() {
20
20
  const header = await this.tokenizer.readToken(AsfObject.TopLevelHeaderObjectToken);
21
21
  if (!header.objectId.equals(GUID.HeaderObject)) {
22
- throw new Error('expected asf header; but was not found; got: ' + header.objectId.str);
22
+ throw new Error(`expected asf header; but was not found; got: ${header.objectId.str}`);
23
23
  }
24
24
  try {
25
25
  await this.parseObjectHeader(header.numberOfHeaderObjects);
@@ -36,19 +36,22 @@ export class AsfParser extends BasicParser {
36
36
  // Parse data part of the ASF Object
37
37
  debug('header GUID=%s', header.objectId.str);
38
38
  switch (header.objectId.str) {
39
- case AsfObject.FilePropertiesObject.guid.str: // 3.2
39
+ case AsfObject.FilePropertiesObject.guid.str: { // 3.2
40
40
  const fpo = await this.tokenizer.readToken(new AsfObject.FilePropertiesObject(header));
41
41
  this.metadata.setFormat('duration', Number(fpo.playDuration / BigInt(1000)) / 10000 - Number(fpo.preroll) / 1000);
42
42
  this.metadata.setFormat('bitrate', fpo.maximumBitrate);
43
43
  break;
44
- case AsfObject.StreamPropertiesObject.guid.str: // 3.3
44
+ }
45
+ case AsfObject.StreamPropertiesObject.guid.str: { // 3.3
45
46
  const spo = await this.tokenizer.readToken(new AsfObject.StreamPropertiesObject(header));
46
- this.metadata.setFormat('container', 'ASF/' + spo.streamType);
47
+ this.metadata.setFormat('container', `ASF/${spo.streamType}`);
47
48
  break;
48
- case AsfObject.HeaderExtensionObject.guid.str: // 3.4
49
+ }
50
+ case AsfObject.HeaderExtensionObject.guid.str: { // 3.4
49
51
  const extHeader = await this.tokenizer.readToken(new AsfObject.HeaderExtensionObject());
50
52
  await this.parseExtensionObject(extHeader.extensionDataSize);
51
53
  break;
54
+ }
52
55
  case AsfObject.ContentDescriptionObjectState.guid.str: // 3.10
53
56
  tags = await this.tokenizer.readToken(new AsfObject.ContentDescriptionObjectState(header));
54
57
  await this.addTags(tags);
@@ -57,7 +60,7 @@ export class AsfParser extends BasicParser {
57
60
  tags = await this.tokenizer.readToken(new AsfObject.ExtendedContentDescriptionObjectState(header));
58
61
  await this.addTags(tags);
59
62
  break;
60
- case GUID.CodecListObject.str:
63
+ case GUID.CodecListObject.str: {
61
64
  const codecs = await AsfObject.readCodecEntries(this.tokenizer);
62
65
  codecs.forEach(codec => {
63
66
  this.metadata.addStreamInfo({
@@ -68,6 +71,7 @@ export class AsfParser extends BasicParser {
68
71
  const audioCodecs = codecs.filter(codec => codec.type.audioCodec).map(codec => codec.codecName).join('/');
69
72
  this.metadata.setFormat('codec', audioCodecs);
70
73
  break;
74
+ }
71
75
  case GUID.StreamBitratePropertiesObject.str:
72
76
  // ToDo?
73
77
  await this.tokenizer.ignore(header.objectSize - AsfObject.HeaderObjectToken.len);
@@ -78,7 +82,7 @@ export class AsfParser extends BasicParser {
78
82
  await this.tokenizer.ignore(header.objectSize - AsfObject.HeaderObjectToken.len);
79
83
  break;
80
84
  default:
81
- this.metadata.addWarning('Ignore ASF-Object-GUID: ' + header.objectId.str);
85
+ this.metadata.addWarning(`Ignore ASF-Object-GUID: ${header.objectId.str}`);
82
86
  debug('Ignore ASF-Object-GUID: %s', header.objectId.str);
83
87
  await this.tokenizer.readToken(new AsfObject.IgnoreObjectState(header));
84
88
  }
@@ -99,14 +103,16 @@ export class AsfParser extends BasicParser {
99
103
  // ToDo: extended stream header properties are ignored
100
104
  await this.tokenizer.readToken(new AsfObject.ExtendedStreamPropertiesObjectState(header));
101
105
  break;
102
- case AsfObject.MetadataObjectState.guid.str: // 4.7
106
+ case AsfObject.MetadataObjectState.guid.str: { // 4.7
103
107
  const moTags = await this.tokenizer.readToken(new AsfObject.MetadataObjectState(header));
104
108
  await this.addTags(moTags);
105
109
  break;
106
- case AsfObject.MetadataLibraryObjectState.guid.str: // 4.8
110
+ }
111
+ case AsfObject.MetadataLibraryObjectState.guid.str: { // 4.8
107
112
  const mlTags = await this.tokenizer.readToken(new AsfObject.MetadataLibraryObjectState(header));
108
113
  await this.addTags(mlTags);
109
114
  break;
115
+ }
110
116
  case GUID.PaddingObject.str:
111
117
  // ToDo: register bytes pad
112
118
  await this.tokenizer.ignore(remaining);
@@ -118,7 +124,7 @@ export class AsfParser extends BasicParser {
118
124
  await this.tokenizer.ignore(remaining);
119
125
  break;
120
126
  default:
121
- this.metadata.addWarning('Ignore ASF-Object-GUID: ' + header.objectId.str);
127
+ this.metadata.addWarning(`Ignore ASF-Object-GUID: ${header.objectId.str}`);
122
128
  // console.log("Ignore ASF-Object-GUID: %s", header.objectId.str);
123
129
  await this.tokenizer.readToken(new AsfObject.IgnoreObjectState(header));
124
130
  break;
@@ -127,3 +133,4 @@ export class AsfParser extends BasicParser {
127
133
  } while (extensionSize > 0);
128
134
  }
129
135
  }
136
+ //# sourceMappingURL=AsfParser.js.map
@@ -1,5 +1,5 @@
1
1
  import { CommonTagMapper } from '../common/GenericTagMapper.js';
2
- import { IRating, ITag } from '../type.js';
2
+ import type { IRating, ITag } from '../type.js';
3
3
  export declare class AsfTagMapper extends CommonTagMapper {
4
4
  static toRating(rating: string): IRating;
5
5
  constructor();
@@ -73,7 +73,7 @@ const asfTagMap = {
73
73
  export class AsfTagMapper extends CommonTagMapper {
74
74
  static toRating(rating) {
75
75
  return {
76
- rating: parseFloat(rating + 1) / 5
76
+ rating: Number.parseFloat(rating + 1) / 5
77
77
  };
78
78
  }
79
79
  constructor() {
@@ -81,11 +81,12 @@ export class AsfTagMapper extends CommonTagMapper {
81
81
  }
82
82
  postMap(tag) {
83
83
  switch (tag.id) {
84
- case 'WM/SharedUserRating':
84
+ case 'WM/SharedUserRating': {
85
85
  const keys = tag.id.split(':');
86
86
  tag.value = AsfTagMapper.toRating(tag.value);
87
87
  tag.id = keys[0];
88
88
  break;
89
+ }
89
90
  }
90
91
  }
91
92
  }
@@ -1,12 +1,4 @@
1
- import { DataType } from './AsfObject.js';
1
+ import type { DataType } from './AsfObject.js';
2
2
  export type AttributeParser = (buf: Uint8Array) => boolean | string | number | bigint | Uint8Array;
3
- export declare class AsfUtil {
4
- static getParserForAttr(i: DataType): AttributeParser;
5
- static parseUnicodeAttr(uint8Array: Uint8Array): string;
6
- private static attributeParsers;
7
- private static parseByteArrayAttr;
8
- private static parseBoolAttr;
9
- private static parseDWordAttr;
10
- private static parseQWordAttr;
11
- private static parseWordAttr;
12
- }
3
+ export declare function getParserForAttr(i: DataType): AttributeParser;
4
+ export declare function parseUnicodeAttr(uint8Array: Uint8Array): string;
@@ -1,34 +1,33 @@
1
1
  import * as Token from 'token-types';
2
2
  import * as util from '../common/Util.js';
3
- export class AsfUtil {
4
- static getParserForAttr(i) {
5
- return AsfUtil.attributeParsers[i];
6
- }
7
- static parseUnicodeAttr(uint8Array) {
8
- return util.stripNulls(util.decodeString(uint8Array, 'utf-16le'));
9
- }
10
- static parseByteArrayAttr(buf) {
11
- return new Uint8Array(buf);
12
- }
13
- static parseBoolAttr(buf, offset = 0) {
14
- return AsfUtil.parseWordAttr(buf, offset) === 1;
15
- }
16
- static parseDWordAttr(buf, offset = 0) {
17
- return Token.UINT32_LE.get(buf, offset);
18
- }
19
- static parseQWordAttr(buf, offset = 0) {
20
- return Token.UINT64_LE.get(buf, offset);
21
- }
22
- static parseWordAttr(buf, offset = 0) {
23
- return Token.UINT16_LE.get(buf, offset);
24
- }
3
+ export function getParserForAttr(i) {
4
+ return attributeParsers[i];
25
5
  }
26
- AsfUtil.attributeParsers = [
27
- AsfUtil.parseUnicodeAttr,
28
- AsfUtil.parseByteArrayAttr,
29
- AsfUtil.parseBoolAttr,
30
- AsfUtil.parseDWordAttr,
31
- AsfUtil.parseQWordAttr,
32
- AsfUtil.parseWordAttr,
33
- AsfUtil.parseByteArrayAttr
6
+ export function parseUnicodeAttr(uint8Array) {
7
+ return util.stripNulls(util.decodeString(uint8Array, 'utf-16le'));
8
+ }
9
+ const attributeParsers = [
10
+ parseUnicodeAttr,
11
+ parseByteArrayAttr,
12
+ parseBoolAttr,
13
+ parseDWordAttr,
14
+ parseQWordAttr,
15
+ parseWordAttr,
16
+ parseByteArrayAttr
34
17
  ];
18
+ function parseByteArrayAttr(buf) {
19
+ return new Uint8Array(buf);
20
+ }
21
+ function parseBoolAttr(buf, offset = 0) {
22
+ return parseWordAttr(buf, offset) === 1;
23
+ }
24
+ function parseDWordAttr(buf, offset = 0) {
25
+ return Token.UINT32_LE.get(buf, offset);
26
+ }
27
+ function parseQWordAttr(buf, offset = 0) {
28
+ return Token.UINT64_LE.get(buf, offset);
29
+ }
30
+ function parseWordAttr(buf, offset = 0) {
31
+ return Token.UINT16_LE.get(buf, offset);
32
+ }
33
+ //# sourceMappingURL=AsfUtil.js.map
package/lib/asf/GUID.js CHANGED
@@ -15,7 +15,7 @@ import { hexToUint8Array, uint8ArrayToHex } from 'uint8array-extras';
15
15
  */
16
16
  class GUID {
17
17
  static fromBin(bin, offset = 0) {
18
- return new GUID(this.decode(bin, offset));
18
+ return new GUID(GUID.decode(bin, offset));
19
19
  }
20
20
  /**
21
21
  * Decode GUID in format like "B503BF5F-2EA9-CF11-8EE3-00C00C205365"
@@ -25,11 +25,7 @@ class GUID {
25
25
  */
26
26
  static decode(objectId, offset = 0) {
27
27
  const view = new DataView(objectId.buffer, offset);
28
- const guid = view.getUint32(0, true).toString(16) + "-" +
29
- view.getUint16(4, true).toString(16) + "-" +
30
- view.getUint16(6, true).toString(16) + "-" +
31
- view.getUint16(8).toString(16) + "-" +
32
- uint8ArrayToHex(objectId.slice(offset + 10, offset + 16));
28
+ const guid = `${view.getUint32(0, true).toString(16)}-${view.getUint16(4, true).toString(16)}-${view.getUint16(6, true).toString(16)}-${view.getUint16(8).toString(16)}-${uint8ArrayToHex(objectId.slice(offset + 10, offset + 16))}`;
33
29
  return guid.toUpperCase();
34
30
  }
35
31
  /**
@@ -55,9 +51,9 @@ class GUID {
55
51
  static encode(str) {
56
52
  const bin = new Uint8Array(16);
57
53
  const view = new DataView(bin.buffer);
58
- view.setUint32(0, parseInt(str.slice(0, 8), 16), true);
59
- view.setUint16(4, parseInt(str.slice(9, 13), 16), true);
60
- view.setUint16(6, parseInt(str.slice(14, 18), 16), true);
54
+ view.setUint32(0, Number.parseInt(str.slice(0, 8), 16), true);
55
+ view.setUint16(4, Number.parseInt(str.slice(9, 13), 16), true);
56
+ view.setUint16(6, Number.parseInt(str.slice(14, 18), 16), true);
61
57
  bin.set(hexToUint8Array(str.slice(19, 23)), 8);
62
58
  bin.set(hexToUint8Array(str.slice(24)), 10);
63
59
  return bin;
@@ -120,3 +116,4 @@ GUID.FileTransferMedia = new GUID("91BD222C-F21C-497A-8B6D-5AA86BFC0185");
120
116
  GUID.BinaryMedia = new GUID("3AFB65E2-47EF-40F2-AC2C-70A90D71D343");
121
117
  GUID.ASF_Index_Placeholder_Object = new GUID("D9AADE20-7C17-4F9C-BC28-8555DD98E2A2");
122
118
  export default GUID;
119
+ //# sourceMappingURL=GUID.js.map