diff --git a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy index 78392c5..8efcc85 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -327,6 +327,7 @@ Configuration: case 'remove': return processRemove(rest, currentSelection) case 'tag': return processTag(rest, currentSelection) case 'untag': return processTag(rest, currentSelection, false) + case 'randomize': return processRandomize(rest) case 'clear': return processClear(rest) case 'pause': return processPause() case 'stop': return processStop() @@ -566,6 +567,44 @@ Configuration: msg "Removed ${toRemove.size()} files." return toRemove } + private def processRandomize(String options) { + Playlist p + switch (options) { + case 'queue': p = playQueue; break + case ~/playlist (.+)/: + String idOrName = Matcher.lastMatcher[0][1] + p = getExactlyOne(Playlist, idOrName) + break + default: invalidOptionsErr('randomize') } + + library.randomizePlaylist(p) } + + private def processReorder(String options) { + Playlist p + int startingIdx = -1 + + String[] parts = options.split(/ as | starting at /) + + if (parts.size() < 2) invalidOptionsErr('reorder'); + + // Playlist or queue? + switch (parts[0].trim()) { + case 'queue': p = playQueue; break + case ~/playlist (.+)/: + String idOrName = Matcher.lastMatcher[0][1] + p = getExactlyOne(Playlist, idOrName) + break + default: invalidOptionsErr('reorder') } + + // What files in order? + List playlistFiles = library.getMediaFilesWhere(playlistId: p.id) + String[] fileIds = parts[1].split(/[,;\s]/) + List files = fileIds.collect { library.getMediaFileById(it) } + .findAll() + + if (parts.size() == 3) startingIdx = safeToInteger(parts[2]) + } + private def processTag(String options, List selection, boolean addTags = true) { @@ -722,6 +761,8 @@ Available commands: enqueue Enqueue requested media to the end of the play queue. add Append requested media to the end of a playlist. remove Remove requested from the play queue or playlist. + randomize Re-order the files in a play queue or a playlist randomly. + reorder Re-order the files in a play queue or a playlist. tag Associate tags with requested media. untag Remove the association between the given tags and media. clear Clear the selection, play queue, playlist, or screen. @@ -900,7 +941,36 @@ remove from playlist """ - // tag + // RANDOMIZE + // -------------- + case 'randomize': return """\ +randomize queue +randomize playlist + + Randomize the order of all elements in either the current play queue or the + named playlist. + +""" + + // REORDER + // -------------- + case 'reorder': return """\ +reorder queue move to +reorder playlist move to + + Move a single file from its current position to the named position in the + play queue/playlist. + +reorder queue as ... starting at +reorder playlist as ... starting at + + Take a set of files in the playlist, reorder them into given order, and + move them to the given starting position (defaults to the end of the + playlist) + +""" + + // TAG // -------------- case 'tag': return """\ tag ... @@ -1053,6 +1123,14 @@ Playlist and Queue Management: create bookmark update bookmark + randomize queue + randomize playlist + + reorder queue move to + reorder playlist move to + reorder queue as ... + reorder playlist as ... + clear clear queue clear selection