From 811997668969a5bf782f9edc6fba92db7aa35b6d Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 26 Jun 2017 23:24:02 -0300 Subject: Clean-up and such --- src/http-music.js | 23 ++++++++++++----------- src/loop-play.js | 46 ++++++++++++++-------------------------------- 2 files changed, 26 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/http-music.js b/src/http-music.js index 863d170..e926e5d 100755 --- a/src/http-music.js +++ b/src/http-music.js @@ -2,14 +2,12 @@ 'use strict' -const fs = require('fs') - const { promisify } = require('util') +const fs = require('fs') +const pickers = require('./pickers') const loopPlay = require('./loop-play') const processArgv = require('./process-argv') -const pickers = require('./pickers') - const { filterPlaylistByPathString, removeGroupByPathString, getPlaylistTreeString } = require('./playlist-utils') @@ -259,7 +257,10 @@ Promise.resolve() return } - const play = loopPlay(picker, playOpts) + const { + promise: playPromise, + controller: play + } = loopPlay(picker, playOpts) // We're looking to gather standard input one keystroke at a time. process.stdin.setRawMode(true) @@ -303,11 +304,11 @@ Promise.resolve() } if (Buffer.from('s').equals(data)) { - // clearConsoleLine() - // console.log( - // "Skipping the track that's currently playing. " + - // "(Press I for track info!)" - // ) + clearConsoleLine() + console.log( + "Skipping the track that's currently playing. " + + "(Press I for track info!)" + ) play.skipCurrent() } @@ -331,7 +332,7 @@ Promise.resolve() } }) - return play.promise + return playPromise } else { return activePlaylist } diff --git a/src/loop-play.js b/src/loop-play.js index 3c00ef5..10b1d5f 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -1,13 +1,7 @@ 'use strict' const { spawn } = require('child_process') -const promisifyProcess = require('./promisify-process') -const sanitize = require('sanitize-filename') -const tempy = require('tempy') -const path = require('path') - const FIFO = require('fifo-js') - const EventEmitter = require('events') class PlayController { @@ -84,7 +78,7 @@ class PlayController { } skipCurrent() { - this.killProcess() + this.kill() } seekAhead(secs) { @@ -113,7 +107,7 @@ class PlayController { } } - killProcess() { + kill() { if (this.process) { this.process.kill() } @@ -125,13 +119,20 @@ class PlayController { this.currentTrack = null } + + logTrackInfo() { + if (this.currentTrack) { + const [ curTitle, curArg ] = this.currentTrack + console.log(`Playing: \x1b[1m${curTitle} \x1b[2m${curArg}\x1b[0m`) + } else { + console.log("No song currently playing.") + } + } } module.exports = function loopPlay(picker, playArgs = []) { - // Looping play function. Takes one argument, the "pick" function, - // which returns a track to play. Preemptively downloads the next - // track while the current one is playing for seamless continuation - // from one song to the next. Stops when the result of the pick + // Looping play function. Takes one argument, the "picker" function, + // which returns a track to play. Stops when the result of the picker // function is null (or similar). Optionally takes a second argument // used as arguments to the `play` process (before the file name). @@ -142,25 +143,6 @@ module.exports = function loopPlay(picker, playArgs = []) { return { promise, - - seekBack: secs => playController.seekBack(secs), - seekAhead: secs => playController.seekAhead(secs), - skipCurrent: () => playController.skipCurrent(), - volUp: amount => playController.volUp(amount), - volDown: amount => playController.volDown(amount), - togglePause: () => playController.togglePause(), - - kill: function() { - playController.killProcess() - }, - - logTrackInfo: function() { - if (playController.currentTrack) { - const [ curTitle, curArg ] = playController.currentTrack - console.log(`Playing: \x1b[1m${curTitle} \x1b[2m${curArg}\x1b[0m`) - } else { - console.log("No song currently playing.") - } - } + controller: playController } } -- cgit 1.3.0-6-gf8a5