-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (22 loc) · 796 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
const ytdl = require("ytdl-core");
const sanitize = require("sanitize-filename");
const fs = require("fs");
const ffmpeg = require('fluent-ffmpeg');
// Open fs, read each line, download each line
async function download(video) {
if(!ytdl.validateURL(video)) {
console.log(`Invalid video: ${video}`);
return;
}
const info = await ytdl.getInfo(video);
console.log(`Downloading ${info.title}`);
const stream = ytdl(video, {quality: 'highestaudio', filter: 'audioonly'});
ffmpeg(stream)
.audioBitrate(320)
.save(`${sanitize(info.title)}.mp3`)
.on('end', () => console.log(`Downloaded ${info.title}`));
}
const data = fs.readFileSync(fs.openSync("files.json", "r"));
for(const video of JSON.parse(data)) {
void download(video);
}