From 48ed5168d477fe11fe4f21ae104e3750935b0943 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 15 Feb 2020 22:13:53 -0400 Subject: cli args (bass boost ur music) $ mtui --player sox --player-options bass +25 \; --- players.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'players.js') diff --git a/players.js b/players.js index 5d332b3..868129d 100644 --- a/players.js +++ b/players.js @@ -10,9 +10,11 @@ const util = require('util') const unlink = util.promisify(fs.unlink) class Player extends EventEmitter { - constructor() { + constructor(processOptions = []) { super() + this.processOptions = processOptions + this.disablePlaybackStatus = false this.isLooping = false this.isPaused = false @@ -78,7 +80,7 @@ module.exports.MPVPlayer = class extends Player { // The more powerful MPV player. MPV is virtually impossible for a human // being to install; if you're having trouble with it, try the SoX player. - this.process = spawn('mpv', this.getMPVOptions(file)) + this.process = spawn('mpv', this.getMPVOptions(file).concat(this.processOptions)) let lastPercent = 0 @@ -223,7 +225,7 @@ module.exports.SoXPlayer = class extends Player { // You don't get keyboard controls such as seeking or volume adjusting // with SoX, though. - this.process = spawn('play', [file]) + this.process = spawn('play', [file].concat(this.processOptions)) this.process.stdout.on('data', data => { process.stdout.write(data.toString()) @@ -276,19 +278,18 @@ module.exports.SoXPlayer = class extends Player { } } -module.exports.getPlayer = async function() { - if (await commandExists('mpv')) { - /* - if (await commandExists('socat')) { - return new module.exports.ControllableMPVPlayer() - } else { - return new module.exports.MPVPlayer() - } - */ - return new module.exports.ControllableMPVPlayer() - } else if (await commandExists('play')) { - return new module.exports.SoXPlayer() - } else { +module.exports.getPlayer = async function(name = null, options = []) { + if (await commandExists('mpv') && (name === null || name === 'mpv')) { + return new module.exports.ControllableMPVPlayer(options) + } else if (name === 'mpv') { + return null + } + + if (await commandExists('play') && (name === null || name === 'sox')) { + return new module.exports.SoXPlayer(options) + } else if (name === 'sox') { return null } + + return null } -- cgit 1.3.0-6-gf8a5