« 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--crawlers.js11
-rw-r--r--todo.txt3
2 files changed, 14 insertions, 0 deletions
diff --git a/crawlers.js b/crawlers.js
index 61f422b..82ef78e 100644
--- a/crawlers.js
+++ b/crawlers.js
@@ -190,6 +190,17 @@ function crawlLocal(dirPath, extensions = [
   'wav', 'mp3', 'mp4', 'm4a', 'aac',
   'mod'
 ]) {
+  // If the passed path is a file:// URL, try to decode it:
+  try {
+    const url = new URL(dirPath)
+    if (url.protocol === 'file:') {
+      dirPath = decodeURIComponent(url.pathname)
+    }
+  } catch (error) {
+    // If it's not a URL, don't do anything special - it's (assumedly) an
+    // ordinary path ("/path/to/the directory").
+  }
+
   return readDir(dirPath).then(items => {
     items.sort(sortIgnoreCase(naturalSort()))
 
diff --git a/todo.txt b/todo.txt
index c008d46..b06ef7d 100644
--- a/todo.txt
+++ b/todo.txt
@@ -29,3 +29,6 @@ TODO: Pressing enter in the queue seems to not be doing the right thing?
 TODO: iTunes downloader - test this.
 
 TODO: Warn if no mkfifo (means controls won't work).
+
+TODO: file:// support for crawl-local.
+      (Done!)