first commit
This commit is contained in:
25
downloadSong.js
Normal file
25
downloadSong.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import https from 'https';
|
||||
import fs from 'fs';
|
||||
|
||||
async function downloadSong(downloadLink, folder, filename, songCount) {
|
||||
console.log(`Downloading song #${songCount} ...`)
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get(downloadLink, (response) => {
|
||||
response.pipe(fs.createWriteStream(`${folder}/${filename}.mp3`))
|
||||
.on('finish', () => {
|
||||
console.log(`${songCount} songs downloaded successfully`);
|
||||
resolve();
|
||||
})
|
||||
.on('error', (error) => {
|
||||
console.error('Error downloading song:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
process.on('message', async (message) => {
|
||||
const { downloadLink, folder, filename, songCount } = message;
|
||||
await downloadSong(downloadLink, folder, filename, songCount);
|
||||
process.send(`Song #${songCount} downloaded successfully`);
|
||||
});
|
||||
Reference in New Issue
Block a user