« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/loop-play.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/loop-play.js')
-rw-r--r--src/loop-play.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index 7fec995..66de65a 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -164,6 +164,10 @@ class DownloadController extends EventEmitter {
     this.playlist = playlist
   }
 
+  async init() {
+    this.converter = await makeConverter('wav')
+  }
+
   waitForDownload() {
     // Returns a promise that resolves when a download is
     // completed.  Note that this isn't necessarily the download
@@ -226,10 +230,8 @@ class DownloadController extends EventEmitter {
 
     let convertFile
 
-    const converter = await makeConverter('wav')
-
     try {
-      convertFile = await converter(downloadFile)
+      convertFile = await this.converter(downloadFile)
     } catch(err) {
       this.emit('errored', err)
       return
@@ -417,7 +419,7 @@ class PlayController extends EventEmitter {
   }
 }
 
-module.exports = function loopPlay(
+module.exports = async function startLoopPlay(
   playlist, picker, playerCommand = 'mpv', playOpts = []
 ) {
   // Looping play function. Takes one argument, the "picker" function,
@@ -447,6 +449,7 @@ module.exports = function loopPlay(
   }
 
   const downloadController = new DownloadController(playlist)
+  await downloadController.init()
 
   const playController = new PlayController(
     picker, player, playlist, downloadController