const { createWriteStream } = require('fs');
const { Bar } = require('cli-progress');
const ytdl = require('ytdl-core');
const ffmpeg = require('fluent-ffmpeg');
async function downloadAudio(url, filename, format)
let downloadPath = '/storage/emulated/0/Download/';
const fullPath = downloadPath + filename;
const progressBarFormat = `{bar} {percentage}% | ETA: {eta}s | Загрузка`;
if (url.includes('youtube.com')) {
const video = ytdl(url);
const progressBar = new Bar({}, { format: progressBarFormat });
progressBar.start(100, 0);
const audio = ffmpeg(video)
.format(format)
.on('progress', (progress) => {
const percentage = progress.percent * 0.01;
const value = percentage * 100;
progressBar.update(value);
})
.on('error', (error) => {
console.error(error);
});
audio.pipe(createWriteStream(fullPath));
await new Promise((resolve, reject) => {
audio.on('end', () => {
progressBar.stop();
console.log(`Аудиофайл успешно загружен в ${downloadPath}!`);
resolve();
});
});
} else if (url.includes('music.youtube.com')) {
const { videoDetails } = await ytdl.getInfo(url);
const stream = ytdl.downloadFromInfo(videoDetails, { filter: 'audioonly' });
const progressBar = new Bar({}, { format: progressBarFormat });
progressBar.start(100, 0);
stream.on('progress', (chunkLength, downloaded, total) => {
const percentage = downloaded / total;
const value = percentage * 100;
progressBar.update(value);
});
stream.pipe(createWriteStream(fullPath));
await new Promise((resolve, reject) => {
stream.on('end', () => {
progressBar.stop();
console.log(`Аудиофайл успешно загружен в ${downloadPath}!`)
)};
};
};
module.exports(download
```Audio);
#I don't understand how to solve this problem
3 messages · Page 1 of 1 (latest)
You didn't open the brackets for the function
- async function downloadAudio(url, filename, format)
+ async function downloadAudio(url, filename, format) {