Created
July 26, 2010 18:20
-
-
Save bryanwb/490973 to your computer and use it in GitHub Desktop.
This file contains 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
//usage: $ node wav2mp3.js file1.wav file2.wav | |
// converts to .mp3 format and deletes original .wav file | |
// thanks to creationix for his assistance | |
var fs = require('fs'); | |
var sys = require('sys'); | |
var Step = require('step'); | |
var spawn = require('child_process').spawn; | |
var exec = require('child_process').exec; | |
var counter = 0; | |
Step( | |
function doConversions() { | |
var group = this.group(); | |
process.argv.splice(2).forEach(function(arg){ | |
convert(arg, group()); | |
counter++; | |
}); | |
}, | |
function printResults(){ | |
sys.puts("" + counter + " files converted to mp3"); | |
} | |
); | |
function convert(file, callback){ | |
if (file.slice(-4) === ".mp3"){ | |
sys.puts('file ' + file + ' already converted '); | |
} else { | |
Step( | |
function checkFile(){ | |
fs.stat(file, this); | |
}, | |
function convertFile(err){ | |
if(err) { | |
sys.print(err.message) | |
} else { | |
var conversion = exec('soundconverter -b -m ' + | |
'audio/mpeg -s .mp3 ' + file, this); | |
} | |
}, | |
function deleteOriginal(err){ | |
if(err){ | |
sys.print(err.message) | |
} else { | |
exec('rm -f ' + file, this); | |
} | |
}, | |
callback | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment