-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 1021 Bytes
/
index.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
const program = require('commander');
var fs = require('fs');
let MediaSplit = require('media-split');
const downloadsFolder = require('downloads-folder');
program
.option('-v, --video <url>', 'Url for YouTube video.')
.option('-t, --timestamps <timestamps>', 'Path to text file with timestamps to split mp3 by (name it [time.txt]).');
program.parse(process.argv);
const options = program.opts();
if (options.video && options.timestamps) {
fs.readFile(options.timestamps, 'utf8', (err, data) => {
if (err) throw err;
let songs = data.split("\n");
for (let i = 0; i < songs.length; i++) {
songs[i] = "[" + songs[i];
songs[i] = songs[i].replace(" -", "]");
}
let split = new MediaSplit({
input: options.video,
output: downloadsFolder(),
downloadCover: false,
quality: "highestaudio",
sections: songs
});
console.log("Starting to split mp3 file.")
split.parse()
.then((sections) => {
console.log("Complete!")
});
});
}