read id3 tags from mp3 using javascript

I know this has been asked here before but my conditions are a little different. I am making a chrome app so i have access to all the latest JavaScript file apis it supports without worrying about compatibility. More over i would really like to do this my self.. ie without any library. A tutorial or a guide will do. After all how difficult can it really be?

Basically i have mp3's that user adds and i want to be able to read most basic information like artist and Album (actually, just these two but others wont do any harm).

I believe i have the idea of what id3 tag is and how can the info be read. I just have to see it in action just once. Thanks

Answers:

Answer

There's no need to use binaryajax.js or id3 parser lib anymore. In Chrome at, you can use FileReader and DataView to read and extract the ID3v1 info. It's just a few lines:

http://ericbidelman.tumblr.com/post/8343485440/reading-mp3-id3-tags-in-javascript

Answer

This library has good docs. I love GitHub

https://github.com/leetreveil/node-musicmetadata


API

var fs = require('fs');
var mm = require('musicmetadata');

//create a new parser from a node ReadStream
var parser = new mm(fs.createReadStream('sample.mp3'));

//listen for the metadata event
parser.on('metadata', function (result) {
  console.log(result);
});

This will output the standard music metadata:

{ artist : ['Spor'],
  album : 'Nightlife, Vol 5.',
  albumartist : [ 'Andy C', 'Spor' ],
  title : 'Stronger',
  year : '2010',
  track : { no : 1, of : 44 },
  disk : { no : 1, of : 2 },
  picture : [ { format : 'jpg', data : <Buffer> } ]
}
Answer

As @joekarl has pointed out, there are libraries to do this for you. I saw your request for info so you can do it yourself, but here's a gem from the 500+ or so lines from the library on nihilogic.dk:

var iLong = bBigEndian ? 
            (((((iByte1 << 8) + iByte2) << 8) + iByte3) << 8) + iByte4
            : (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1;
        if (iLong < 0) iLong += 4294967296;
        return iLong;

Not to mention a significant amount of pure Javascript AJAX work.

There's no reason to reinvent this wheel. However, if you want to look at the code and rewrite it for whatever reason, here are the two libraries files:

binary ajax library
id3 parser

If you really want to cut out any of the AJAX and just start with reading a file you already have (somehow, without AJAX), the second link has a function called, coincidentally, readTagsFromData. I suggest you start there for your goals.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.