CLI: Added remove and jump commands. Allow multiple commands separated by ';'. Fixed empty selection behavior.

This commit is contained in:
Jonathan Bernard 2016-03-12 21:14:54 -06:00
parent 255f9f9eed
commit 400d3d1774

View File

@ -282,7 +282,8 @@ Configuration:
if (new Date() > dismissMsgDate) resetStatus() if (new Date() > dismissMsgDate) resetStatus()
if (consoleReadBuffer.size() > 0) { if (consoleReadBuffer.size() > 0) {
line = consoleReadBuffer.remove(0) line = consoleReadBuffer.remove(0)
processInput(line.split(/\s/) as LinkedList) line.split(';').each {
processInput(it.trim().split(/\s/) as LinkedList) }
} else { } else {
drawLeader() drawLeader()
if (curMediaFile) { if (curMediaFile) {
@ -304,6 +305,7 @@ Configuration:
case 'list': return processList(line, currentSelection) case 'list': return processList(line, currentSelection)
case 'add': return processAdd(line) case 'add': return processAdd(line)
case 'enqueue': return processEnqueue(line) case 'enqueue': return processEnqueue(line)
case 'remove': return processRemove(line)
case 'tag': return processTag(line) case 'tag': return processTag(line)
case 'clear': return processClear(line) case 'clear': return processClear(line)
case 'play': return processPlay(line) case 'play': return processPlay(line)
@ -311,6 +313,7 @@ Configuration:
case 'stop': return processStop(line) case 'stop': return processStop(line)
case 'next': return processNext(line) case 'next': return processNext(line)
case 'prev': return processPrev(line) case 'prev': return processPrev(line)
case 'jump': return processJump(line)
case 'ff': case 'ff':
case 'fastforward': return processFastForward(line) case 'fastforward': return processFastForward(line)
case 'rw': case 'rw':
@ -374,7 +377,7 @@ Configuration:
return sel return sel
case 'playlist': case 'playlist':
sel.playlist = playQueue; return sel sel.playlist = playQueue; return sel
case 'file': case 'file': case 'mediaFile':
sel.mediaFile = curMediaFile; return sel sel.mediaFile = curMediaFile; return sel
case 'tags': case 'tags':
sel.tags = library.getTagsWhere({ sel.tags = library.getTagsWhere({
@ -388,8 +391,17 @@ Configuration:
} }
switch (option) { switch (option) {
case 'file': option = 'mediaFile' case 'file':
case 'album': case 'artist': case 'playlist': sel.mediaFile = ensureExactlyOne(
library.getByIdOrName(MediaFile, line.join(' ')))
return sel
case 'playlist':
sel.playlist = ensureExactlyOne(
library.getByIdOrName(Playlist, line.join(' ')))
sel.playlist.lastUsed = new Timestamp(new Date().time)
sel.playlist = library.save(sel.playlist)
return sel
case 'mediaFile': case 'album': case 'artist':
sel[option] = ensureExactlyOne( sel[option] = ensureExactlyOne(
library.getByIdOrName(modelClass[option], line.join(' '))) library.getByIdOrName(modelClass[option], line.join(' ')))
return sel return sel
@ -436,6 +448,20 @@ Configuration:
selectedFiles.collect { it.id }) selectedFiles.collect { it.id })
return playQueue } return playQueue }
private def processRemove(LinkedList line) {
String[] parts = line.join(' ').split(' from ')
Playlist playlist
def selection
if (parts.length == 1 || parts[1] == 'queue') playlist = playQueue
else if (parts.length == 2) // TODO: shoule ensure starts with 'playlist'
playlist = processSelect(parts[1].split(' ') as LinkedList)
selection = processSelect(parts[0].split(' ') as LinkedList)
if (selection) selection.selectedFiles.each { file ->
library.removeFromPlaylist(playlist.id, file.id) } }
private def processTag(LinkedList line) { private def processTag(LinkedList line) {
List<String> parts = line.join(' ').split(' as ').collect { it.trim() } List<String> parts = line.join(' ').split(' as ').collect { it.trim() }
@ -495,7 +521,8 @@ Configuration:
if (!selection) selection = new Selection() if (!selection) selection = new Selection()
def option = options.poll() def option = options.poll()
boolean all = option == 'all' boolean all = option == 'all'
if (all) option = options.poll() boolean current = option == 'current'
if (all || current) option = options.poll()
logger.debug("Option: $option") logger.debug("Option: $option")
@ -504,6 +531,8 @@ Configuration:
switch(option) { switch(option) {
case 'albums': case 'albums':
if (all) list = library.getAlbums() if (all) list = library.getAlbums()
else if (current) list = library.getAlbumsWhere(
playlistId: playQueue.id)
else if (selection.album) list = [selection.album] else if (selection.album) list = [selection.album]
else list = library.getAlbumsWhere( else list = library.getAlbumsWhere(
playlistId: selection.playlist?.id, playlistId: selection.playlist?.id,
@ -518,6 +547,8 @@ Configuration:
case 'artists': case 'artists':
if (all) list = library.getArtists() if (all) list = library.getArtists()
else if (current) list = library.getArtistsWhere(
playlistId: playQueue.id)
else if (selection.artist) list = [selection.artist] else if (selection.artist) list = [selection.artist]
else list = library.getArtistsWhere( else list = library.getArtistsWhere(
playlistId: selection.playlist?.id, playlistId: selection.playlist?.id,
@ -527,12 +558,14 @@ Configuration:
String artistMatch = options?.join(" ")?.trim() String artistMatch = options?.join(" ")?.trim()
if (artistMatch) list = list.findAll { it.name =~ artistMatch } if (artistMatch) list = list.findAll { it.name =~ artistMatch }
printLongMessage(makeList(selection, Artist, list, all, printLongMessage(makeList(selection, Artist, list, all,
{ "${it.id}: ${it.name}" })) { "${it.id}: ${it}" }))
break break
case 'files': case 'files':
case 'selection': case 'selection':
if (all) list = library.getMediaFiles() if (all) list = library.getMediaFiles()
else if (current) list = library.getMediaFilesWhere(
playlistId: playQueue.id)
else list = selection.selectedFiles else list = selection.selectedFiles
if (selection.album) list = list.sort { it.trackNumber } if (selection.album) list = list.sort { it.trackNumber }
@ -540,23 +573,26 @@ Configuration:
if (mediaFileMatch) list = list.findAll { if (mediaFileMatch) list = list.findAll {
it.name =~ mediaFileMatch } it.name =~ mediaFileMatch }
printLongMessage(makeList(selection, MediaFile, list, all, printLongMessage(makeList(selection, MediaFile, list, all,
{ "${it.id}: ${it.trackNumber} - ${it.name}" })) { "${it.id}: ${it.trackNumber} - ${it}" }))
break break
case 'bookmarks': case 'bookmarks':
if (all) list = library.getBookmarks() if (all) list = library.getBookmarks()
else if (current) list = library.getBookmarksWhere(
playlistId: playQueue.id)
else list = library.getBookmarksWhere( else list = library.getBookmarksWhere(
playlistId: selection?.playlist?.id) playlistId: selection?.playlist?.id)
String bookmarkMatch = options?.join(" ")?.trim() String bookmarkMatch = options?.join(" ")?.trim()
if (boolmarkMatch) if (bookmarkMatch)
list = list.findAll { it.name =~ bookmarkMatch } list = list.findAll { it.name =~ bookmarkMatch }
printLongMessage(makeList(selection, Bookmark, list, all, printLongMessage(makeList(selection, Bookmark, list, all,
{ "${it.id}: ${it.name} ${it.userCreated ? '' : ' (auto)'}" })) { "${it.id}: ${it} ${it.userCreated ? '' : ' (auto)'}" }))
break break
case 'playlists': case 'playlists':
if (all) list = library.getPlaylists() if (all) list = library.getPlaylists()
else if (current) list = [playQueue]
else list = library.getPlaylistsWhere( else list = library.getPlaylistsWhere(
artistId: selection?.artist?.id, artistId: selection?.artist?.id,
albumId: selection?.album?.id, albumId: selection?.album?.id,
@ -566,11 +602,13 @@ Configuration:
if (playlistMatch) if (playlistMatch)
list = list.findAll { it.name =~ playlistMatch } list = list.findAll { it.name =~ playlistMatch }
printLongMessage(makeList(selection, Playlist, list, all, printLongMessage(makeList(selection, Playlist, list, all,
{ "${it.id}: ${it.name} ${it.userCreated ? '' : ' (auto)'}" })) { "${it.id}: ${it} ${it.userCreated ? '' : ' (auto)'}" }))
break break
case 'tags': case 'tags':
if (all) list = library.getTags() if (all) list = library.getTags()
else if (current) list = library.getTagsWhere(
playlistId: playQueue.id)
else list = library.getTagsWhere( else list = library.getTagsWhere(
playlistId: selection?.playlist?.id, playlistId: selection?.playlist?.id,
artistId: selection?.artist?.id, artistId: selection?.artist?.id,
@ -668,6 +706,33 @@ Configuration:
if ((playBookmark.playIndex - count) >= 0) if ((playBookmark.playIndex - count) >= 0)
vlcj.mediaListPlayer.playItem(playBookmark.playIndex - count) } vlcj.mediaListPlayer.playItem(playBookmark.playIndex - count) }
private def processJump(LinkedList line) {
String errMsg =
"Invalid options to the ${promptStyle}jump${normalStyle}" +
" command. Use ${promptStyle}help jump${normalStyle} to see a " +
"list of valid options."
String to = line.poll()
if (!to || to.trim() != "to") { printLongMessage(errMsg); return }
def criteria = line.poll()
if (!criteria) { printLongMessage(errMsg); return }
def target = getExactlyOne(MediaFile, criteria)
if (!target) return
int index = library.getMediaFilesWhere(playlistId: playQueue.id)
.findIndexOf { it.id == target.id }
if (index < 0) {
setErr "'$target' is not in the current play queue."; return }
printLongMessage("""
target: $target
index: $index""")
vlcj.mediaListPlayer.mediaPlayer.stop()
vlcj.mediaListPlayer.playItem(index) }
private def processFastForward(LinkedList line) { private def processFastForward(LinkedList line) {
def amount = line.poll() def amount = line.poll()
def unit = line.poll()?.trim() def unit = line.poll()?.trim()
@ -958,11 +1023,13 @@ Configuration:
return value } return value }
public List<MediaFile> getSelectedFiles() { public List<MediaFile> getSelectedFiles() {
if (album || artist || mediaFile || playlist || tags)
return library.getMediaFilesWhere( return library.getMediaFilesWhere(
playlistId: playlist?.id, playlistId: playlist?.id,
artistId: artist?.id, artistId: artist?.id,
albumId: album?.id, albumId: album?.id,
tags: tags) } tags: tags)
return null }
public String toString() { public String toString() {
StringBuilder s = new StringBuilder() StringBuilder s = new StringBuilder()