« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/downloaders.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index bc9cf15..c0e54eb 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -58,10 +58,17 @@ function makeLocalDownloader() {
   // platform way).
 
   return function(arg) {
+    // It's possible the downloader argument start with the "file://" protocol
+    // string; in that case we'll want to snip it off and URL-decode the
+    // string.
+    const fileProto = 'file://'
+    if (arg.startsWith(fileProto)) {
+      arg = decodeURIComponent(arg.slice(fileProto.length))
+    }
+
     const dir = tempy.directory()
     // TODO: Is it necessary to sanitize here?
-    // haha, the answer to "should I sanitize" is probably always
-    // YES..
+    // Haha, the answer to "should I sanitize" is probably always YES..
     const base = path.basename(arg, path.extname(arg))
     const file = dir + '/' + sanitize(base) + '.mp3'
     return copyFile(arg, file)