Skip to content

Instantly share code, notes, and snippets.

@leetreveil
Created May 19, 2011 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leetreveil/981533 to your computer and use it in GitHub Desktop.
Save leetreveil/981533 to your computer and use it in GitHub Desktop.
node-musicmetadata folder scan
var fs = require('fs'),
walk = require('walk'),
path = require('path'),
mm = require('musicmetadata');
walker = walk.walk('/Users/leetreveil/Music/Mine', { followLinks : false });
walker.on('file', function(root, fileStats, next) {
if (/^.*\.(mp3|m4a|flac|ogg)/.test(fileStats.name)) {
var fullPath = path.join(root, fileStats.name);
//use 4kb bufferSize, most of metadata can be read in the first few 4kb reads
var stream = fs.createReadStream(fullPath, { bufferSize : 4 * 1024 });
var parser = new mm(stream);
parser.on('metadata', function(result) {
console.log(result);
});
parser.on('done', function(err) {
if (err) throw err;
//kill the stream as soon as the done event has been raised (improves perf)
stream.destroy();
});
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment