From 4612f37b2a7b3402253fc7982f6829d668ed326c Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 2 Jul 2018 23:44:35 -0300 Subject: Shift-Q to shuffle and queue selected group --- README.md | 3 ++- ui.js | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index db5a817..53a31c7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ playlist.json file (usually generated by http-music or downloaded from online). * **In the main listing:** * Enter - if the selected item is a group, enter it; otherwise play it * Backspace - leave the current group (if in one) - * q - queue the selected track to play after any other items in the queue (usually after the current track) + * q - queue the selected track or group to play after any other items in the queue (usually after the current track) + * Q (shift+Q) - queue the selected group, but shuffled * d - download the selected track (but don't play it) * **In the queue listing:** * s - shuffle the queue diff --git a/ui.js b/ui.js index 9a5b727..21ac9df 100644 --- a/ui.js +++ b/ui.js @@ -1,6 +1,6 @@ const { getDownloaderFor } = require('./downloaders') const { getPlayer } = require('./players') -const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString } = require('./playlist-utils') +const { parentSymbol, isGroup, isTrack, getItemPath, getItemPathString, flattenGrouplike } = require('./playlist-utils') const { shuffleArray } = require('./general-util') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') @@ -55,6 +55,7 @@ class AppElement extends FocusElement { this.grouplikeListingElement.on('select (space)', item => this.handleSpacePressed( () => handleSelectFromMain(item))) this.grouplikeListingElement.on('queue', item => this.queueGrouplikeItem(item)) + this.grouplikeListingElement.on('queue (shuffled)', item => this.shuffleQueueGrouplikeItem(item)) const handleSelectFromPathElement = item => { this.form.selectInput(this.grouplikeListingElement) @@ -279,6 +280,14 @@ class AppElement extends FocusElement { this.queueListingElement.buildItems() } + shuffleQueueGrouplikeItem(item) { + if (!isGroup(item)) { + return this.queueGrouplikeItem(item) + } + + return this.queueGrouplikeItem({items: shuffleArray(flattenGrouplike(item).items)}) + } + async downloadGrouplikeItem(item) { if (isGroup(item)) { // TODO: Download all children (recursively), show a confirmation prompt @@ -524,11 +533,9 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - itemElement.on('download', () => this.emit('download', item)) - itemElement.on('remove', () => this.emit('remove', item)) - itemElement.on('select (space)', () => this.emit('select (space)', item)) - itemElement.on('select (enter)', () => this.emit('select (enter)', item)) - itemElement.on('queue', () => this.emit('queue', item)) + for (const evtName of ['download', 'remove', 'select (space)', 'select (enter)', 'queue', 'queue (shuffled)']) { + itemElement.on(evtName, () => this.emit(evtName, item)) + } form.addInput(itemElement) } } else if (!this.grouplike.isTheQueue) { @@ -674,7 +681,11 @@ class GrouplikeItemElement extends Button { if (telc.isCaselessLetter(keyBuf, 'd')) { this.emit('download') } else if (telc.isCaselessLetter(keyBuf, 'q')) { - this.emit('queue') + if (keyBuf[0] === 'q'.charCodeAt(0)) { + this.emit('queue') + } else { + this.emit('queue (shuffled)') + } } else if (telc.isBackspace(keyBuf)) { this.emit('remove') } else if (telc.isSpace(keyBuf)) { -- cgit 1.3.0-6-gf8a5