From 6d063af2b57841dce30ddb07bf60ce828d737697 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 11 Aug 2017 10:06:04 -0300 Subject: Completely re-implement pickers --- src/play.js | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src/play.js') diff --git a/src/play.js b/src/play.js index 50be20e..408b79c 100755 --- a/src/play.js +++ b/src/play.js @@ -7,7 +7,7 @@ const clone = require('clone') const fs = require('fs') const fetch = require('node-fetch') const commandExists = require('./command-exists') -const { byName: pickersByName } = require('./pickers') +const makePicker = require('./pickers') const startLoopPlay = require('./loop-play') const processArgv = require('./process-argv') const processSmartPlaylist = require('./smart-playlist') @@ -55,7 +55,8 @@ async function main(args) { let sourcePlaylist = null let activePlaylist = null - let pickerType = 'shuffle' + let pickerSortMode = 'shuffle' + let pickerLoopMode = 'loop-regenerate' let playerCommand = await determineDefaultPlayer() let playOpts = [] @@ -276,15 +277,31 @@ async function main(args) { 'np': util => util.alias('-no-play'), - '-picker': function(util) { - // --picker (alias: --selector) - // Selects the mode that the song to play is picked. + '-sort-mode': function(util) { + // --sort-mode (alias: --sort) + // Sets the mode by which the playback order list is sorted. + // Valid options include 'order', 'shuffle', and 'shuffle-top-level' + // (which has an alias 'shuffle-groups'). // See pickers.js. - pickerType = util.nextArg() + pickerSortMode = util.nextArg() }, - '-selector': util => util.alias('-picker'), + '-sort': util => util.alias('-sort-mode'), + + '-loop-mode': function(util) { + // --loop-mode (alias: --loop) + // Sets the mode by which the playback order list is looped (typically, + // what happens when the picker's index counter gets to the end of the + // list). + // Valid options include 'no-loop', 'loop-same-order' (or 'loop'), + // 'loop-regenerate', and 'pick-random'. + // See pickers.js. + + pickerLoopMode = util.nextArg() + }, + + '-loop': util => util.alias('-loop-mode'), '-player': function(util) { // --player @@ -307,14 +324,9 @@ async function main(args) { } if (willPlay || (willPlay === null && shouldPlay)) { - if (!Object.keys(pickersByName).includes(pickerType)) { - console.error("Invalid picker type: " + pickerType) - return - } - - console.log(`Using ${pickerType} picker.`) + console.log(`Using sort: ${pickerSortMode} and loop: ${pickerLoopMode}.`) - const picker = pickersByName[pickerType](activePlaylist) + const picker = makePicker(activePlaylist, pickerSortMode, pickerLoopMode) console.log(`Using ${playerCommand} player.`) -- cgit 1.3.0-6-gf8a5