« get me outta code hell

Output to file 'Foo Bar.mp3' instead of 'Foo%20Bar.mp3' - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLiam <towerofnix@gmail.com>2017-06-13 12:25:00 -0300
committerLiam <towerofnix@gmail.com>2017-06-13 12:25:00 -0300
commite3aab40a0ac45ae13384b28b27c242ff11a7c4d4 (patch)
tree5cf85eb6f7a9d21b4e11ac3a7c330ead9328aa9a
parenta056ebe64ecedcc73874b1d06ab19eb235780147 (diff)
Output to file 'Foo Bar.mp3' instead of 'Foo%20Bar.mp3'
-rw-r--r--src/downloaders.js3
-rw-r--r--todo.txt7
2 files changed, 9 insertions, 1 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index ad322fa..fa1f337 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -3,6 +3,7 @@ const fetch = require('node-fetch')
 const promisifyProcess = require('./promisify-process')
 const tempy = require('tempy')
 const path = require('path')
+const sanitize = require('sanitize-filename')
 
 const { spawn } = require('child_process')
 const { promisify } = require('util')
@@ -12,7 +13,7 @@ const writeFile = promisify(fs.writeFile)
 function makeHTTPDownloader() {
   return function(arg) {
     const dir = tempy.directory()
-    const out = dir + '/' + path.basename(arg)
+    const out = dir + '/' + sanitize(decodeURIComponent(path.basename(arg)))
 
     return fetch(arg)
       .then(response => response.buffer())
diff --git a/todo.txt b/todo.txt
index bbb23f2..439181b 100644
--- a/todo.txt
+++ b/todo.txt
@@ -128,3 +128,10 @@ TODO: Let playlist filter match things lowercase. '72 Minutes Of Fame' should
       best to prioritize a case-sensitive match before a non-case-sensitive
       one. Given the input 'FoObAR', prioritize 'FoObAR' over 'Foobar'.)
       (Done!)
+
+TODO: Figure out why written track files (when using HTTP downloader) are
+      URL-encoded. It's probably writing a file based on the href-file name,
+      rather than the title. That's alright, but maybe we should URL-decode
+      and then sanitize the href-file name, so that we get 'Foo Bar.mp3'
+      instead of 'Foo%20Bar.mp3'.
+      (Done!)