diff options
author | Florrie <towerofnix@gmail.com> | 2020-02-15 22:13:53 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2020-02-15 22:15:15 -0400 |
commit | 48ed5168d477fe11fe4f21ae104e3750935b0943 (patch) | |
tree | c0d9260246933d180a2fa5405da8e66e9c484705 /players.js | |
parent | fd09d0196f8db2102f9364a56f3075bf2cd93c88 (diff) |
cli args (bass boost ur music)
$ mtui --player sox --player-options bass +25 \;
Diffstat (limited to 'players.js')
-rw-r--r-- | players.js | 33 |
1 files changed, 17 insertions, 16 deletions
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 } |