Converted over to TS

This commit is contained in:
2025-10-22 11:48:36 +02:00
parent 8c7ec8e968
commit 27a4043095
9 changed files with 364 additions and 71 deletions

25
downloadSong.ts Normal file
View File

@@ -0,0 +1,25 @@
import * as https from 'https';
import * as fs from 'fs';
async function downloadSong(downloadLink: string, folder: string, filename: string, songCount: number): Promise<void> {
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: Error) => {
console.error('Error downloading song:', error);
reject(error);
});
});
});
}
process.on('message', async (message: any) => {
const { downloadLink, folder, filename, songCount } = message;
await downloadSong(downloadLink, folder, filename, songCount);
process.send && process.send(`Song #${songCount} downloaded successfully`);
});