« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--index.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/index.js b/index.js
index a3b4b9f..b85e0e8 100644
--- a/index.js
+++ b/index.js
@@ -5,6 +5,19 @@ const { getDownloaderFor } = require('./downloaders')
 const EventEmitter = require('events')
 
 class InternalApp extends EventEmitter {
+  constructor() {
+    super()
+    this.player = null
+  }
+
+  async setup() {
+    this.player = await getPlayer()
+  }
+
+  async startPlaying(arg) {
+    this.player.playFile(await this.download(arg))
+  }
+
   download(arg) {
     return getDownloaderFor(arg)(arg)
   }
@@ -12,8 +25,8 @@ class InternalApp extends EventEmitter {
 
 async function main() {
   const internalApp = new InternalApp()
-  const player = await getPlayer()
-  player.playFile(await internalApp.download('http://billwurtz.com/cable-television.mp3'))
+  await internalApp.setup()
+  internalApp.startPlaying('http://billwurtz.com/cable-television.mp3')
 }
 
 main().catch(err => console.error(err))