Created
May 19, 2011 19:32
-
-
Save leetreveil/981533 to your computer and use it in GitHub Desktop.
node-musicmetadata folder scan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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