-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
27 lines (24 loc) · 935 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 fs = require('fs');
const yts = require('yt-search');
const ffmpeg = require('fluent-ffmpeg');
const { exec } = require('child_process');
var content = ``;
const music = fs.readdirSync('./music').filter(file => file.endsWith('.mp3'));
const html = fs.readFileSync('./index.html');
music.forEach(async (file) => {
try {
const video = await yts(file.slice(0, -4));
const stream = ytdl(video?.all[0].url, { filter: 'audioonly' });
content += `<audio controls src="./music/${file}"></audio>`;
fs.writeFileSync("./index.html", content)
const stats = fs.statSync(`./music/${file}`);
const fileSizeInBytes = stats.size;
const size = fileSizeInBytes / (1024*1024);
if(size > 1) return;
ffmpeg(stream)
.audioBitrate(128)
.format('mp3')
.save(fs.createWriteStream(`./music/${file}`, { flags: 'a' }));
}catch(e) {console.log(e)}
})