« get me outta code hell

http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/downloaders.js19
-rwxr-xr-xsrc/play.js3
-rw-r--r--todo.txt9
3 files changed, 30 insertions, 1 deletions
diff --git a/src/downloaders.js b/src/downloaders.js
index 527f67d..3f3a427 100644
--- a/src/downloaders.js
+++ b/src/downloaders.js
@@ -33,4 +33,21 @@ function makeYouTubeDownloader() {
   }
 }
 
-module.exports = {makeHTTPDownloader, makeYouTubeDownloader}
+function makeLocalDownloader() {
+  return function(arg, out) {
+    const read = fs.createReadStream(arg)
+    const write = fs.createWriteStream(out)
+
+    return new Promise((resolve, reject) => {
+      write.on('error', err => reject(err))
+      write.on('close', () => resolve())
+      read.pipe(write)
+    })
+  }
+}
+
+module.exports = {
+  makeHTTPDownloader,
+  makeYouTubeDownloader,
+  makeLocalDownloader
+}
diff --git a/src/play.js b/src/play.js
index 38b05d5..bc9324d 100755
--- a/src/play.js
+++ b/src/play.js
@@ -185,6 +185,9 @@ readFile('./playlist.json', 'utf-8')
       } else if (downloaderType === 'youtube') {
         console.log("Using YouTube downloader.")
         downloader = downloaders.makeYouTubeDownloader()
+      } else if (downloaderType === 'local') {
+        console.log("Using local file downloader.")
+        downloader = downloaders.makeLocalDownloader()
       } else {
         console.error("Invalid downloader type: " + downloaderType)
         return
diff --git a/todo.txt b/todo.txt
index 2bed599..53a5991 100644
--- a/todo.txt
+++ b/todo.txt
@@ -70,3 +70,12 @@ TODO: Volume controls. Who knows how to do this? It might have to be an
 
 TODO: Tempfiles, maybe?
       (Done!)
+
+TODO: Use NOT the internet as its source, so that it's a bit more general
+      purpose. This would only take adding a new downloader.
+      (Done!)
+
+TODO: Recursive local file playlist crawler.
+
+TODO: *Requiring* a literal `playlist.json` file doesn't seem quite right,
+      especially since there's the `--open` option.