GithubHelp home page GithubHelp logo

leetreveil / musicmetadata Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aadsm/node-id3

558.0 14.0 66.0 65.83 MB

Streaming music metadata parser for node and the browser.

JavaScript 98.11% HTML 1.89%

musicmetadata's Introduction

Build Status NPM version npm downloads

Streaming music metadata parser for node and the browser.

Installation

Install via npm:

npm install musicmetadata

You can also download a pre packaged browser release from dist/musicmetadata.js. See example/index.html for usage.

Supports

  • mp3 (1.1, 2.2, 2.3, 2.4)
  • m4a (mp4)
  • vorbis (ogg, flac)
  • asf (wma, wmv)

API

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

// create a new parser from a node ReadStream
var parser = mm(fs.createReadStream('sample.mp3'), function (err, metadata) {
  if (err) throw err;
  console.log(metadata);
});

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 },
  genre : ['Drum & Bass'],
  picture : [ { format : 'jpg', data : <Buffer> } ],
  duration : 302.41 // in seconds
}

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();
});

musicmetadata 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 musicmetadata 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) {

});

Licence

(The MIT License)

Copyright (c) 2016 Lee Treveil [email protected]

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.

musicmetadata's People

Contributors

andrewrk avatar bahamas10 avatar benkaiser avatar borewit avatar cobalamin avatar danielearwicker avatar dertseha avatar jpage-godaddy avatar leetreveil avatar mutewinter avatar ondras avatar pmarques avatar rodu avatar tim-smart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

musicmetadata's Issues

Write feature

Hi! Would you add wirte id3 info to mp3 feature to this project in future. I'd love to use it in my project.

Issues with .m4a's

I've got a set of m4a files that I can view the metadata perfectly fine with mp3tag, but I don't get anything from musicmetadata:

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

var dir = '/Users/wangstabill/Music/Katatonia\ -\ Dead\ End\ Kings/';
var files = fs.readdirSync(dir);

files.forEach(function (file) {
  var parser = new musicmetadata(fs.createReadStream(dir + file));
  parser.on('metadata', function (result) {
    console.log(result);
  });
});

gives:

{ title: '',
  artist: [],
  albumartist: [],
  album: '',
  year: 0,
  track: { no: 0, of: 0 },
  genre: [],
  disk: { no: 0, of: 0 },
  picture: {} }
{ title: '',
  artist: [],
  albumartist: [],
  album: '',
  year: 0,
  track: { no: 0, of: 0 },
  genre: [],
  disk: { no: 0, of: 0 },
  picture: {} }
etc...

The metadata event is firing the correct number of times, but the result argument object doesn't have values. I'm using musicmetadata v0.1.9. I'd also be happy to email the offending files.

track no 8 and 9 show up as 0 for flac files

certain flac tracks of mine report track no 0, if their track numbers are 8 or 9.

I suspect there is some octal conversion happening... but i haven't dug through the source yet.

In the output below, tracks 8 and 9 report a trackno of 0. this CD was ripped using soundjuicer on Ubuntu 12.04.. this has happened for other songs as well.

dave @ [ lifeforce :: (Linux) ] ~/dev/node-musicnamer $ ./bin/musicnamer.js --tags ../../Desktop/As\ I\ Lay\ Dying/Awakened/*

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 10 - My Only Home.flac -----

{ title: 'My Only Home',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 10, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 11 - Tear Out My Eyes.flac -----

{ title: 'Tear Out My Eyes',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012',
  track: { no: 11, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 1 - Cauterize.flac -----

{ title: 'Cauterize',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012',
  track: { no: 1, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 2 - A Greater Foundation.flac -----

{ title: 'A Greater Foundation',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 2, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 3 - Resilience.flac -----

{ title: 'Resilience',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 3, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 4 - Wasted Words.flac -----

{ title: 'Wasted Words',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012',
  track: { no: 4, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 5 - Whispering Silence.flac -----

{ title: 'Whispering Silence',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 5, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 6 - Overcome.flac -----

{ title: 'Overcome',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 6, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 7 - No Lungs to Breathe.flac -----

{ title: 'No Lungs to Breathe',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 7, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 9 - Washed Away.flac -----

{ title: 'Washed Away',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012-09-25',
  track: { no: 0, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

----- processing ../../Desktop/As I Lay Dying/Awakened/Disc 1 - 8 - Defender.flac -----

{ title: 'Defender',
  artist: [ 'As I Lay Dying' ],
  albumartist: [ 'As I Lay Dying' ],
  album: 'Awakened',
  year: '2012',
  track: { no: 0, of: 11 },
  genre: [],
  disk: { no: 1, of: 0 },
  picture: 
   [ { format: 'jpg',
       data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff e1 00 fa 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 06 01 1a 00 05 00 00 00 01 00 00 00 ...> } ] }

EventEmitter memory leak

How would one get around this issue?

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at [object Object]. (events.js:123:17)
at [object Object]. (.../node_modules/musicmetadata/lib/id3v1.js:14:16)
at [object Object].emit (events.js:64:17)
at [object Object]._emitData (fs.js:915:10)
at afterRead (fs.js:897:10)
at wrapper (fs.js:245:17)

Write metadata back to file

This really isn't an issue, but I was wondering if you ever considered writing updated metadata back to the file. If you haven't, would you happen to know of a pure node.js library that does this?

duration of mp3 file = 0 ?

Hello,
when I get the info from an mp3 the duration is 0 ?
Do I have to manually add the duration to the mp3 ?

leaked global variable: bigEndian

Was running my mocha tests after adding some usage of this module and mocha reported me this error:

Error: global leak detected: bigEndian

I grepped sources and found it indeed :) It's in common.js and even looks unused.
Is it ok to remove it perhaps? Or at least add 'var'?

Event on('metadata') is fired twice in 0.3.1

After hours and hours of pulling my hair, thinking there was something wrong with another library I am using, or perhaps a bug in fs.createReadableStream it turns out the latest version of musicmetadata has a bug.

I rolled back to v0.3.0 and metadata event is fired once as it supposed to.

Now as you can imagine firing this event twice was causing problems with async library calling callback(null, meta) twice which would throw an error, and in other case it would try to create database element twice and fail because of duplicate SQL entry.

can't get a valid picture url on nodejs

Hey there.

I'm trying to get the picture from an mp3, but I can't can't get it working.

Getting title, album, artist and so on works great, but the picture doesn't show up correctly. I'm just getting the default missing image picture. The picture.data seems to contain enough data, so I assume I'm just displaying it wrong.
I'm following this example here, but I'm using nodejs.

        // create a new parser from a node ReadStream
        var stream = fs.createReadStream(song.path);
        var parser = musicmetadata(stream);

        // listen for the metadata event
        parser.on('metadata', function(result) {
            if (result.picture.length > 0) {
                var picture = result.picture[0];
                img.src = URL.createObjectURL(new Blob([picture.data], {'type': 'image/' + picture.format}));
            }
        });

What am I doing wrong?
Thanks!

Unable to read tags from an specific ogg file

Hi, node-musicmetadata seems to be unable to read the tags from the following ogg file:
http://topaxi.ch/Modestep_-_To_The_Stars_Break_The_Noize_The_Autobots_Remix.ogg

  if (start > end) throw new Error('oob');
                   ^
Error: oob
    at Buffer.slice (buffer.js:517:26)
    at [object Object].get (/home/topaxi/node-music/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:239:20)
    at /home/topaxi/node-music/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:339:28
    at [object Object].<anonymous> (/home/topaxi/node-music/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:366:9)
    at [object Object].emit (events.js:67:17)
    at [object Object]._emitData (fs.js:1150:10)
    at afterRead (fs.js:1132:10)
    at Object.wrapper [as oncomplete] (fs.js:254:17)

Duration of FLAC/WMA tracks is always 0

I have noticed that when I try to fetch the 'duration' metadata using:

mm(fs.createReadStream(file), {duration: true});

that I always seem to get a 0 duration returned for FLAC and WMA files. I have resorted to using node-taglib in these instances but I also rely on the album art features that musicmetadata supports. I'd prefer to only have one tag parsing library as a dependency so if there's any info you could provide that would be awesome.

Other language support?

I was testing this on japanese songs and it returns squares instead of japanese characters in the tags. Mind adding support for other languages, such as Japanese and Korean characters?

Thank you in advance.

Duration for fixed bit-rate incorrect

Currently, the id3v2 parser, after deciding that an MP3 is fixed-bitrate, it divides the size of the entire file by the kbps. This is leading to inaccurate durations, which are especially pronounced if the ID3 frames contain a lot of data, as with APIC frames.

Hanging on certain mp3

Great library, but I've found some files that it hangs hard on (tried timeout to continue to next file, but hangs such that timeout callback isn't called).

I've put together a reproduction of the bug at https://github.com/stelleg/musicmetadata-bug

Sorry I can't be more helpful, but tried debugging with node inspector to no avail (once it hangs inspector is useless).

Thanks!

Error: EventEmitter has no method `onAny`.

I'm running Node 0.10.7 and am getting the following error when listening to any event:

 /path/to/musicmetadata/lib/musicmetadata.js:32
    parser.onAny(eventHandler(self));
           ^
TypeError: Object #<EventEmitter> has no method 'onAny'
    at ReadStream.<anonymous> (/path/to/musicmetadata/lib/musicmetadata.js:32:12)
    at ReadStream.g (events.js:175:14)
    at ReadStream.EventEmitter.emit (events.js:95:17)
    at ReadStream.<anonymous> (_stream_readable.js:736:14)
    at ReadStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at ReadStream.Readable.push (_stream_readable.js:127:10)
    at onread (fs.js:1561:12)

For example, parser.on('metadata', handler) triggers it.

I've checked the code and the only place it's referenced is lib/musicmetadata.js:32. I haven't delved too far into the depths of the library and haven't had time to check any version constraints that may be causing it.

Thanks.

update README with new metadata format

Example: artist and albumartist are now arrays

{ title: '',
  artist: [],
  albumartist: [],
  album: '',
  year: 0,
  track: { no: 0, of: 0 },
  genre: [ '' ],
  disk: { no: 0, of: 0 },
  picture: {} }

Feel free to add me as a collaborator and I'll do minor stuff like this for you, and still make pull requests for bigger stuff.

"tag" event

Use case: list all the metadata tags and values in a file.

(certainly) bad id3 leads to the "metadata" event to be called lots of times

Hello,

I'm in trouble with some mp3, the "metadata" and "done" events are called a lot of time, and this of course breaks my app...
Using node.js 0.6.3 and musicmetadata 0.1.3 .

Here is my test code :

var m = require("musicmetadata");
var fs = require("fs");

var parser = new m(fs.createReadStream(process.argv[2]));

parser.on('metadata', function(result) {
  console.log("metadata");
  console.log(result);
});

parser.on('done', function(err) {
  console.log("done");
  if (err) console.log(err);   
});

The x-1 times the "done" event error is [Error: Expected id3v1.1 header but was not found.] and the last time the "done" event error is [TypeError: Cannot call method 'trim' of undefined].

Note that the last time, the metadata array contains the good metadata !

How can I help you ? do you want me to send you an mp3 file having this problem, or do you have diagnostics tools I can use (I'm on Linux) to improve this bug report ?

Regards,

Mickael

Performance drop for OGG

As you switched to the binary module by substack, the performance of parsing OGG metadata dropped a lot

100 Files processed

0.1.5: ./import.js 8.75s user 0.82s system 89% cpu 10.724 total
0.1.6: ./import.js 47.18s user 1.38s system 99% cpu 48.751 total

I'm scanning through about 2500 files for now, reading all of them takes a lot of time (where the old version was much faster)... it's not an issue for me as i only read new files, but i thought you should know :)

How to extract the picture from the music file ?

I wrote this code to save the music's picture into a file:

var picturePath = 'picture.' + picture.format;
fs.open( picturePath, 'w', function( err, file ) {
    if ( !err )
    {
        fs.write(file, picture.data, 0, picture.data.length, null, function(err, written, buffer) {
            if (err)
            {
                console.log( err );
            }
            fs.close( file );
        });
    }
    else
    {
        console.log( err );
    }
});

No error has occured, the file was successfully created and it contained data but it was unreadable by all the picture viewers I've tested.
I used ID3 Editor to extract the picture from my mp3 and I got a readable picture with the exact same weight than the file I just created before. But when I compared the binary data of the two files, I saw that it was completely different.

So my question is: Is there something missing in my code to create my image file (like a conversion process of the data or whatever...) ? Or this is a real issue ?

Parsing metadata for non file streams

In our application, we are processing HTTP file upload streams through a pipeline of various intermediate streams; uploads are not saved to the file system. One thing we'd like to do is parse the metadata of audio files. As you are probably already aware, based on your TODO comments, this doesn't currently work because the code attempts a fs.stat on a non-existant stream.path property.

Is measuring the length of the stream the only purpose of this call? If this is the only reason why only file streams are supported, what do you think about using the length-stream module instead? That is a simple byte-counting pass-through stream. Perhaps fs.stat can continue to be used if the stream has a path property, and length-stream otherwise?

I'm happy to send a pull request with this change, but wanted to check if you'd be OK with this approach or if you have something better in mind.

Invalid buffer data

Hello again. Do you mind checking these song files? They return a picture data however when I make an image out of them I get trash images. I've tested on other albums my code is working fine.

Song1 and Song2.

Thank you very much.

discussion: monkey patching

Monkey patching is generally considered unsafe, for example:
https://github.com/leetreveil/node-musicmetadata/blob/master/lib/common.js#L23

In my opinion monkey patching should generally be avoided. Here are wikipedia's reasons why.

You can still accomplish the same thing with a different syntax, for example, common.onRealEnd(stream, cb).

Also this module adds things to the strtok namespace. In order to be careful not to clobber or be clobbered, these things should be in musicmetadata's own namespace.

Id3v1.1 header but was not found.

Error: Expected id3v1.1 header but was not found.
at parse (/root/gruya/src_staging/gruya/node_modules/musicmetadata/lib/id3v1.js:29:15)
at Id3v1.parse.offset (/root/gruya/src_staging/gruya/node_modules/musicmetadata/lib/id3v1.js:19:5)
at stream.Stream.onRealEnd.on.called (/root/gruya/src_staging/gruya/node_modules/musicmetadata/lib/common.js:27:18)
at EventEmitter.emit (events.js:93:17)
at afterRead (fs.js:1330:12)
at Object.wrapper as oncomplete

I am having the following error when processing some mp3, where may be the problem?

The file id3v1.js
if (header !== 'TAG')
error occurs when the TAG is pag

Last metadata block of flac files is ignored

flac decoding emits "done" when encountering the header of the last data block - not after processing it, thus skipping some info.

For a test, I've commented out the if at lines 38+ and modified the return after handling the data block to read:

        if (cb.blockHeader.last_metadata_block) {
          self.emit('done');
          return strtok.DONE;
        } else {
          cb.position = 'METADATA_BLOCK_HEADER';
          return new strtok.BufferType(4);
        }

and worked for me.

The tests take huge space

I am on a slow internet, and the mp3 files in the test folder takes too much space for a such tiny module

this mp3 causes a crash

http://superjoe.s3.amazonaws.com/temp/node-musicmetadata-broken.mp3

/home/andy/tmp/npmtest/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:290
            assert.ok(bufOffset >= 0 && bufOffset < b.length);
                                                     ^
TypeError: Cannot read property 'length' of undefined
    at emitData (/home/andy/tmp/npmtest/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:290:54)
    at ReadStream.dataListener (/home/andy/tmp/npmtest/node_modules/musicmetadata/node_modules/strtok/lib/strtok.js:366:9)
    at ReadStream.EventEmitter.emit (events.js:95:17)
    at ReadStream.<anonymous> (_stream_readable.js:736:14)
    at ReadStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at ReadStream.Readable.push (_stream_readable.js:127:10)
    at onread (fs.js:1561:12)

I'll look into making a test case and and a fix.

lib/index.js:cleanupPicture :: Return type and description of image

Hi

The code in the lib/id3v2_frames.js reads type and description no problem, but then it is discarded when returning 'metadata' event.

As a developer, does this mean that the intended behaviour is to setup separate event for 'APIC' tag itself, and then to merge it back to metadata?

Kind regards

Use 'proper' inheritance from EventEmitter

I was using the library for many files and encountered the same problem as in #1 as well as spurious events from other objects. Looking at the code, I found out that the EventEmitter is new'd up for the prototypes.

As per Node 0.10.0, this is now a problem. See here: https://github.com/joyent/node/wiki/Api-changes-between-v0.8-and-v0.10 (Look for paragraph starting with "The EventEmitter constructor initializes various properties now.")

I've changed the code to use util.inherits() for at least MusicMetadata and Flac (I'm only using flac files) and all was solved.

year: inconsistent type

Here are some years I'm seeing:

  year: '2010',
  year: '1997',
  year: '1991',
  year: '2002',
  year: '2009',
  year: '2011',
  year: 0,
  year: 0,
  year: '2009',
  year: '2011-10-28T07:00:00Z',
  year: '2003',
  year: '1999',
  year: '2010',
  year: '2011',
  year: '2010',
  year: '2012',
  year: '2011',
  year: 0,
  year: 0,
  year: '2009',
  year: 0,

I think this should be always a string, or always a number.

Also is that '2011-10-28T07:00:00Z' correct? I can provide the mp3 if you want.

discussion: catchall try block

many of the parsers have a try/catch that is not meant to be used. In other words, the try/catch is trying to handle unexpected errors rather than an expected error condition.

is this true? or is there a good reason to have those try/catch blocks there?

In my opinion, a try catch should only exist if there are explicit conditions you wish to catch. Anything else we actually want to crash so that the error can be reported and fixed as soon as possible.

example: https://github.com/leetreveil/node-musicmetadata/blob/master/lib/id4.js#L7

musicmetadata breaks consistent behavior in stream object

Due to line 52 in index.js:
self.stream.emit('data', result);

We receive inconsistent behavior from the read stream. At the moment, I am piping the same stream to multiple other objects: crypto.createHash('md5'), s3 (from aws-sdk - AWS.S3)

So emitting the data event directly will cause an incorrect md5 to be calculated, and will undoubtedly upload a corrupt file to s3.

I have reviewed your code and due to how strtok2 works there really is no easy way around this issue, without most likely making some drastic changes. I would love your thoughts on this. Thank you for your time.

m4v support?

What a nice lib! Any chance m4v/mp4 support could be added? Trying to come up with a good way to get a hold of that metadata

Length

It is not necessarily included in the ID3 tags, but having the duration of a song would be really useful. Are there any plans to add duration detection? (my music player is coming along nicely and I would like to display a duration attribute on the list)

music-player

Uncaught ReferenceError: require is not defined

Hello,

I am exploring meteor.js and need to get some metadata from an mp3. I am using this code:

Template.id3.rendered = function() {
var fs = require('fs');
var mm = require('musicmetadata');

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

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

};

I am calling the Template to my main html page. But require is not defined. Any thoughts?

Thanks

Can't read .wav files

So I just converted an mp3 to wav, and the file now has no meta data associated with it?

$ ffmpeg -i ~/Downloads/while\ my\ guitar\ piano.mp3 ~/Downloads/while\ my\ guitar\ piano.wav

this m4a file yields no events or errors

File: http://superjoe.s3.amazonaws.com/temp/node-musicmetadata-broken.m4a

Test case:

var Mm = require('musicmetadata');
var fs = require('fs');
var thefile = "node-musicmetadata-broken.m4a"

var parser = new Mm(fs.createReadStream(thefile));
parser.on('metadata', function(metadata) {
  console.log("metadata", metadata);
});
parser.on('done', function(value) {
  console.log("done");
});

When this script is run, nothing is printed to stdout and no errors occur.

I'll see if I can fix it.

on('metadata') called twice in v0.4.0 if duration:true

For some files, the on('metadata') is called twice. When this happens, the on('done') throws [Error: expected frame header but was not found].

Turning off duration calculation fixes the issue but I would like to get the duration as well.

This happens for a song whose info looks like this...

screen shot 2014-07-10 at 8 42 47 pm

Parsing duration of VBR audio is painfully slow

See #40 . taglib was discussed, but I'm not sure if node gyp has support for installing dynamically linked libraries. The project also has a note about compiling it from source in order to have access to the async API. I've been using fluent-ffmpeg in the meantime, which has a significantly larger dependency (which I use anyways). new require('fluent-ffmpeg').Metadata('/path.mp3', function (metadata, err) {});.

proposal: event for identification of the type of stream

One of the things you might want to learn from this library is what type of file we are dealing with. One use case is to distinguish between audio files and non- audio files.

I propose an event like this:

parser.on('mimetype', function(mimetype) {
  console.log(mimetype);
});

This would print audio/mpeg for an mp3 file, audio/ogg for an ogg file, etc. It would only fire such events for file types that are recognized by musicmetadata (that is it has the ability to parse the tags of the file type).

@leetreveil are you on board with this?

parsing many files

@leetreveil , what are your thoughts on parsing large numbers of files? It seems in Node v0.10.0 that trying to do the following with node-musicmetadata:

arrayOfFileNames.forEach(function (filename) {
  var parser = new musicmetadata(fs.createReadStream(filename));
  parser.on('metadata', function (result) {
    // ...
  }
});

will log the follwing error in the console:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at EventEmitter.addListener (events.js:160:15)

I'll double check with Node v0.10.5, but what are your thoughts for processing many files? Maybe simply increasing the max listeners as the error message says?

Write Support

I am considering writing a music player based completely in node that runs through a browser (similar to Google Play Music, but for your own music collection, and open source). For this though I know I will need to store all the metadata in a db (and scan the collection at the start). However when a user changes the metadata, it would be good to write it back to the file, in case they wish to move to a different media player. Is it possible that this library could expand to support writing metadata?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.