music-metadata 8.1.2 → 8.1.4

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.
package/README.md CHANGED
@@ -1,450 +1,450 @@
1
- ![Node.js CI](https://github.com/Borewit/music-metadata/workflows/Node.js%20CI/badge.svg)
2
- [![Build status](https://ci.appveyor.com/api/projects/status/tgtqynlon8t99qq5/branch/master?svg=true)](https://ci.appveyor.com/project/Borewit/music-metadata/branch/master)
3
- [![NPM version](https://img.shields.io/npm/v/music-metadata.svg)](https://npmjs.org/package/music-metadata)
4
- [![npm downloads](http://img.shields.io/npm/dm/music-metadata.svg)](https://npmcharts.com/compare/music-metadata,jsmediatags,musicmetadata,node-id3,mp3-parser,id3-parser,wav-file-info?start=600)
5
- [![Coverage Status](https://coveralls.io/repos/github/Borewit/music-metadata/badge.svg?branch=master)](https://coveralls.io/github/Borewit/music-metadata?branch=master)
6
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/57d731b05c9e41889a2a17cb4b0384d7)](https://app.codacy.com/app/Borewit/music-metadata?utm_source=github.com&utm_medium=referral&utm_content=Borewit/music-metadata&utm_campaign=Badge_Grade_Dashboard)
7
- [![CodeQL](https://github.com/Borewit/music-metadata/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Borewit/music-metadata/actions/workflows/codeql-analysis.yml)
8
- [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/6938/branches/61821/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=6938&bid=61821)
9
- [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/music-metadata/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/music-metadata?targetFile=package.json)
10
- [![Discord](https://img.shields.io/discord/460524735235883049.svg)](https://discord.gg/KyBr6sb)
11
-
12
- # music-metadata
13
-
14
- Stream and file based music metadata parser for [node.js](https://nodejs.org/).
15
- Supports any common audio and tagging format.
16
- [TypeScript](https://www.typescriptlang.org/) definitions are included.
17
-
18
- ## Features
19
-
20
- ### Support for audio file types
21
-
22
- | Audio format | Description | Wiki | |
23
- | ------------- |---------------------------------| -------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------:|
24
- | AIFF / AIFF-C | Audio Interchange File Format | [:link:](https://wikipedia.org/wiki/Audio_Interchange_File_Format) | <img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Apple_Computer_Logo_rainbow.svg" width="40" alt="Apple rainbow logo"> |
25
- | AAC | ADTS / Advanced Audio Coding | [:link:](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) | <img src="https://svgshare.com/i/UT8.svg" width="40" alt="AAC logo"> |
26
- | APE | Monkey's Audio | [:link:](https://wikipedia.org/wiki/Monkey's_Audio) | <img src="https://foreverhits.files.wordpress.com/2015/05/ape_audio.jpg" width="40" alt="Monkey's Audio logo"> |
27
- | ASF | Advanced Systems Format | [:link:](https://wikipedia.org/wiki/Advanced_Systems_Format) | |
28
- | BWF | Broadcast Wave Format | [:link:](https://en.wikipedia.org/wiki/Broadcast_Wave_Format) | |
29
- | DSDIFF | Philips DSDIFF | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
30
- | DSF | Sony's DSD Stream File | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
31
- | FLAC | Free Lossless Audio Codec | [:link:](https://wikipedia.org/wiki/FLAC) | <img src="https://upload.wikimedia.org/wikipedia/commons/a/a2/FLAC_logo_vector.svg" width="80" alt="FLAC logo"> |
32
- | MP2 | MPEG-1 Audio Layer II | [:link:](https://wikipedia.org/wiki/MPEG-1_Audio_Layer_II) | |
33
- | Matroska | Matroska (EBML), mka, mkv | [:link:](https://wikipedia.org/wiki/Matroska) | <img src="https://upload.wikimedia.org/wikipedia/commons/1/1a/Matroska_2010.svg" width="80" alt="Matroska logo"> |
34
- | MP3 | MPEG-1 / MPEG-2 Audio Layer III | [:link:](https://wikipedia.org/wiki/MP3) | <img src="https://upload.wikimedia.org/wikipedia/commons/e/ea/Mp3.svg" width="80" alt="MP3 logo"> |
35
- | MPC | Musepack SV7 | [:link:](https://wikipedia.org/wiki/Musepack) | <img src="https://www.musepack.net/pictures/musepack_logo.png" width="80" alt="musepack logo"> |
36
- | MPEG 4 | mp4, m4a, m4v | [:link:](https://wikipedia.org/wiki/MPEG-4) | <img src="https://svgshare.com/i/UU3.svg" width="80" alt="mpeg 4 logo"> |
37
- | Ogg | Open container format | [:link:](https://en.wikipedia.org/wiki/Ogg) | <img src="https://upload.wikimedia.org/wikipedia/commons/a/a1/Ogg_Logo.svg" width="80" alt="Ogg logo"> |
38
- | Opus | | [:link:](https://wikipedia.org/wiki/Opus_(audio_format)) | <img src="https://upload.wikimedia.org/wikipedia/commons/0/02/Opus_logo2.svg" width="80" alt="Opus logo"> |
39
- | Speex | | [:link:](https://wikipedia.org/wiki/Speex) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/b5/Speex_logo_2006.svg" width="80" alt="Speex logo"> |
40
- | Theora | | [:link:](https://en.wikipedia.org/wiki/Theora) | <img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Theora_logo_2007.svg" width="70" alt="Theora logo"> |
41
- | Vorbis | Vorbis audio compression | [:link:](https://wikipedia.org/wiki/Ogg_Vorbis) | <img src="https://upload.wikimedia.org/wikipedia/commons/8/8d/Xiph.Org_logo_square.svg" width="70" alt="Vorbis logo"> |
42
- | WAV | RIFF WAVE | [:link:](https://wikipedia.org/wiki/WAV) | |
43
- | WebM | webm | [:link:](https://wikipedia.org/wiki/WebM) | <img src="https://upload.wikimedia.org/wikipedia/commons/3/34/WebM_logo.svg" width="80" alt="Matroska logo"> |
44
- | WV | WavPack | [:link:](https://wikipedia.org/wiki/WavPack) | <img src="http://www.wavpack.com/wavpacklogo.svg" width="60" alt="WavPack logo"> |
45
- | WMA | Windows Media Audio | [:link:](https://wikipedia.org/wiki/Windows_Media_Audio) | <img src="https://upload.wikimedia.org/wikipedia/commons/7/76/Windows_Media_Player_simplified_logo.svg" width="40" alt="Windows Media logo"> |
46
-
47
- ### Supported tag headers
48
-
49
- Following tag header formats are supported:
50
- * [APE](https://wikipedia.org/wiki/APE_tag)
51
- * [ASF](https://wikipedia.org/wiki/Advanced_Systems_Format)
52
- * EXIF 2.3
53
- * [ID3](https://wikipedia.org/wiki/ID3): ID3v1, ID3v1.1, ID3v2.2, [ID3v2.3](http://id3.org/id3v2.3.0) & [ID3v2.4](http://id3.org/id3v2.4.0-frames)
54
- * [iTunes](https://github.com/sergiomb2/libmp4v2/wiki/iTunesMetadata)
55
- * [RIFF](https://wikipedia.org/wiki/Resource_Interchange_File_Format)/INFO
56
- * [Vorbis comment](https://wikipedia.org/wiki/Vorbis_comment)
57
- * [AIFF](https://wikipedia.org/wiki/Audio_Interchange_File_Format)
58
-
59
- It allows many tags to be accessed in audio format, and tag format independent way.
60
-
61
- Support for [MusicBrainz](https://musicbrainz.org/) tags as written by [Picard](https://picard.musicbrainz.org/).
62
- [ReplayGain](https://wiki.hydrogenaud.io/index.php?title=ReplayGain) tags are supported.
63
-
64
- ### Audio format & encoding details
65
-
66
- Support for encoding / format details:
67
- * [Bit rate](https://wikipedia.org/wiki/Bit_rate)
68
- * [Audio bit depth](https://wikipedia.org/wiki/Audio_bit_depth)
69
- * Duration
70
- * Encoding profile (e.g. [CBR](https://en.wikipedia.org/wiki/Constant_bitrate), V0, V2)
71
-
72
-
73
- ## Online demo's
74
- * [<img src="https://raw.githubusercontent.com/Borewit/audio-tag-analyzer/master/src/assets/icon/audio-tag-analyzer.svg" width="40">Audio Tag Analyzer](https://audio-tag-analyzer.netlify.com/)
75
- * [<img src="https://cdn.sanity.io/images/3do82whm/next/ba8c847f13a5fa39d88f8bc9b7846b7886531b18-2500x2500.svg" width="40"> Webamp](https://webamp.org/)
76
-
77
-
78
- ## Compatibility
79
-
80
- Module: version 8 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
81
- JavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).
82
- Requires Node.js ≥ 14.13.1 engine.
83
-
84
- ### Browser Support
85
-
86
- Although music-metadata is designed to run the node.js. [music-metadata-browser](https://github.com/Borewit/music-metadata-browser) can be used on the browser side.
87
-
88
- To avoid Node `fs` dependency inclusion, you may use a sub-module inclusion:
89
- ```js
90
- import * as mm from 'music-metadata/lib/core';
91
- ```
92
-
93
- | function | `music-metadata` | `music-metadata/lib/core` |
94
- |------------------------------------------------------| ---------------------------|----------------------------|
95
- | [`parseBuffer`](#parsebuffer-function) | ✓ | ✓ |
96
- | [`parseStream`](#parsestream-function) * | ✓ | ✓ |
97
- | [`parseFromTokenizer`](#parsefromtokenizer-function) | ✓ | ✓ |
98
- | [`parseFile`](#parsefile-function) | ✓ | |
99
-
100
- ### Sponsor
101
- [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
102
-
103
- ## Usage
104
-
105
- ### Installation
106
- Install using [npm](http://npmjs.org/):
107
-
108
- ```bash
109
- npm install music-metadata
110
- ```
111
- or using [yarn](https://yarnpkg.com/):
112
- ```bash
113
- yarn add music-metadata
114
- ```
115
-
116
- ### Import music-metadata
117
-
118
- Import music-metadata:
119
- ```JavaScript
120
- import { parseFile } from 'music-metadata';
121
- ```
122
- Import the methods you need, like `parseFile` in this example.
123
-
124
- ### Module Functions
125
-
126
- There are two ways to parse (read) audio tracks:
127
- 1) Audio (music) files can be parsed using direct file access using the [parseFile function](#parsefile)
128
- 2) Using [Node.js streams](https://nodejs.org/api/stream.html) using the [parseStream function](#parseStream).
129
-
130
- Direct file access tends to be a little faster, because it can 'jump' to various parts in the file without being obliged to read intermediate data.
131
-
132
- #### parseFile function
133
-
134
- Parses the specified file (`filePath`) and returns a promise with the metadata result (`IAudioMetadata`).
135
-
136
- ```ts
137
- parseFile(filePath: string, opts: IOptions = {}): Promise<IAudioMetadata>`
138
- ```
139
-
140
- Example:
141
- ```js
142
- import { parseFile } from 'music-metadata';
143
- import { inspect } from 'util';
144
-
145
- (async () => {
146
- try {
147
- const metadata = await parseFile('../music-metadata/test/samples/MusicBrainz - Beth Hart - Sinner\'s Prayer [id3v2.3].V2.mp3');
148
- console.log(inspect(metadata, { showHidden: false, depth: null }));
149
- } catch (error) {
150
- console.error(error.message);
151
- }
152
- })();
153
- ```
154
-
155
- #### parseStream function
156
-
157
- Parses the provided audio stream for metadata.
158
- It is recommended to provide the corresponding [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types).
159
- An extension (e.g.: `.mp3`), filename or path will also work.
160
- If the MIME-type or filename (via `fileInfo.path`) is not provided, or not understood, music-metadata will try to derive the type from the content.
161
-
162
- ```ts
163
- parseStream(stream: Stream.Readable, fileInfo?: IFileInfo | string, opts?: IOptions = {}): Promise<IAudioMetadata>`
164
- ```
165
-
166
- Example:
167
- ```js
168
- import { parseStream } from 'music-metadata';
169
-
170
- (async () => {
171
- try {
172
- const metadata = await parseStream(someReadStream, {mimeType: 'audio/mpeg', size: 26838});
173
- console.log(metadata);
174
- } catch (error) {
175
- console.error(error.message);
176
- }
177
- })();
178
- ```
179
-
180
- #### parseBuffer function
181
-
182
- Parse metadata from an audio file, where the audio file is held in a [Buffer](https://nodejs.org/api/buffer.html).
183
-
184
- ```ts
185
- parseBuffer(buffer: Buffer, fileInfo?: IFileInfo | string, opts?: IOptions = {}): Promise<IAudioMetadata>
186
- ```
187
-
188
- Example:
189
- ```js
190
- import { parseBuffer } from 'music-metadata';
191
-
192
- (async () => {
193
- try {
194
- const metadata = await parseBuffer(someBuffer, 'audio/mpeg');
195
- console.log(metadata);
196
- } catch (error) {
197
- console.error(error.message);
198
- }
199
- })();
200
- ```
201
-
202
- #### parseFromTokenizer function
203
- This is a low level function, reading from a [strtok3](https://github.com/Borewit/strtok3) ITokenizer interface.
204
- [music-metadata-browser](https://github.com/Borewit/music-metadata-browser) is depended on this function.
205
-
206
- This also enables special read modules like:
207
- * [streaming-http-token-reader](https://github.com/Borewit/streaming-http-token-reader) for chunked HTTP(S) reading, using [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests).
208
-
209
- #### orderTags function
210
-
211
- Utility to Converts the native tags to a dictionary index on the tag identifier
212
-
213
- ```ts
214
- orderTags(nativeTags: ITag[]): [tagId: string]: any[]
215
- ```
216
-
217
- ```js
218
- import { parseFile, orderTags } from 'music-metadata';
219
- import { inspect } from 'util';
220
-
221
- (async () => {
222
- try {
223
- const metadata = await parseFile('../test/samples/MusicBrainz - Beth Hart - Sinner\'s Prayer [id3v2.3].V2.mp3');
224
- const orderedTags = orderTags(metadata.native['ID3v2.3']);
225
- console.log(inspect(orderedTags, { showHidden: false, depth: null }));
226
- } catch (error) {
227
- console.error(error.message);
228
- }
229
- })();
230
- ```
231
-
232
- #### ratingToStars function
233
-
234
- Can be used to convert the normalized rating value to the 0..5 stars, where 0 an undefined rating, 1 the star the lowest rating and 5 the highest rating.
235
-
236
- ```ts
237
- ratingToStars(rating: number): number
238
- ```
239
- #### selectCover function
240
-
241
- Select cover image based on image type field, otherwise the first picture in file.
242
-
243
- ```ts
244
- export function selectCover(pictures?: IPicture[]): IPicture | null
245
- ```
246
-
247
- ```js
248
- import { parseFile, selectCover } from 'music-metadata';
249
-
250
- (async () => {
251
- const {common} = await parseFile(filePath);
252
- const cover = selectCover(common.picture); // pick the cover image
253
- }
254
- )();
255
- ```
256
-
257
- ### Options
258
- * `duration`: default: `false`, if set to `true`, it will parse the whole media file if required to determine the duration.
259
- * `observer: (update: MetadataEvent) => void;`: Will be called after each change to `common` (generic) tag, or `format` properties.
260
- * `skipCovers`: default: `false`, if set to `true`, it will not return embedded cover-art (images).
261
- * `skipPostHeaders? boolean` default: `false`, if set to `true`, it will not search all the entire track for additional headers. Only recommenced to use in combination with streams.
262
- * `includeChapters` default: `false`, if set to `true`, it will parse chapters (currently only MP4 files). _experimental functionality_
263
-
264
- Although in most cases duration is included, in some cases it requires `music-metadata` parsing the entire file.
265
- To enforce parsing the entire file if needed you should set `duration` to `true`.
266
-
267
- ### Metadata result
268
-
269
- If the returned promise resolves, the metadata (TypeScript `IAudioMetadata` interface) contains:
270
- * [`metadata.format`](#metadataformat) Audio format information
271
- * [`metadata.common`](#metadatacommon) Is a generic (abstract) way of reading metadata information.
272
- * [`metadata.trackInfo`](#metadatatrackInfo) Is a generic (abstract) way of reading metadata information.
273
- * `metadata.native` List of native (original) tags found in the parsed audio file.
274
-
275
- #### `metadata.format`
276
-
277
- The questionmark `?` indicates the property is optional.
278
-
279
- Audio format information. Defined in the TypeScript `IFormat` interface:
280
- * `format.container?: string` Audio encoding format. e.g.: 'flac'
281
- * `format.codec?` Name of the codec (algorithm used for the audio compression)
282
- * `format.codecProfile?: string` Codec profile / settings
283
- * `format.tagTypes?: TagType[]` List of tagging formats found in parsed audio file
284
- * `format.duration?: number` Duration in seconds
285
- * `format.bitrate?: number` Number bits per second of encoded audio file
286
- * `format.sampleRate?: number` Sampling rate in Samples per second (S/s)
287
- * `format.bitsPerSample?: number` Audio bit depth
288
- * `format.lossless?: boolean` True if lossless, false for lossy encoding
289
- * `format.numberOfChannels?: number` Number of audio channels
290
- * `format.creationTime?: Date` Track creation time
291
- * `format.modificationTime?: Date` Track modification / tag update time
292
- * `format.trackGain?: number` Track gain in dB
293
- * `format.albumGain?: number` Album gain in dB
294
-
295
- #### `metadata.trackInfo`
296
-
297
- To support advanced containers like [Matroska](https://wikipedia.org/wiki/Matroska) or [MPEG-4](https://en.wikipedia.org/wiki/MPEG-4), which may contain multiple audio and video tracks, the **experimental** `metadata.trackInfo` has been added,
298
-
299
- `metadata.trackInfo` is either `undefined` or has an **array** of [trackInfo](#trackinfo)
300
-
301
- ##### trackInfo
302
-
303
- Audio format information. Defined in the TypeScript `IFormat` interface:
304
- * `trackInfo.type?: TrackType` Track type
305
- * `trackInfo.codecName?: string` Codec name
306
- * `trackInfo.codecSettings?: string` Codec settings
307
- * `trackInfo.flagEnabled?: boolean` Set if the track is usable, default: `true`
308
- * `trackInfo.flagDefault?: boolean` Set if that track (audio, video or subs) SHOULD be active if no language found matches the user preference.
309
- * `trackInfo.flagLacing?: boolean` Set if the track **may** contain blocks using lacing
310
- * `trackInfo.name?: string` A human-readable track name.
311
- * `trackInfo.language?: string` Specifies the language of the track
312
- * `trackInfo.audio?: IAudioTrack`, see [`trackInfo.audioTrack`](#trackinfoaudiotrack)
313
- * `trackInfo.video?: IVideoTrack`, see [`trackInfo.videoTrack`](#trackinfovideotrack)
314
-
315
- ##### `trackInfo.audioTrack`
316
-
317
- * `audioTrack.samplingFrequency?: number`
318
- * `audioTrack.outputSamplingFrequency?: number`
319
- * `audioTrack.channels?: number`
320
- * `audioTrack.channelPositions?: Buffer`
321
- * `audioTrack.bitDepth?: number`
322
-
323
- ##### `trackInfo.videoTrack`
324
-
325
- * `videoTrack.flagInterlaced?: boolean`
326
- * `videoTrack.stereoMode?: number`
327
- * `videoTrack.pixelWidth?: number`
328
- * `videoTrack.pixelHeight?: number`
329
- * `videoTrack.displayWidth?: number`
330
- * `videoTrack.displayHeight?: number`
331
- * `videoTrack.displayUnit?: number`
332
- * `videoTrack.aspectRatioType?: number`
333
- * `videoTrack.colourSpace?: Buffer`
334
- * `videoTrack.gammaValue?: number`
335
-
336
- #### `metadata.common`
337
-
338
- [Common tag documentation](doc/common_metadata.md) is automatically generated.
339
-
340
- ## Examples
341
-
342
- In order to read the duration of a stream (with the exception of file streams), in some cases you should pass the size of the file in bytes.
343
- ```js
344
- import { parseStream } from 'music-metadata';
345
- import { inspect } from 'util';
346
-
347
- (async () => {
348
- const metadata = await parseStream(someReadStream, {mimeType: 'audio/mpeg', size: 26838}, {duration: true});
349
- console.log(inspect(metadata, {showHidden: false, depth: null}));
350
- someReadStream.close();
351
- }
352
- )();
353
- ```
354
-
355
- ### Access cover art
356
-
357
- Via `metadata.common.picture` you can access an array of cover art if present.
358
- Each picture has this interface:
359
-
360
- ```ts
361
- /**
362
- * Attached picture, typically used for cover art
363
- */
364
- export interface IPicture {
365
- /**
366
- * Image mime type
367
- */
368
- format: string;
369
- /**
370
- * Image data
371
- */
372
- data: Buffer;
373
- /**
374
- * Optional description
375
- */
376
- description?: string;
377
- /**
378
- * Picture type
379
- */
380
- type?: string;
381
- }
382
- ```
383
-
384
- To assign `img` HTML-object you can do something like:
385
- ```js
386
- img.src = `data:${picture.format};base64,${picture.data.toString('base64')}`;
387
- ```
388
-
389
- ## Frequently Asked Questions
390
-
391
- 1. How can I traverse (a long) list of files?
392
-
393
- What is important that file parsing should be done in a sequential manner.
394
- In a plain loop, due to the asynchronous character (like most JavaScript functions), it would cause all the files to run in parallel which is will cause your application to hang in no time.
395
- There are multiple ways of achieving this:
396
-
397
- 1. Using recursion
398
-
399
- ```js
400
- import { parseFile } from 'music-metadata';
401
-
402
- function parseFiles(audioFiles) {
403
-
404
- const audioFile = audioFiles.shift();
405
-
406
- if (audioFile) {
407
- return parseFile(audioFile).then(metadata => {
408
- // Do great things with the metadata
409
- return parseFiles(audioFiles); // process rest of the files AFTER we are finished
410
- })
411
- }
412
- }
413
-
414
- ```
415
-
416
- 2. Use async/await
417
-
418
- Use [async/await](https://javascript.info/async-await)
419
-
420
- ```js
421
- import { parseFile } from 'music-metadata';
422
-
423
- // it is required to declare the function 'async' to allow the use of await
424
- async function parseFiles(audioFiles) {
425
-
426
- for (const audioFile of audioFiles) {
427
-
428
- // await will ensure the metadata parsing is completed before we move on to the next file
429
- const metadata = await parseFile(audioFile);
430
- // Do great things with the metadata
431
- }
432
- }
433
- ```
434
-
435
- 3. Use a specialized module to traverse files
436
-
437
- There are specialized modules to traversing (walking) files and directory,
438
- like [walk](https://www.npmjs.com/package/walk).
439
-
440
- ## Licence
441
-
442
- The MIT License (MIT)
443
-
444
- Copyright © 2022 Borewit
445
-
446
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
447
-
448
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
449
-
450
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ ![Node.js CI](https://github.com/Borewit/music-metadata/workflows/Node.js%20CI/badge.svg)
2
+ [![Build status](https://ci.appveyor.com/api/projects/status/tgtqynlon8t99qq5/branch/master?svg=true)](https://ci.appveyor.com/project/Borewit/music-metadata/branch/master)
3
+ [![NPM version](https://img.shields.io/npm/v/music-metadata.svg)](https://npmjs.org/package/music-metadata)
4
+ [![npm downloads](http://img.shields.io/npm/dm/music-metadata.svg)](https://npmcharts.com/compare/music-metadata,jsmediatags,musicmetadata,node-id3,mp3-parser,id3-parser,wav-file-info?start=600)
5
+ [![Coverage Status](https://coveralls.io/repos/github/Borewit/music-metadata/badge.svg?branch=master)](https://coveralls.io/github/Borewit/music-metadata?branch=master)
6
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/57d731b05c9e41889a2a17cb4b0384d7)](https://app.codacy.com/app/Borewit/music-metadata?utm_source=github.com&utm_medium=referral&utm_content=Borewit/music-metadata&utm_campaign=Badge_Grade_Dashboard)
7
+ [![CodeQL](https://github.com/Borewit/music-metadata/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Borewit/music-metadata/actions/workflows/codeql-analysis.yml)
8
+ [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/6938/branches/61821/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=6938&bid=61821)
9
+ [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/music-metadata/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/music-metadata?targetFile=package.json)
10
+ [![Discord](https://img.shields.io/discord/460524735235883049.svg)](https://discord.gg/KyBr6sb)
11
+
12
+ # music-metadata
13
+
14
+ Stream and file based music metadata parser for [node.js](https://nodejs.org/).
15
+ Supports any common audio and tagging format.
16
+ [TypeScript](https://www.typescriptlang.org/) definitions are included.
17
+
18
+ ## Features
19
+
20
+ ### Support for audio file types
21
+
22
+ | Audio format | Description | Wiki | |
23
+ | ------------- |---------------------------------| -------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------:|
24
+ | AIFF / AIFF-C | Audio Interchange File Format | [:link:](https://wikipedia.org/wiki/Audio_Interchange_File_Format) | <img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Apple_Computer_Logo_rainbow.svg" width="40" alt="Apple rainbow logo"> |
25
+ | AAC | ADTS / Advanced Audio Coding | [:link:](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) | <img src="https://svgshare.com/i/UT8.svg" width="40" alt="AAC logo"> |
26
+ | APE | Monkey's Audio | [:link:](https://wikipedia.org/wiki/Monkey's_Audio) | <img src="https://foreverhits.files.wordpress.com/2015/05/ape_audio.jpg" width="40" alt="Monkey's Audio logo"> |
27
+ | ASF | Advanced Systems Format | [:link:](https://wikipedia.org/wiki/Advanced_Systems_Format) | |
28
+ | BWF | Broadcast Wave Format | [:link:](https://en.wikipedia.org/wiki/Broadcast_Wave_Format) | |
29
+ | DSDIFF | Philips DSDIFF | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
30
+ | DSF | Sony's DSD Stream File | [:link:](https://wikipedia.org/wiki/Direct_Stream_Digital) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/bc/DSDlogo.svg" width="80" alt="DSD logo"> |
31
+ | FLAC | Free Lossless Audio Codec | [:link:](https://wikipedia.org/wiki/FLAC) | <img src="https://upload.wikimedia.org/wikipedia/commons/a/a2/FLAC_logo_vector.svg" width="80" alt="FLAC logo"> |
32
+ | MP2 | MPEG-1 Audio Layer II | [:link:](https://wikipedia.org/wiki/MPEG-1_Audio_Layer_II) | |
33
+ | Matroska | Matroska (EBML), mka, mkv | [:link:](https://wikipedia.org/wiki/Matroska) | <img src="https://upload.wikimedia.org/wikipedia/commons/1/1a/Matroska_2010.svg" width="80" alt="Matroska logo"> |
34
+ | MP3 | MPEG-1 / MPEG-2 Audio Layer III | [:link:](https://wikipedia.org/wiki/MP3) | <img src="https://upload.wikimedia.org/wikipedia/commons/e/ea/Mp3.svg" width="80" alt="MP3 logo"> |
35
+ | MPC | Musepack SV7 | [:link:](https://wikipedia.org/wiki/Musepack) | <img src="https://www.musepack.net/pictures/musepack_logo.png" width="80" alt="musepack logo"> |
36
+ | MPEG 4 | mp4, m4a, m4v | [:link:](https://wikipedia.org/wiki/MPEG-4) | <img src="https://svgshare.com/i/UU3.svg" width="80" alt="mpeg 4 logo"> |
37
+ | Ogg | Open container format | [:link:](https://en.wikipedia.org/wiki/Ogg) | <img src="https://upload.wikimedia.org/wikipedia/commons/a/a1/Ogg_Logo.svg" width="80" alt="Ogg logo"> |
38
+ | Opus | | [:link:](https://wikipedia.org/wiki/Opus_(audio_format)) | <img src="https://upload.wikimedia.org/wikipedia/commons/0/02/Opus_logo2.svg" width="80" alt="Opus logo"> |
39
+ | Speex | | [:link:](https://wikipedia.org/wiki/Speex) | <img src="https://upload.wikimedia.org/wikipedia/commons/b/b5/Speex_logo_2006.svg" width="80" alt="Speex logo"> |
40
+ | Theora | | [:link:](https://en.wikipedia.org/wiki/Theora) | <img src="https://upload.wikimedia.org/wikipedia/commons/5/57/Theora_logo_2007.svg" width="70" alt="Theora logo"> |
41
+ | Vorbis | Vorbis audio compression | [:link:](https://wikipedia.org/wiki/Ogg_Vorbis) | <img src="https://upload.wikimedia.org/wikipedia/commons/8/8d/Xiph.Org_logo_square.svg" width="70" alt="Vorbis logo"> |
42
+ | WAV | RIFF WAVE | [:link:](https://wikipedia.org/wiki/WAV) | |
43
+ | WebM | webm | [:link:](https://wikipedia.org/wiki/WebM) | <img src="https://upload.wikimedia.org/wikipedia/commons/3/34/WebM_logo.svg" width="80" alt="Matroska logo"> |
44
+ | WV | WavPack | [:link:](https://wikipedia.org/wiki/WavPack) | <img src="http://www.wavpack.com/wavpacklogo.svg" width="60" alt="WavPack logo"> |
45
+ | WMA | Windows Media Audio | [:link:](https://wikipedia.org/wiki/Windows_Media_Audio) | <img src="https://upload.wikimedia.org/wikipedia/commons/7/76/Windows_Media_Player_simplified_logo.svg" width="40" alt="Windows Media logo"> |
46
+
47
+ ### Supported tag headers
48
+
49
+ Following tag header formats are supported:
50
+ * [APE](https://wikipedia.org/wiki/APE_tag)
51
+ * [ASF](https://wikipedia.org/wiki/Advanced_Systems_Format)
52
+ * EXIF 2.3
53
+ * [ID3](https://wikipedia.org/wiki/ID3): ID3v1, ID3v1.1, ID3v2.2, [ID3v2.3](http://id3.org/id3v2.3.0) & [ID3v2.4](http://id3.org/id3v2.4.0-frames)
54
+ * [iTunes](https://github.com/sergiomb2/libmp4v2/wiki/iTunesMetadata)
55
+ * [RIFF](https://wikipedia.org/wiki/Resource_Interchange_File_Format)/INFO
56
+ * [Vorbis comment](https://wikipedia.org/wiki/Vorbis_comment)
57
+ * [AIFF](https://wikipedia.org/wiki/Audio_Interchange_File_Format)
58
+
59
+ It allows many tags to be accessed in audio format, and tag format independent way.
60
+
61
+ Support for [MusicBrainz](https://musicbrainz.org/) tags as written by [Picard](https://picard.musicbrainz.org/).
62
+ [ReplayGain](https://wiki.hydrogenaud.io/index.php?title=ReplayGain) tags are supported.
63
+
64
+ ### Audio format & encoding details
65
+
66
+ Support for encoding / format details:
67
+ * [Bit rate](https://wikipedia.org/wiki/Bit_rate)
68
+ * [Audio bit depth](https://wikipedia.org/wiki/Audio_bit_depth)
69
+ * Duration
70
+ * Encoding profile (e.g. [CBR](https://en.wikipedia.org/wiki/Constant_bitrate), V0, V2)
71
+
72
+
73
+ ## Online demo's
74
+ * [<img src="https://raw.githubusercontent.com/Borewit/audio-tag-analyzer/master/src/assets/icon/audio-tag-analyzer.svg" width="40">Audio Tag Analyzer](https://audio-tag-analyzer.netlify.com/)
75
+ * [<img src="https://cdn.sanity.io/images/3do82whm/next/ba8c847f13a5fa39d88f8bc9b7846b7886531b18-2500x2500.svg" width="40"> Webamp](https://webamp.org/)
76
+
77
+
78
+ ## Compatibility
79
+
80
+ Module: version 8 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
81
+ JavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).
82
+ Requires Node.js ≥ 14.13.1 engine.
83
+
84
+ ### Browser Support
85
+
86
+ Although music-metadata is designed to run the node.js. [music-metadata-browser](https://github.com/Borewit/music-metadata-browser) can be used on the browser side.
87
+
88
+ To avoid Node `fs` dependency inclusion, you may use a sub-module inclusion:
89
+ ```js
90
+ import * as mm from 'music-metadata/lib/core';
91
+ ```
92
+
93
+ | function | `music-metadata` | `music-metadata/lib/core` |
94
+ |------------------------------------------------------| ---------------------------|----------------------------|
95
+ | [`parseBuffer`](#parsebuffer-function) | ✓ | ✓ |
96
+ | [`parseStream`](#parsestream-function) * | ✓ | ✓ |
97
+ | [`parseFromTokenizer`](#parsefromtokenizer-function) | ✓ | ✓ |
98
+ | [`parseFile`](#parsefile-function) | ✓ | |
99
+
100
+ ### Sponsor
101
+ [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
102
+
103
+ ## Usage
104
+
105
+ ### Installation
106
+ Install using [npm](http://npmjs.org/):
107
+
108
+ ```bash
109
+ npm install music-metadata
110
+ ```
111
+ or using [yarn](https://yarnpkg.com/):
112
+ ```bash
113
+ yarn add music-metadata
114
+ ```
115
+
116
+ ### Import music-metadata
117
+
118
+ Import music-metadata:
119
+ ```JavaScript
120
+ import { parseFile } from 'music-metadata';
121
+ ```
122
+ Import the methods you need, like `parseFile` in this example.
123
+
124
+ ### Module Functions
125
+
126
+ There are two ways to parse (read) audio tracks:
127
+ 1) Audio (music) files can be parsed using direct file access using the [parseFile function](#parsefile)
128
+ 2) Using [Node.js streams](https://nodejs.org/api/stream.html) using the [parseStream function](#parseStream).
129
+
130
+ Direct file access tends to be a little faster, because it can 'jump' to various parts in the file without being obliged to read intermediate data.
131
+
132
+ #### parseFile function
133
+
134
+ Parses the specified file (`filePath`) and returns a promise with the metadata result (`IAudioMetadata`).
135
+
136
+ ```ts
137
+ parseFile(filePath: string, opts: IOptions = {}): Promise<IAudioMetadata>`
138
+ ```
139
+
140
+ Example:
141
+ ```js
142
+ import { parseFile } from 'music-metadata';
143
+ import { inspect } from 'util';
144
+
145
+ (async () => {
146
+ try {
147
+ const metadata = await parseFile('../music-metadata/test/samples/MusicBrainz - Beth Hart - Sinner\'s Prayer [id3v2.3].V2.mp3');
148
+ console.log(inspect(metadata, { showHidden: false, depth: null }));
149
+ } catch (error) {
150
+ console.error(error.message);
151
+ }
152
+ })();
153
+ ```
154
+
155
+ #### parseStream function
156
+
157
+ Parses the provided audio stream for metadata.
158
+ It is recommended to provide the corresponding [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types).
159
+ An extension (e.g.: `.mp3`), filename or path will also work.
160
+ If the MIME-type or filename (via `fileInfo.path`) is not provided, or not understood, music-metadata will try to derive the type from the content.
161
+
162
+ ```ts
163
+ parseStream(stream: Stream.Readable, fileInfo?: IFileInfo | string, opts?: IOptions = {}): Promise<IAudioMetadata>`
164
+ ```
165
+
166
+ Example:
167
+ ```js
168
+ import { parseStream } from 'music-metadata';
169
+
170
+ (async () => {
171
+ try {
172
+ const metadata = await parseStream(someReadStream, {mimeType: 'audio/mpeg', size: 26838});
173
+ console.log(metadata);
174
+ } catch (error) {
175
+ console.error(error.message);
176
+ }
177
+ })();
178
+ ```
179
+
180
+ #### parseBuffer function
181
+
182
+ Parse metadata from an audio file, where the audio file is held in a [Buffer](https://nodejs.org/api/buffer.html).
183
+
184
+ ```ts
185
+ parseBuffer(buffer: Buffer, fileInfo?: IFileInfo | string, opts?: IOptions = {}): Promise<IAudioMetadata>
186
+ ```
187
+
188
+ Example:
189
+ ```js
190
+ import { parseBuffer } from 'music-metadata';
191
+
192
+ (async () => {
193
+ try {
194
+ const metadata = await parseBuffer(someBuffer, 'audio/mpeg');
195
+ console.log(metadata);
196
+ } catch (error) {
197
+ console.error(error.message);
198
+ }
199
+ })();
200
+ ```
201
+
202
+ #### parseFromTokenizer function
203
+ This is a low level function, reading from a [strtok3](https://github.com/Borewit/strtok3) ITokenizer interface.
204
+ [music-metadata-browser](https://github.com/Borewit/music-metadata-browser) is depended on this function.
205
+
206
+ This also enables special read modules like:
207
+ * [streaming-http-token-reader](https://github.com/Borewit/streaming-http-token-reader) for chunked HTTP(S) reading, using [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests).
208
+
209
+ #### orderTags function
210
+
211
+ Utility to Converts the native tags to a dictionary index on the tag identifier
212
+
213
+ ```ts
214
+ orderTags(nativeTags: ITag[]): [tagId: string]: any[]
215
+ ```
216
+
217
+ ```js
218
+ import { parseFile, orderTags } from 'music-metadata';
219
+ import { inspect } from 'util';
220
+
221
+ (async () => {
222
+ try {
223
+ const metadata = await parseFile('../test/samples/MusicBrainz - Beth Hart - Sinner\'s Prayer [id3v2.3].V2.mp3');
224
+ const orderedTags = orderTags(metadata.native['ID3v2.3']);
225
+ console.log(inspect(orderedTags, { showHidden: false, depth: null }));
226
+ } catch (error) {
227
+ console.error(error.message);
228
+ }
229
+ })();
230
+ ```
231
+
232
+ #### ratingToStars function
233
+
234
+ Can be used to convert the normalized rating value to the 0..5 stars, where 0 an undefined rating, 1 the star the lowest rating and 5 the highest rating.
235
+
236
+ ```ts
237
+ ratingToStars(rating: number): number
238
+ ```
239
+ #### selectCover function
240
+
241
+ Select cover image based on image type field, otherwise the first picture in file.
242
+
243
+ ```ts
244
+ export function selectCover(pictures?: IPicture[]): IPicture | null
245
+ ```
246
+
247
+ ```js
248
+ import { parseFile, selectCover } from 'music-metadata';
249
+
250
+ (async () => {
251
+ const {common} = await parseFile(filePath);
252
+ const cover = selectCover(common.picture); // pick the cover image
253
+ }
254
+ )();
255
+ ```
256
+
257
+ ### Options
258
+ * `duration`: default: `false`, if set to `true`, it will parse the whole media file if required to determine the duration.
259
+ * `observer: (update: MetadataEvent) => void;`: Will be called after each change to `common` (generic) tag, or `format` properties.
260
+ * `skipCovers`: default: `false`, if set to `true`, it will not return embedded cover-art (images).
261
+ * `skipPostHeaders? boolean` default: `false`, if set to `true`, it will not search all the entire track for additional headers. Only recommenced to use in combination with streams.
262
+ * `includeChapters` default: `false`, if set to `true`, it will parse chapters (currently only MP4 files). _experimental functionality_
263
+
264
+ Although in most cases duration is included, in some cases it requires `music-metadata` parsing the entire file.
265
+ To enforce parsing the entire file if needed you should set `duration` to `true`.
266
+
267
+ ### Metadata result
268
+
269
+ If the returned promise resolves, the metadata (TypeScript `IAudioMetadata` interface) contains:
270
+ * [`metadata.format`](#metadataformat) Audio format information
271
+ * [`metadata.common`](#metadatacommon) Is a generic (abstract) way of reading metadata information.
272
+ * [`metadata.trackInfo`](#metadatatrackInfo) Is a generic (abstract) way of reading metadata information.
273
+ * `metadata.native` List of native (original) tags found in the parsed audio file.
274
+
275
+ #### `metadata.format`
276
+
277
+ The questionmark `?` indicates the property is optional.
278
+
279
+ Audio format information. Defined in the TypeScript `IFormat` interface:
280
+ * `format.container?: string` Audio encoding format. e.g.: 'flac'
281
+ * `format.codec?` Name of the codec (algorithm used for the audio compression)
282
+ * `format.codecProfile?: string` Codec profile / settings
283
+ * `format.tagTypes?: TagType[]` List of tagging formats found in parsed audio file
284
+ * `format.duration?: number` Duration in seconds
285
+ * `format.bitrate?: number` Number bits per second of encoded audio file
286
+ * `format.sampleRate?: number` Sampling rate in Samples per second (S/s)
287
+ * `format.bitsPerSample?: number` Audio bit depth
288
+ * `format.lossless?: boolean` True if lossless, false for lossy encoding
289
+ * `format.numberOfChannels?: number` Number of audio channels
290
+ * `format.creationTime?: Date` Track creation time
291
+ * `format.modificationTime?: Date` Track modification / tag update time
292
+ * `format.trackGain?: number` Track gain in dB
293
+ * `format.albumGain?: number` Album gain in dB
294
+
295
+ #### `metadata.trackInfo`
296
+
297
+ To support advanced containers like [Matroska](https://wikipedia.org/wiki/Matroska) or [MPEG-4](https://en.wikipedia.org/wiki/MPEG-4), which may contain multiple audio and video tracks, the **experimental** `metadata.trackInfo` has been added,
298
+
299
+ `metadata.trackInfo` is either `undefined` or has an **array** of [trackInfo](#trackinfo)
300
+
301
+ ##### trackInfo
302
+
303
+ Audio format information. Defined in the TypeScript `IFormat` interface:
304
+ * `trackInfo.type?: TrackType` Track type
305
+ * `trackInfo.codecName?: string` Codec name
306
+ * `trackInfo.codecSettings?: string` Codec settings
307
+ * `trackInfo.flagEnabled?: boolean` Set if the track is usable, default: `true`
308
+ * `trackInfo.flagDefault?: boolean` Set if that track (audio, video or subs) SHOULD be active if no language found matches the user preference.
309
+ * `trackInfo.flagLacing?: boolean` Set if the track **may** contain blocks using lacing
310
+ * `trackInfo.name?: string` A human-readable track name.
311
+ * `trackInfo.language?: string` Specifies the language of the track
312
+ * `trackInfo.audio?: IAudioTrack`, see [`trackInfo.audioTrack`](#trackinfoaudiotrack)
313
+ * `trackInfo.video?: IVideoTrack`, see [`trackInfo.videoTrack`](#trackinfovideotrack)
314
+
315
+ ##### `trackInfo.audioTrack`
316
+
317
+ * `audioTrack.samplingFrequency?: number`
318
+ * `audioTrack.outputSamplingFrequency?: number`
319
+ * `audioTrack.channels?: number`
320
+ * `audioTrack.channelPositions?: Buffer`
321
+ * `audioTrack.bitDepth?: number`
322
+
323
+ ##### `trackInfo.videoTrack`
324
+
325
+ * `videoTrack.flagInterlaced?: boolean`
326
+ * `videoTrack.stereoMode?: number`
327
+ * `videoTrack.pixelWidth?: number`
328
+ * `videoTrack.pixelHeight?: number`
329
+ * `videoTrack.displayWidth?: number`
330
+ * `videoTrack.displayHeight?: number`
331
+ * `videoTrack.displayUnit?: number`
332
+ * `videoTrack.aspectRatioType?: number`
333
+ * `videoTrack.colourSpace?: Buffer`
334
+ * `videoTrack.gammaValue?: number`
335
+
336
+ #### `metadata.common`
337
+
338
+ [Common tag documentation](doc/common_metadata.md) is automatically generated.
339
+
340
+ ## Examples
341
+
342
+ In order to read the duration of a stream (with the exception of file streams), in some cases you should pass the size of the file in bytes.
343
+ ```js
344
+ import { parseStream } from 'music-metadata';
345
+ import { inspect } from 'util';
346
+
347
+ (async () => {
348
+ const metadata = await parseStream(someReadStream, {mimeType: 'audio/mpeg', size: 26838}, {duration: true});
349
+ console.log(inspect(metadata, {showHidden: false, depth: null}));
350
+ someReadStream.close();
351
+ }
352
+ )();
353
+ ```
354
+
355
+ ### Access cover art
356
+
357
+ Via `metadata.common.picture` you can access an array of cover art if present.
358
+ Each picture has this interface:
359
+
360
+ ```ts
361
+ /**
362
+ * Attached picture, typically used for cover art
363
+ */
364
+ export interface IPicture {
365
+ /**
366
+ * Image mime type
367
+ */
368
+ format: string;
369
+ /**
370
+ * Image data
371
+ */
372
+ data: Buffer;
373
+ /**
374
+ * Optional description
375
+ */
376
+ description?: string;
377
+ /**
378
+ * Picture type
379
+ */
380
+ type?: string;
381
+ }
382
+ ```
383
+
384
+ To assign `img` HTML-object you can do something like:
385
+ ```js
386
+ img.src = `data:${picture.format};base64,${picture.data.toString('base64')}`;
387
+ ```
388
+
389
+ ## Frequently Asked Questions
390
+
391
+ 1. How can I traverse (a long) list of files?
392
+
393
+ What is important that file parsing should be done in a sequential manner.
394
+ In a plain loop, due to the asynchronous character (like most JavaScript functions), it would cause all the files to run in parallel which is will cause your application to hang in no time.
395
+ There are multiple ways of achieving this:
396
+
397
+ 1. Using recursion
398
+
399
+ ```js
400
+ import { parseFile } from 'music-metadata';
401
+
402
+ function parseFiles(audioFiles) {
403
+
404
+ const audioFile = audioFiles.shift();
405
+
406
+ if (audioFile) {
407
+ return parseFile(audioFile).then(metadata => {
408
+ // Do great things with the metadata
409
+ return parseFiles(audioFiles); // process rest of the files AFTER we are finished
410
+ })
411
+ }
412
+ }
413
+
414
+ ```
415
+
416
+ 2. Use async/await
417
+
418
+ Use [async/await](https://javascript.info/async-await)
419
+
420
+ ```js
421
+ import { parseFile } from 'music-metadata';
422
+
423
+ // it is required to declare the function 'async' to allow the use of await
424
+ async function parseFiles(audioFiles) {
425
+
426
+ for (const audioFile of audioFiles) {
427
+
428
+ // await will ensure the metadata parsing is completed before we move on to the next file
429
+ const metadata = await parseFile(audioFile);
430
+ // Do great things with the metadata
431
+ }
432
+ }
433
+ ```
434
+
435
+ 3. Use a specialized module to traverse files
436
+
437
+ There are specialized modules to traversing (walking) files and directory,
438
+ like [walk](https://www.npmjs.com/package/walk).
439
+
440
+ ## Licence
441
+
442
+ The MIT License (MIT)
443
+
444
+ Copyright © 2022 Borewit
445
+
446
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
447
+
448
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
449
+
450
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.