diff --git a/deemix/decryption.js b/deemix/decryption.js index 0d86867..c613f9d 100644 --- a/deemix/decryption.js +++ b/deemix/decryption.js @@ -63,22 +63,19 @@ async function streamTrack(outputStream, track, start=0, downloadObject, listene }else { console.log(`${itemName} downloading ${complete} bytes`) } - }).on("readable", ()=>{ - let chunk; - while ((chunk = response.read(2048 * 3))){ - chunkLength += chunk.length + }).on('data', function(chunk){ + chunkLength += chunk.length - if (downloadObject){ - let chunkProgres - if (downloadObject.__type__ === "Single"){ - chunkProgres = (chunkLength / (complete + start)) * 100 - downloadObject.progressNext = chunkProgres - }else{ - chunkProgres = (chunk.length / (complete + start)) / downloadObject.size * 100 - downloadObject.progressNext += chunkProgres - } - downloadObject.updateProgress(listener) + if (downloadObject){ + let chunkProgres + if (downloadObject.__type__ === "Single"){ + chunkProgres = (chunkLength / (complete + start)) * 100 + downloadObject.progressNext = chunkProgres + }else{ + chunkProgres = (chunk.length / (complete + start)) / downloadObject.size * 100 + downloadObject.progressNext += chunkProgres } + downloadObject.updateProgress(listener) } }) diff --git a/deemix/downloader.js b/deemix/downloader.js index 20f2efe..f99c38c 100644 --- a/deemix/downloader.js +++ b/deemix/downloader.js @@ -148,11 +148,11 @@ class Downloader { this.downloadObject.collection.tracks_gw.forEach((track, pos) => { q.push({track, pos}) }) - + await q.drain() } - if (this.listener) this.listener.send("finishedDownload", this.downloadObject.uuid) + if (this.listener) this.listener.send("finishDownload", this.downloadObject.uuid) } async download(extraData, track){ @@ -265,6 +265,15 @@ class Downloader { } else if (extension == '.flac'){ tagFLAC(writepath, track, this.settings.tags) } + this.downloadObject.downloadObject += 1 + this.downloadObject.files.push(String(writepath)) + if (this.listener) + this.listener.send('updateQueue', { + uuid: this.downloadObject.uuid, + downloaded: true, + downloadPath: String(writepath), + extrasPath: String(this.extrasPath) + }) return {} } diff --git a/deemix/types/DownloadObjects.js b/deemix/types/DownloadObjects.js index 4c1afbb..f0f9091 100644 --- a/deemix/types/DownloadObjects.js +++ b/deemix/types/DownloadObjects.js @@ -75,7 +75,7 @@ class IDownloadObject{ updateProgress(listener){ if (Math.round(this.progressNext) != this.progress && Math.round(this.progressNext) % 2 == 0){ this.progress = Math.round(this.progressNext) - if (listener) listener.emit('updateQueue', {uuid: this.uuid, progress: this.progress}) + if (listener) listener.send('updateQueue', {uuid: this.uuid, progress: this.progress}) } }