-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffprobe.js
40 lines (38 loc) · 1.33 KB
/
ffprobe.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
//Require all modules
require('dotenv').config();
var http = require('http');
var formidable = require('formidable');
var ffprobe = require('ffprobe');
var ffprobeStatic = require('ffprobe-static');
//Initiate the server
http.createServer(function (req, res) {
//Check route
if (req.url == '/ffprobe') {
//Get the incoming form (POST)
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
let filepath = files.targetfile.path;
//Log filepath for testing
console.log(filepath);
ffprobe(filepath, { path: ffprobeStatic.path })
.then(function (info) {
//Turn info-object (JSON) into string and display it
res.write(JSON.stringify(info));
res.end();
})
.catch(function (err) {
console.error(err);
})
});
} else {
//If not the response then give the form
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="ffprobe" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="targetfile"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}
}).listen(process.env.PORT);
//Let the user know where the test can be accessed from
console.log('Running Tradecast test on localhost:' + process.env.PORT);