« 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.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/crawlers.js b/crawlers.js
index 5a4987a..1db02fd 100644
--- a/crawlers.js
+++ b/crawlers.js
@@ -1,6 +1,7 @@
 const fs = require('fs')
 const path = require('path')
 const naturalSort = require('node-natural-sort')
+const expandHomeDir = require('expand-home-dir')
 const fetch = require('node-fetch')
 const url = require('url')
 const { downloadPlaylistFromOptionValue, promisifyProcess } = require('./general-util')
@@ -238,8 +239,9 @@ function crawlLocal(dirPath, extensions = [
       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").
+    // If it's not a URL, it's (assumedly) an ordinary path ("/path/to/the directory").
+    // In this case we'll expand any ~ in the path (e.g. ~/Music -> /home/.../Music).
+    dirPath = expandHomeDir(dirPath)
   }
 
   return readDir(dirPath).then(items => {