code cleanup
This commit is contained in:
13
main.ts
13
main.ts
@@ -220,33 +220,28 @@ class DownloadQueue {
|
||||
|
||||
public enqueue(url: string, folder: string, filename: string) {
|
||||
this.queue.push({ url, folder, filename });
|
||||
// Only process the queue if we're not at max capacity
|
||||
this.processQueue();
|
||||
}
|
||||
|
||||
private async processQueue(): Promise<void> {
|
||||
// Keep processing while we have capacity and items in the queue
|
||||
while (this.activeDownloads < this.maxConcurrency && this.queue.length > 0) {
|
||||
const { url, folder, filename } = this.queue.shift()!;
|
||||
this.activeDownloads++;
|
||||
|
||||
// Process the download asynchronously but continue the loop immediately
|
||||
// to potentially start more downloads if there's capacity
|
||||
this.processDownload(url, folder, filename).then(() => {
|
||||
// After download is complete, decrease activeDownloads and continue processing
|
||||
this.activeDownloads--;
|
||||
this.processQueue(); // Process next item in queue
|
||||
this.processQueue();
|
||||
}).catch((error) => {
|
||||
console.error('Error downloading song:', error);
|
||||
this.activeDownloads--;
|
||||
this.processQueue(); // Continue processing queue even if there's an error
|
||||
this.processQueue();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async processDownload(url: string, folder: string, filename: string): Promise<void> {
|
||||
await downloadSong(url, folder, filename);
|
||||
songCount++; // Increment the song count after successful download
|
||||
songCount++;
|
||||
console.log(`${songCount} songs downloaded successfully \n${this.queue.length} remaining`);
|
||||
}
|
||||
}
|
||||
@@ -281,7 +276,7 @@ for (const mentalState of mentalStates) {
|
||||
// Phase 2 : Download songs to device
|
||||
//
|
||||
|
||||
console.log(chalk.green(`Started downloading ${genre} ${mentalState}`))
|
||||
console.log(chalk.green(`Started queuing ${genre} ${mentalState}`))
|
||||
for (const song of data) {
|
||||
let activity = song.track.tags.filter((x: any) => x.type == 'activity').map((x: any) => x.value).join('/');
|
||||
let NEL = song.trackVariation.neuralEffectLevel;
|
||||
|
||||
Reference in New Issue
Block a user