forked from UWCS/music-server-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrackdata.js
31 lines (25 loc) · 912 Bytes
/
trackdata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/local/bin/node
var sys = require('sys');
var fs = require('fs');
var exec = require('child_process').exec;
exports.getInfo = function(path, callback){
exec("mplayer -frames 0 "+path, function (error, stdout, stderr) { //Mplayer the file and stop it, collect data from stdout
if (error) {
sys.puts("Error: "+error);
}
else {
var get = { "track": /(Title|Song|Name): (.*)/i, //Regex the stdout to find track data
"artist": /(Singer|Band|Artist|Author): (.*)/i, //The /i is necessary for case-insensitivity.
"album": /(Disc|Album|CD): (.*)/i,
"year": /(Year|Release): (.*)/i
};
var data = {};
for (var i in get) {
if (get[i].exec(stdout) !== null) { //If data exists for the field
data[i] = get[i].exec(stdout)[2]; //Add it to the array
}
}
callback(data); //Run the callback function on the array.
}
});
}