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/index.html
for usage.
var fs = require('fs');
var mm = require('music-metadata');
// create a new parser from a node ReadStream
var parser = mm(fs.createReadStream('04. Lungs.flac'), {native=true, duration=true}, function (err, metadata) {
if (err) throw err;
console.log(metadata);
});
This will output the following music metadata:
{
common: {
title: 'Lungs',
artist: ['I Have A Tribe'],
albumartist: ['I Have A Tribe'],
album: 'No Countries',
year: '2015',
track: {no: 4, of: 5},
genre: ['Pop Rock'],
disk: {no: 1, of: 1},
picture: [
{
format: 'jpg',
data: {
type: 'Buffer',
data: ['...']
}
}
],
grouping: 'Rock',
copyright: '2015 Grönland Records',
releasecountry: 'DE',
label: 'Grönland Records',
musicbrainz_albumartistid: ['d8e73ae6-9884-4061-a056-c686b3375c9d'],
date: '2015-10-16',
musicbrainz_trackid: 'ed040a93-1f95-4f91-8c41-359f5a6e7770',
albumartistsort: ['I Have a Tribe'],
originaldate: '2015-10-16',
script: 'Latn',
musicbrainz_albumid: '4f54e938-89b4-4ee8-b282-74964f1e23bb',
releasestatus: 'official',
acoustid_id: '5c94b20e-be79-4f6d-9800-d4caf8bc2a76',
catalognumber: 'DAGRON153',
musicbrainz_artistid: ['d8e73ae6-9884-4061-a056-c686b3375c9d'],
media: 'Digital Media',
releasetype: ['ep'],
originalyear: '2015',
musicbrainz_releasegroupid: '9c288627-be99-490e-9d3e-e6b135e9b8dd',
musicbrainz_recordingid: 'a1a9ede1-219b-464c-9520-d9fd1debf933',
artistsort: ['I Have a Tribe']
},
format: {
duration: 266.56,
numberOfChannels: 2,
bitsPerSample: 16,
tagType: 'vorbis',
sampleRate: 44100
},
vorbis: {
GROUPING: 'Rock',
COPYRIGHT: '2015 Grönland Records',
GENRE: ['Pop Rock'],
DESCRIPTION: ['Interprètes : I Have A Tribe, Main Artist; Patrick O\'Laoghaire, Composer, Lyricist; Copyright Control\r\nLabel : Grönland Records - GoodToGo\r\n'],
TITLE: 'Lungs',
RELEASECOUNTRY: 'DE',
TOTALDISCS: ['1'],
LABEL: 'Grönland Records',
TOTALTRACKS: ['5'],
MUSICBRAINZ_ALBUMARTISTID: ['d8e73ae6-9884-4061-a056-c686b3375c9d'],
DATE: '2015-10-16',
DISCNUMBER: '1',
TRACKTOTAL: '5',
MUSICBRAINZ_RELEASETRACKID: 'ed040a93-1f95-4f91-8c41-359f5a6e7770',
ALBUMARTISTSORT: ['I Have a Tribe'],
ORIGINALDATE: '2015-10-16',
SCRIPT: 'Latn',
MUSICBRAINZ_ALBUMID: '4f54e938-89b4-4ee8-b282-74964f1e23bb',
RELEASESTATUS: 'official',
ALBUMARTIST: ['I Have A Tribe'],
ACOUSTID_ID: '5c94b20e-be79-4f6d-9800-d4caf8bc2a76',
CATALOGNUMBER: 'DAGRON153',
ALBUM: 'No Countries',
MUSICBRAINZ_ARTISTID: ['d8e73ae6-9884-4061-a056-c686b3375c9d'],
MEDIA: 'Digital Media',
RELEASETYPE: ['ep'],
ORIGINALYEAR: '2015',
ARTIST: ['I Have A Tribe'],
DISCTOTAL: '1',
MUSICBRAINZ_RELEASEGROUPID: '9c288627-be99-490e-9d3e-e6b135e9b8dd',
MUSICBRAINZ_TRACKID: 'a1a9ede1-219b-464c-9520-d9fd1debf933',
ARTISTSORT: ['I Have a Tribe'],
ARTISTS: ['I Have A Tribe'],
TRACKNUMBER: '4',
METADATA_BLOCK_PICTURE: [
{
type: 'Cover (front)',
format: 'image/jpeg',
description: 'Official cover included in digital release',
width: 0,
height: 0,
colour_depth: 0,
indexed_color: 0,
data: {
type: 'Buffer',
data: ['...']
}
}
]
}
}
Note, the stream is not closed by default. To prevent leaks, you must close it yourself:
var readableStream = fs.createReadStream('sample.mp3');
var parser = mm(readableStream, function (err, metadata) {
if (err) throw err;
readableStream.close();
});
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);
});
You can also read the duration; to calculate the duration music-metadata
may need to parse the entire file
so only enable this if you need the functionality.
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, you must also 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 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.
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.