-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
74 lines (66 loc) · 1.64 KB
/
demo.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var net = require('net');
var fs = require('fs');
var HOST = '127.0.0.1';
//var HOST = '192.168.59.103';
if(process.argv.length < 3) {
console.log("Needs song name as an argument");
process.exit(1);
}
var PORT;
var ext = process.argv[3] || 'mp3';
if (ext==='mp3') {
PORT = 8000;
}
else if (ext==='flac') {
PORT = 8001;
}
else {
ext = 'wav';
PORT = 8002;
}
//PORT = 8003;
//ext = 'txt';
fileStream = fs.createReadStream(process.argv[2]);
outputFilename = "output.wav";
//data = '';
//client = new net.Socket();
//
//var endBuffer = new Buffer(0);
//var errorString = 'PROCESS_ERROR';
//var errorBuffer = JSON.stringify(new Buffer(errorString).toJSON());
//
//client.connect(PORT, HOST, function() {
// fileStream.pipe(client).pipe(writeStream);
// client.on('error', function() {
// console.log('Client stream errored.');
// });
// client.on('data', function(chunk) {
// endBuffer = Buffer.concat([endBuffer, chunk]);
// if(endBuffer.length > errorString.length) {
// endBuffer = endBuffer.slice(endBuffer.length-errorString.length)
// }
// });
// client.on('close', function() {
// console.log('client closed');
// if(errorBuffer === JSON.stringify(endBuffer.toJSON())) {
// console.log('Process failed.')
// }
// });
//});
var request = require('request');
var url = 'http://'+HOST+':'+8010+'/wav-to-mp3';
var req = request.post({
url: url,
formData: {
'file': fileStream
}
});
req.on('response', function(response) {
if(response.statusCode === 200) {
var writeStream = fs.createWriteStream(outputFilename);
req.pipe(writeStream);
}
else {
console.log('failed?', response.statusCode);
}
});