« get me outta code hell

Support SoX again; make 'converter' meta-downloader (converts to wav) - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/play.js
diff options
context:
space:
mode:
authorliam4 <towerofnix@gmail.com>2017-07-24 20:26:37 -0300
committerliam4 <towerofnix@gmail.com>2017-07-24 20:26:37 -0300
commita8ef887dbfaee530d13e86ff583393a4ddf88e93 (patch)
tree8c9b1d94c9b79e83d3201e58882382dd9cdce930 /src/play.js
parentb6e90e8f380569803b9a83f8997159b34d64e501 (diff)
Support SoX again; make 'converter' meta-downloader (converts to wav)
Diffstat (limited to 'src/play.js')
-rwxr-xr-xsrc/play.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/play.js b/src/play.js
index 9515d97..6db8e68 100755
--- a/src/play.js
+++ b/src/play.js
@@ -6,6 +6,7 @@ const { promisify } = require('util')
 const clone = require('clone')
 const fs = require('fs')
 const fetch = require('node-fetch')
+const commandExists = require('command-exists')
 const pickers = require('./pickers')
 const loopPlay = require('./loop-play')
 const processArgv = require('./process-argv')
@@ -39,11 +40,22 @@ function clearConsoleLine() {
   process.stdout.write('\x1b[1K\r')
 }
 
+async function determineDefaultPlayer() {
+  if (await commandExists('mpv')) {
+    return 'mpv'
+  } else if (await commandExists('play')) {
+    return 'play'
+  } else {
+    return null
+  }
+}
+
 async function main(args) {
   let sourcePlaylist = null
   let activePlaylist = null
 
   let pickerType = 'shuffle'
+  let playerCommand = await determineDefaultPlayer()
   let playOpts = []
 
   // WILL play says whether the user has forced playback via an argument.
@@ -270,6 +282,17 @@ async function main(args) {
 
     '-selector': util => util.alias('-picker'),
 
+    '-player': function(util) {
+      // --player <player>
+      // Sets the shell command by which audio is played.
+      // Valid options include 'sox' (or 'play') and 'mpv'. Use whichever is
+      // installed on your system; mpv is the default.
+
+      playerCommand = util.nextArg()
+    },
+
+    '-player': util => util.alias('-player-command'),
+
     '-play-opts': function(util) {
       // --play-opts <opts>
       // Sets command line options passed to the `play` command.
@@ -301,11 +324,13 @@ async function main(args) {
       return
     }
 
+    console.log(`Using ${playerCommand} player.`)
+
     const {
       promise: playPromise,
       playController: play,
       downloadController
-    } = loopPlay(picker, playOpts)
+    } = loopPlay(picker, playerCommand, playOpts)
 
     // We're looking to gather standard input one keystroke at a time.
     // But that isn't *always* possible, e.g. when piping into the http-music