Last active
August 12, 2019 13:01
-
-
Save viatsko/ea89bcc3ab6195de32ed to your computer and use it in GitHub Desktop.
djs
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 waveform = require('waveform'); | |
var fs = require('fs'); | |
var probe = require('node-ffprobe'); | |
var _ = require('lodash'); | |
var async = require('async'); | |
var walk = require('walk'); | |
var files = []; | |
// Walker options | |
var walker = walk.walk('/home/www/dj/www/mp3', { followLinks: false }); | |
walker.on('file', function(root, stat, next) { | |
// Add this file to the list of files | |
if(stat.name.match(/\.mp3$/)) files.push(root + '/' + stat.name); | |
next(); | |
}); | |
walker.on('end', function() { | |
console.log(files); | |
async.each(files, function(track, callback) { | |
probe(track, function(err, probeData) { | |
fs.writeFile(track + ".probe.json", JSON.stringify(probeData)); | |
}); | |
console.log('done probe ' + track); | |
waveform(track, { | |
// options | |
'scan': false, // whether to do a pass to detect duration | |
// waveform.js options | |
waveformjs: track + ".wave.json", // path to output-file or - for stdout | |
'wjs-width': 800, // width in samples | |
'wjs-precision': 4, // how many digits of precision | |
'wjs-plain': false // exclude metadata in output JSON (default off) | |
}, function(err, stdout) { | |
console.log('done wave ' + track); | |
callback(); | |
}); | |
}); | |
}); | |
// and fixed node_modules/waveform/index.js | |
var path = require('path'); | |
var execFileSync = require('child_process').execFileSync; | |
var waveformBin = path.resolve(__dirname, "build", "Release", "waveform"); | |
var flagNames = { | |
'scan': true, | |
'wjs-plain': true, | |
}; | |
module.exports = function(audiofile, options, callback) { | |
var cmdline = [audiofile]; | |
for (var optName in options) { | |
if (flagNames[optName]) { | |
cmdline.push('--' + optName); | |
} else { | |
var value = options[optName]; | |
cmdline.push('--' + optName); | |
cmdline.push(value); | |
} | |
} | |
callback(null, execFileSync(waveformBin, cmdline)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment