-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·89 lines (79 loc) · 1.87 KB
/
app.js
File metadata and controls
executable file
·89 lines (79 loc) · 1.87 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const inquirer = require('inquirer');
const path = require('path');
const userHome = require('user-home');
const { exec } = require('child_process');
if (!fs.existsSync(process.argv[2])) {
console.log("Provided file doesn't exist");
process.exit();
}
var input_file = path.basename(process.argv[2]);
var loaded_bytes = "";
if (fs.existsSync(userHome + '/.aax-converter-config')) {
loaded_bytes = fs.readFileSync(userHome + '/.aax-converter-config', { encoding: 'utf8' });
};
var general_questions = [
{
type: "input",
name: "activation_bytes",
message: "Activation Bytes",
default: loaded_bytes
},
{
type: "list",
name: "format",
message: "Output Format",
choices: [
"mp3"
]
}
];
var mp3questions = [
{
type: "input",
name: "sample_rate",
message: "Sample Rate",
default: 44100
},
{
type: "input",
name: "bitrate",
message: "Bitrate (kbps)",
default: 320
}
];
inquirer.prompt(general_questions).then((answers) => {
fs.writeFileSync(userHome + '/.aax-converter-config', answers.activation_bytes, (err) => {
if (err) throw err;
});
var command = "ffmpeg -y";
command += " -activation_bytes " + answers.activation_bytes;
command += " -i " + input_file;
switch (answers.format) {
case "mp3":
inquirer.prompt(mp3questions).then((answers) => {
command += " -ar " + answers.sample_rate;
command += " -ac 2";
command += " -b:a " + answers.bitrate + "k";
command += " -vn";
command += " " + input_file.split('.')[0] + ".mp3";
console.log("Converting... (this may take some time)");
runCommand(command, () => {
console.log("Done!");
});
});
break;
default:
break;
}
});
function runCommand(cmd, cb) {
exec(cmd, (err, stdout, stderr) => {
if (err) { return; }
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
cb();
});
}