From 21848502be0a0e923470f2ce5679fe6759b7b8a1 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 4 Aug 2017 23:40:30 -0300 Subject: Ah, progress --- src/loop-play.js | 51 ++++++++++++++++++++++++++------------------------- src/play.js | 3 +-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/loop-play.js b/src/loop-play.js index 5690f9b..4ea73c7 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -91,43 +91,44 @@ class PlayController { this.playerCommand = null this.currentTrack = null this.process = null + this.downloadProcess = null } async loopPlay() { - let nextFile - // Null would imply there's NO up-next track, but really we just haven't // set it yet. this.nextTrack = undefined - const downloadNext = async () => { - this.nextTrack = this.startNextDownload() - if (this.nextTrack !== null) { - try { - nextFile = await this.downloadController.waitForDownload() - } catch(err) { - console.warn( - "\x1b[31mFailed to download (or convert) track \x1b[1m" + - getItemPathString(this.nextTrack) + "\x1b[0m" - ) - await downloadNext() - } - } else { - nextFile = null + await (this.downloadProcess = this.downlold()) + + while (this.nextTrack) { + this.currentTrack = this.nextTrack + + this.downlold() + + // Maybe Promise.all isn't good here? Rather, wait for play-file then + // downlold? Or - we should have some "downlolder" promise, set by + // downlold. + if (this.nextFile) { + await this.playFile(this.nextFile) } + + await this.downloadProcess } + } - await downloadNext() + async downlold() { + this.nextTrack = this.startNextDownload() - while (this.nextTrack) { - this.currentTrack = this.nextTrack + try { + this.nextFile = await this.downloadController.waitForDownload() + } catch(err) { + console.warn( + "\x1b[31mFailed to download (or convert) track \x1b[1m" + + getItemPathString(this.nextTrack) + "\x1b[0m" + ) - await Promise.all([ - // If the downloader returns false, the file failed to download; that - // means we'll just skip this track and wait for the next. - nextFile !== false ? this.playFile(nextFile) : Promise.resolve(), - downloadNext() - ]) + await (this.downloadProcess = this.downlold()) } } diff --git a/src/play.js b/src/play.js index 35001be..08a33cb 100755 --- a/src/play.js +++ b/src/play.js @@ -409,8 +409,7 @@ async function main(args) { // TODO: It would be nice to have this as a method of // PlayController. // Double TODO: This doesn't actually work!! - downloadController.cancel() - play.startNextDownload() + play.downloadProcess = play.downlold() } if ( -- cgit 1.3.0-6-gf8a5