« 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--downloaders.js5
-rw-r--r--todo.txt12
-rw-r--r--ui.js60
3 files changed, 50 insertions, 27 deletions
diff --git a/downloaders.js b/downloaders.js
index 1e2a9e9..b7582a9 100644
--- a/downloaders.js
+++ b/downloaders.js
@@ -19,6 +19,11 @@ const copyFile = fse.copy
 
 const cachify = (identifier, baseFunction) => {
   return async arg => {
+    // If there was no argument passed (or it aws empty), nothing will work..
+    if (!arg) {
+      throw new TypeError('Expected a downloader argument')
+    }
+
     // Determine where the final file will end up. This is just a directory -
     // the file's own name is determined by the downloader.
     const cacheDir = downloaders.rootCacheDir + '/' + identifier
diff --git a/todo.txt b/todo.txt
index f5bff02..c1f7b51 100644
--- a/todo.txt
+++ b/todo.txt
@@ -38,4 +38,14 @@ TODO: Pass YouTube playlist or http://.../playlist.json-like URLs to use them
       (Done!)
 
 TODO: There's some weird glitch where, if downloaderArg is missing (=== ""),
-      it'll play.. something by Jake Chudnow??
+      it'll play.. something by Jake Chudnow?? -- Okay, looks like it's using
+      ~/.mtui/downloads/<locallink, etc>/ as the directory for where it would
+      put the download file (because it's .../localink/ + encode(dlArg) and
+      dlArg is empty). The way the cache works is that it checks if there is
+      already a file in that directory, and there IS: a directory for another
+      track download! But the cache doesn't know this; it just thinks that
+      directory is the MP3 file (or whatever). So it returns it. MPV works fine
+      if you pass it a directory that contains music files, so in my case,
+      72_food (by Jake Chudnow) plays. (That's the first thing returned by
+      readdir, I suppose.)
+      (Done!)
diff --git a/ui.js b/ui.js
index 371958d..9a5b727 100644
--- a/ui.js
+++ b/ui.js
@@ -312,38 +312,46 @@ class AppElement extends FocusElement {
 
     // TODO: Check if it's an item or a group
 
-    // If, by the time the track is downloaded, we're playing something
-    // different from when the download started, assume that we just want to
-    // keep listening to whatever new thing we started.
+    playTrack: {
+      // No downloader argument? That's no good - stop here.
+      // TODO: An error icon on this item, or something???
+      if (!item.downloaderArg) {
+        break playTrack
+      }
 
-    const oldTrack = this.playingTrack
+      // If, by the time the track is downloaded, we're playing something
+      // different from when the download started, assume that we just want to
+      // keep listening to whatever new thing we started.
 
-    const downloadFile = await this.downloadGrouplikeItem(item)
+      const oldTrack = this.playingTrack
 
-    if (this.playingTrack !== oldTrack) {
-      return
-    }
+      const downloadFile = await this.downloadGrouplikeItem(item)
 
-    await this.player.kill()
-    this.recordStore.getRecord(item).playing = true
-    this.playingTrack = item
-    this.playbackInfoElement.updateTrack(item)
-    if (!this.queueListingElement.isSelected) {
-      this.queueListingElement.selectAndShow(item)
-    }
+      if (this.playingTrack !== oldTrack) {
+        return
+      }
 
-    await Promise.all([
-      writeFile(this.rootDirectory + '/current-track.txt',
-        getItemPathString(item)),
-      writeFile(this.rootDirectory + '/current-track.json',
-        JSON.stringify(item, null, 2))
-    ])
+      await this.player.kill()
+      this.recordStore.getRecord(item).playing = true
+      this.playingTrack = item
+      this.playbackInfoElement.updateTrack(item)
+      if (!this.queueListingElement.isSelected) {
+        this.queueListingElement.selectAndShow(item)
+      }
 
-    try {
-      await this.player.playFile(downloadFile)
-    } finally {
-      if (playingThisTrack || this.playingTrack !== item) {
-        this.recordStore.getRecord(item).playing = false
+      await Promise.all([
+        writeFile(this.rootDirectory + '/current-track.txt',
+          getItemPathString(item)),
+        writeFile(this.rootDirectory + '/current-track.json',
+          JSON.stringify(item, null, 2))
+      ])
+
+      try {
+        await this.player.playFile(downloadFile)
+      } finally {
+        if (playingThisTrack || this.playingTrack !== item) {
+          this.recordStore.getRecord(item).playing = false
+        }
       }
     }