-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertVideoToAudio.js
More file actions
24 lines (22 loc) · 915 Bytes
/
Copy pathconvertVideoToAudio.js
File metadata and controls
24 lines (22 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const fs = require("fs");
const ytdl = require("ytdl-core");
const ffmpeg = require("fluent-ffmpeg");
function convertVideoToAudio(url, filename, chatId, bot) {
return new Promise((resolve, reject) => {
console.log("Downloading video...");
bot.sendMessage(chatId, "Downloading video...");
ytdl(url, { quality: "highestaudio" })
.pipe(fs.createWriteStream(`./downloads/${filename}.mp4`))
.on("finish", () => {
console.log("Converting to mp3...");
bot.sendMessage(chatId, "Converting to mp3...");
new ffmpeg({ source: `./downloads/${filename}.mp4`, nolog: true })
.toFormat("mp3")
.on("end", () => resolve())
.on("error", err => reject(err))
.saveToFile(`./downloads/${filename}.mp3`);
})
.on("error", error => console.error(error));
}).catch(err => console.error(err));
}
module.exports = convertVideoToAudio;