Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
music-metadata
Advanced tools
The music-metadata npm package is a powerful tool for parsing and extracting metadata from audio files. It supports a wide range of audio formats and provides detailed information about the audio file, including tags, format, and technical properties.
Extract Basic Metadata
This feature allows you to extract basic metadata from an audio file, such as title, artist, album, and genre. The code sample demonstrates how to use the `parseFile` method to read and log metadata from an MP3 file.
const mm = require('music-metadata');
const fs = require('fs');
async function getMetadata(filePath) {
try {
const metadata = await mm.parseFile(filePath);
console.log(metadata);
} catch (error) {
console.error(error.message);
}
}
getMetadata('path/to/audio/file.mp3');
Extract Format Information
This feature allows you to extract format information from an audio file, such as the container type, codec, sample rate, and bit rate. The code sample demonstrates how to use the `parseFile` method to read and log format information from an MP3 file.
const mm = require('music-metadata');
const fs = require('fs');
async function getFormatInfo(filePath) {
try {
const metadata = await mm.parseFile(filePath);
console.log(metadata.format);
} catch (error) {
console.error(error.message);
}
}
getFormatInfo('path/to/audio/file.mp3');
Extract Technical Properties
This feature allows you to extract technical properties from an audio file, such as duration, number of channels, and bit depth. The code sample demonstrates how to use the `parseFile` method to read and log technical properties from an MP3 file.
const mm = require('music-metadata');
const fs = require('fs');
async function getTechnicalProperties(filePath) {
try {
const metadata = await mm.parseFile(filePath);
console.log(metadata.common);
} catch (error) {
console.error(error.message);
}
}
getTechnicalProperties('path/to/audio/file.mp3');
The node-id3 package is focused on reading and writing ID3 tags in MP3 files. It provides a simpler interface for handling ID3 tags compared to music-metadata, but it is limited to MP3 files and does not support other audio formats.
The musicmetadata package is another tool for extracting metadata from audio files. It supports a variety of audio formats and provides similar functionality to music-metadata. However, it is less actively maintained and may not support the latest audio formats and tags.
The id3js package is a JavaScript library for reading ID3 tags from MP3 files. It is designed to work in both Node.js and browser environments. While it offers similar functionality to music-metadata for MP3 files, it does not support other audio formats.
Streaming music metadata parser for node and the browser.
Install via npm:
npm install music-metadata
You can also download a pre packaged browser release from dist/music-metadata.js
.
See example/drop_media_file.html
for usage.
var fs = require('fs')
var mm = require('music-metadata')
const util = require('util')
var audioStream = fs.createReadStream('../test/samples/MusicBrainz-multiartist [id3v2.4].V2.mp3')
// create a new music-metadata from a node ReadStream
mm.parseStream(audioStream, {native: true}, function (err, metadata) {
// important note, the stream is not closed by default. To prevent leaks, you must close it yourself
audioStream.close();
if (err) throw err;
console.log(util.inspect(metadata, {showHidden: false, depth: null}));
});
import * as fs from 'fs'
import * as mm from '..'
import * as util from 'util'
let audioStream = fs.createReadStream('../test/samples/MusicBrainz-multiartist [id3v2.4].V2.mp3')
// create a new music-metadata parser from a node ReadStream
mm.parseStream(audioStream, {native: true}, (err, metadata) => {
// important note, the stream is not closed by default. To prevent leaks, you must close it yourself
audioStream.close();
if (err) throw err;
console.log(util.inspect(metadata, {showHidden: false, depth: null}));
});
This will output the following music metadata:
{
common:
{
artists: [ 'Beth Hart', 'Joe Bonamassa' ],
track: { no: 1, of: 10 },
disk: { no: 1, of: 1 },
title: 'Sinner\'s Prayer',
artist: 'Beth Hart & Joe Bonamassa',
album: 'Don\'t Explain',
year: 2011,
date: '2011-09-27',
picture:
[ { format: 'jpg',
data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 03 02 02 03 03 03 03 04 03 03 04 05 08 05 05 04 04 05 0a 07 07 06 ... > } ],
originaldate: '2011-09-26',
media: 'CD',
albumartist: 'Beth Hart & Joe Bonamassa',
label: 'J&R Adventures',
albumartistsort: 'Hart, Beth & Bonamassa, Joe',
artistsort: 'Hart, Beth & Bonamassa, Joe',
asin: 'B004X5SCGM',
barcode: '804879313915',
catalognumber: 'PRAR931391',
musicbrainz_albumartistid:
[ '3fe817fc-966e-4ece-b00a-76be43e7e73c',
'984f8239-8fe1-4683-9c54-10ffb14439e9' ],
musicbrainz_albumid: 'e7050302-74e6-42e4-aba0-09efd5d431d8',
releasestatus: 'official',
releasetype: [ 'album' ],
musicbrainz_artistid:
[ '3fe817fc-966e-4ece-b00a-76be43e7e73c',
'984f8239-8fe1-4683-9c54-10ffb14439e9' ],
musicbrainz_releasegroupid: 'e00305af-1c72-469b-9a7c-6dc665ca9adc',
musicbrainz_trackid: 'd062f484-253c-374b-85f7-89aab45551c7',
script: 'Latn',
originalyear: 2011,
musicbrainz_recordingid: 'f151cb94-c909-46a8-ad99-fb77391abfb8' },
format:
{ duration: 2,
headerType: 'id3v2.4',
dataformat: 'mp3',
lossless: false,
bitrate: 128000,
sampleRate: 44100,
numberOfChannels: 2,
encoder: 'LAME3.99r',
codecProfile: 'V2' },
'id3v2.4':
{ TIT2: 'Sinner\'s Prayer',
TPE1: 'Beth Hart & Joe Bonamassa',
TRCK: '1/10',
TALB: 'Don\'t Explain',
TPOS: '1/1',
TDRC: '2011-09-27',
APIC:
[ { format: 'image/jpeg',
type: 'Cover (front)',
description: '',
data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 03 02 02 03 03 03 03 04 03 03 04 05 08 05 05 04 04 05 0a 07 07 06 ... > } ],
TDOR: '2011-09-26',
TIPL:
{ producer: [ 'Roy Weisman' ],
engineer: [ 'James McCullagh', 'Jared Kvitka' ],
arranger: [ 'Jeff Bova' ] },
TMCL:
{ 'bass guitar': [ 'Carmine Rojas' ],
orchestra: [ 'The Bovaland Orchestra' ],
drums: [ 'Anton Fig' ],
percussion: [ 'Anton Fig' ],
guitar: [ 'Blondie Chaplin', 'Joe Bonamassa' ],
keyboard: [ 'Arlan Scheirbaum' ],
vocals: [ 'Beth Hart', 'Joe Bonamassa' ],
piano: [ 'Beth Hart' ] },
TMED: 'CD',
TPE2: 'Beth Hart & Joe Bonamassa',
TPUB: 'J&R Adventures',
TSO2: 'Hart, Beth & Bonamassa, Joe',
TSOP: 'Hart, Beth & Bonamassa, Joe',
'TXXX:ACOUSTID_ID': [ '09c06fac-679a-45b1-8ea0-6ce532318363' ],
'TXXX:ARRANGER': [ 'Jeff Bova' ],
'TXXX:ARTISTS': [ 'Joe Bonamassa' ],
'TXXX:ARTISTSORT': [ 'Hart, Beth & Bonamassa, Joe' ],
'TXXX:ASIN': 'B004X5SCGM',
'TXXX:Artists': [ 'Beth Hart', 'Joe Bonamassa' ],
'TXXX:BARCODE': '804879313915',
'TXXX:Band': [ 'Beth Hart & Joe Bonamassa' ],
'TXXX:CATALOGNUMBER': 'PRAR931391',
'TXXX:ENGINEER': [ 'Jared Kvitka' ],
'TXXX:LABEL': [ 'J&R Adventures' ],
'TXXX:MEDIA': [ 'CD' ],
'TXXX:MUSICBRAINZ_ALBUMARTISTID': [ '984f8239-8fe1-4683-9c54-10ffb14439e9' ],
'TXXX:MUSICBRAINZ_ALBUMID': [ 'e7050302-74e6-42e4-aba0-09efd5d431d8' ],
'TXXX:MUSICBRAINZ_ARTISTID': [ '984f8239-8fe1-4683-9c54-10ffb14439e9' ],
'TXXX:MUSICBRAINZ_RELEASEGROUPID': [ 'e00305af-1c72-469b-9a7c-6dc665ca9adc' ],
'TXXX:MUSICBRAINZ_RELEASETRACKID': [ 'd062f484-253c-374b-85f7-89aab45551c7' ],
'TXXX:MUSICBRAINZ_TRACKID': [ 'f151cb94-c909-46a8-ad99-fb77391abfb8' ],
'TXXX:MusicBrainz Album Artist Id':
[ '3fe817fc-966e-4ece-b00a-76be43e7e73c',
'984f8239-8fe1-4683-9c54-10ffb14439e9' ],
'TXXX:MusicBrainz Album Id': 'e7050302-74e6-42e4-aba0-09efd5d431d8',
'TXXX:MusicBrainz Album Status': 'official',
'TXXX:MusicBrainz Album Type': [ 'album' ],
'TXXX:MusicBrainz Artist Id':
[ '3fe817fc-966e-4ece-b00a-76be43e7e73c',
'984f8239-8fe1-4683-9c54-10ffb14439e9' ],
'TXXX:MusicBrainz Release Group Id': 'e00305af-1c72-469b-9a7c-6dc665ca9adc',
'TXXX:MusicBrainz Release Track Id': 'd062f484-253c-374b-85f7-89aab45551c7',
'TXXX:NOTES': [ 'Medieval CUE Splitter (www.medieval.it)' ],
'TXXX:ORIGINALDATE': [ '2011-09-26' ],
'TXXX:ORIGINALYEAR': [ '2011' ],
'TXXX:PERFORMER': [ 'Beth Hart (piano)' ],
'TXXX:PRODUCER': [ 'Roy Weisman' ],
'TXXX:Part of a set': [ '1/1' ],
'TXXX:RELEASECOUNTRY': [ 'GB' ],
'TXXX:RELEASESTATUS': [ 'official' ],
'TXXX:RELEASETYPE': [ 'album' ],
'TXXX:SCRIPT': 'Latn',
'TXXX:originalyear': '2011',
UFID:
[ { owner_identifier: 'http://musicbrainz.org',
identifier: <Buffer 66 31 35 31 63 62 39 34 2d 63 39 30 39 2d 34 36 61 38 2d 61 64 39 39 2d 66 62 37 37 33 39 31 61 62 66 62 38> } ] } }
music-metadata
also emits all metadata it discovers during parsing. For example if you wanted to read the TLEN
frame from an id3v2.x file you can do this:
parser.on('TLEN', function (result) {
console.log(result);
});
Although in most cases duration is included, in some cases it requires music-metadata
parsing the entire file.
To enforce parsing the entire file if needed you should set duration
to true
.
mm(fs.createReadStream('sample.mp3'), { duration: true }, function (err, metadata) {
});
Note that in order to read the duration for streams that are not file streams, in some cases you should pass the size of the file in bytes.
mm(fs.createReadStream('sample.mp3'), { duration: true, fileSize: 26838 }, function (err, metadata) {
});
(The MIT License)
Copyright (c) 2016 Borewit
Based on [musicmetadata] (https://github.com/leetreveil/musicmetadata/) written by Lee Treveil leetreveil@gmail.com and many others.
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
FAQs
Music metadata parser for Node.js, supporting virtual any audio and tag format.
The npm package music-metadata receives a total of 285,203 weekly downloads. As such, music-metadata popularity was classified as popular.
We found that music-metadata demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.