From 9a3b488fd91291e6ff848145d83fb7552b6bd398 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 25 Aug 2017 16:36:37 -0300 Subject: Hide playback status --- man/http-music-play.1 | 3 +++ src/loop-play.js | 37 ++++++++++++++++++++++++++++++++++--- src/play.js | 20 +++++++++++++++++--- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/man/http-music-play.1 b/man/http-music-play.1 index 5e409ba..d029063 100644 --- a/man/http-music-play.1 +++ b/man/http-music-play.1 @@ -65,6 +65,9 @@ Skips the currently playing track. Clears the active playlist. This does not effect the source playlist, so specific groups can be selected using \fB\-\-keep\fR. +.TP +.BR \-\-disable\-playback\-status ", " \-\-hide\-playback\-status +Hides playback status (timestamps, etc). .TP .BR \-h ", " \-? ", " \-\-help diff --git a/src/loop-play.js b/src/loop-play.js index 585414b..212ee1c 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -22,6 +22,10 @@ const { } = require('./downloaders') class Player { + constructor() { + this.disablePlaybackStatus = false + } + playFile(file) {} seekAhead(secs) {} seekBack(secs) {} @@ -43,6 +47,10 @@ class MPVPlayer extends Player { this.process = spawn('mpv', this.getMPVOptions(file)) this.process.stderr.on('data', data => { + if (this.disablePlaybackStatus) { + return + } + const match = data.toString().match( /(..):(..):(..) \/ (..):(..):(..) \(([0-9]+)%\)/ ) @@ -147,7 +155,25 @@ class SoXPlayer extends Player { this.process = spawn('play', [file]) - return promisifyProcess(this.process) + this.process.stdout.on('data', data => { + process.stdout.write(data.toString()) + }) + + // Most output from SoX is given to stderr, for some reason! + this.process.stderr.on('data', data => { + // The status line starts with "In:". + if (data.toString().trim().startsWith('In:')) { + if (this.disablePlaybackStatus) { + return + } + } + + process.stdout.write(data.toString()) + }) + + return new Promise(resolve => { + this.process.on('close', () => resolve()) + }) } async kill() { @@ -425,7 +451,10 @@ class PlayController extends EventEmitter { } module.exports = async function startLoopPlay( - playlist, picker, playerCommand = 'mpv', playOpts = [] + playlist, { + picker, playerCommand = 'mpv', + disablePlaybackStatus = false + } ) { // Looping play function. Takes one argument, the "picker" function, // which returns a track to play. Stops when the result of the picker @@ -453,6 +482,8 @@ module.exports = async function startLoopPlay( return Promise.resolve() } + Object.assign(player, {disablePlaybackStatus}) + const downloadController = new DownloadController(playlist) await downloadController.init() @@ -460,7 +491,7 @@ module.exports = async function startLoopPlay( picker, player, playlist, downloadController ) - Object.assign(playController, {playerCommand, playOpts}) + Object.assign(playController, {playerCommand}) const promise = playController.loopPlay() diff --git a/src/play.js b/src/play.js index 5d41bb9..efc60df 100755 --- a/src/play.js +++ b/src/play.js @@ -62,7 +62,6 @@ async function main(args) { let pickerSortMode = 'shuffle' let pickerLoopMode = 'loop-regenerate' let playerCommand = await determineDefaultPlayer() - 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 @@ -70,6 +69,8 @@ async function main(args) { let shouldPlay = true let willPlay = null + let disablePlaybackStatus = false + async function openPlaylist(arg, silent = false) { let playlistText @@ -310,7 +311,17 @@ async function main(args) { // installed on your system. playerCommand = util.nextArg() - } + }, + + '-disable-playback-status': function() { + // --disable-playback-status (alias: --hide-playback-status) + // Hides the playback status line. + + console.log("Not showing playback status.") + disablePlaybackStatus = true + }, + + '-hide-playback-status': util => util.alias('-disable-playback-status') } await openPlaylist('./playlist.json', true) @@ -335,7 +346,10 @@ async function main(args) { playController, downloadController, player - } = await startLoopPlay(activePlaylist, picker, playerCommand, playOpts) + } = await startLoopPlay(activePlaylist, { + picker, playerCommand, + disablePlaybackStatus + }) // 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