From a8ef887dbfaee530d13e86ff583393a4ddf88e93 Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 24 Jul 2017 20:26:37 -0300 Subject: Support SoX again; make 'converter' meta-downloader (converts to wav) --- src/play.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/play.js') 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 + // 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 // 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 -- cgit 1.3.0-6-gf8a5