« get me outta code hell

--play-opts - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-06-01 10:09:48 -0300
committerliam4 <towerofnix@gmail.com>2017-06-01 10:09:48 -0300
commite302f04b782685847fd5ab72a1f968f6d03ccfe4 (patch)
tree2d3d6f666f3022ac16356705f3ae5bd54af20524
parent671fc02d4fb26db0a5c3f83845eb46da73b08548 (diff)
--play-opts
-rw-r--r--src/loop-play.js11
-rwxr-xr-xsrc/play.js10
2 files changed, 15 insertions, 6 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index 0a4b291..560ac63 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -12,12 +12,13 @@ const sanitize = require('sanitize-filename')
 
 const writeFile = promisify(fs.writeFile)
 
-module.exports = async function loopPlay(fn) {
+module.exports = async function loopPlay(fn, playArgs = []) {
   // Looping play function. Takes one argument, the "pick" function,
   // which returns a track to play. Preemptively downloads the next
   // track while the current one is playing for seamless continuation
   // from one song to the next. Stops when the result of the pick
-  // function is null (or similar).
+  // function is null (or similar). Optionally takes a second argument
+  // used as arguments to the `play` process (before the file name).
 
   async function downloadNext() {
     const picked = fn()
@@ -53,7 +54,7 @@ module.exports = async function loopPlay(fn) {
 
   while (wavFile) {
     const nextPromise = downloadNext()
-    await playFile(wavFile)
+    await playFile(wavFile, playArgs)
     wavFile = await nextPromise
   }
 }
@@ -63,7 +64,7 @@ function convert(fromFile, toFile) {
   return promisifyProcess(avconv, false)
 }
 
-function playFile(file) {
-  const play = spawn('play', [file])
+function playFile(file, opts = []) {
+  const play = spawn('play', [...opts, file])
   return promisifyProcess(play)
 }
diff --git a/src/play.js b/src/play.js
index 2e47fba..0ffe996 100755
--- a/src/play.js
+++ b/src/play.js
@@ -22,6 +22,7 @@ readFile('./playlist.json', 'utf-8')
     let curPlaylist = playlist
 
     let pickerType = 'shuffle'
+    let playOpts = []
 
     // WILL play says whether the user has forced playback via an argument.
     // SHOULD play says whether the program has automatically decided to play
@@ -139,6 +140,13 @@ readFile('./playlist.json', 'utf-8')
         pickerType = util.nextArg()
       },
 
+      '-play-opts': function(util) {
+        // --play-opts <opts>
+        // Sets command line options passed to the `play` command.
+
+        playOpts = util.nextArg().split(' ')
+      },
+
       '-debug-list': function(util) {
         // --debug-list
         // Prints out the JSON representation of the active playlist.
@@ -159,7 +167,7 @@ readFile('./playlist.json', 'utf-8')
         console.error("Invalid picker type: " + pickerType)
       }
 
-      return loopPlay(picker)
+      return loopPlay(picker, playOpts)
     } else {
       return curPlaylist
     }