From 09875d28d95b825424f513867e503aefdcba7bc7 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Wed, 6 Apr 2016 11:21:18 -0500 Subject: [PATCH] CLI add selection removal. --- .../wdiwtlt/cli/CommandLineInterface.groovy | 101 +++++++++++------- 1 file changed, 62 insertions(+), 39 deletions(-) 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 9adfa46..781ec13 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -77,7 +77,7 @@ Options: Configuration: """ - p2rivate static Logger logger = + private static Logger logger = LoggerFactory.getLogger(CommandLineInterface) private Properties cliConfig @@ -695,44 +695,67 @@ Configuration: msg "${mediaFiles.size()} media files added to '${p.name}'." return added } + private def removeFromSelection(List toRemoveSel, + List selection) { + if (!toRemoveSel) err 'Nothing was selected to be removed.' + if (!selection) err 'Selection is already empty.' + + if (selection[0].class == toRemoveSel[0].class) { + return selection - toRemoveSel } + + List selectionFiles = library.collectMediaFiles(selection) + List toRemoveFiles = library.collectMediaFiles(toRemoveSel) + return selectionFiles - toRemoveFiles } + private def processRemove(String options, List selection = null) { def m = (options =~ /(.+) from (.+)/) String removeFrom = m[0][2] + List toRemoveSel - if (m[0][1] != 'selection') selection = select(m[0][1], selection) - if (!selection) err 'Nothing was selected to be removed.' + if (m[0][1] == 'selection') toRemoveSel = selection + else toRemoveSel = select(m[0][1], selection) - Playlist p - if (removeFrom == 'queue') p = playQueue - else if (removeFrom.startsWith('playlist')) { - String[] parts = removeFrom.split(/\s/, 2) - if (parts.size() < 2) err 'No playlist id or name given.' - p = getExactlyOne(Playlist, parts[1]) } + if (!toRemoveSel) err 'Nothing was selected to be removed.' - List toRemove = library.collectMediaFiles(selection) - toRemove.each { library.removeFromPlaylist(p.id, it.id) } + if (removeFrom == 'selection') { + currentSelecton = removeFromSelection(toRemoveSel, selection) + msg "Removed from selection." + return } - // Reset our queue if we removed from the queue - if (removeFrom == 'queue') { - vlcj.mediaListPlayer.stop() - setPlayQueue(playQueue) + else { + Playlist p + if (removeFrom == 'queue') p = playQueue + else if (removeFrom.startsWith('playlist')) { + String[] parts = removeFrom.split(/\s/, 2) + if (parts.size() < 2) err 'No playlist id or name given.' + p = getExactlyOne(Playlist, parts[1]) } - // Restart playback with the file that was playing before we - // removed stuff (may not be there anymore) - if (playBookmark) { - MediaFile mf = library.getMediaFileById(playBookmark.mediaFileId) - List playlistMFs = library.getMediaFilesWhere( - playlistId: playQueue.id) - int index = playlistMFs.indexOf(mf) - if (index > 0) { - vlcj.mediaListPlayer.playItem(index) - if (playBookmark.playTimeMs > 0) { - vlcj.mediaListPlayer.mediaPlayer.time = - playBookmark.playTimeMs } } } } + List toRemoveFiles = library.collectMediaFiles(toRemoveSel) + toRemoveFiles.each { library.removeFromPlaylist(p.id, it.id) } - msg "Removed ${toRemove.size()} files." - return toRemove } + // Reset our queue if we removed from the queue + if (removeFrom == 'queue') { + vlcj.mediaListPlayer.stop() + setPlayQueue(playQueue) + + // Restart playback with the file that was playing before we + // removed stuff (may not be there anymore) + if (playBookmark) { + MediaFile mf = library.getMediaFileById(playBookmark.mediaFileId) + List playlistMFs = library.getMediaFilesWhere( + playlistId: playQueue.id) + int index = playlistMFs.indexOf(mf) + + if (index > 0) { + vlcj.mediaListPlayer.playItem(index) + + if (playBookmark.playTimeMs > 0) { + vlcj.mediaListPlayer.mediaPlayer.time = + playBookmark.playTimeMs } } } } + + msg "Removed ${toRemoveFiles.size()} files." + return toRemoveFiles } } private def processRandomize(String options) { Playlist p @@ -1153,18 +1176,19 @@ add to playlist // REMOVE // -------------- case 'remove': return """\ -remove selection from queue +remove selection from { queue | selection } remove selection from playlist - Remove the media files for the current selection from the current play - queue or from a playlist looked up by ID or name (including partial match). + Remove the media files for the current selection from the current + selection, the current play queue, or from a playlist looked up by ID or + name (including partial match). -remove from queue +remove from { queue | selection } remove from playlist Make a selection using the ${cmdStyle}select${normalStyle} syntax then remove those media - files from either the play queue or from a playlist looked up by ID or name - (including partial match). + files from either the current selection, the play queue, or from a + playlist looked up by ID or name (including partial match). """ @@ -1352,8 +1376,8 @@ Playlist and Queue Management: remove selection from playlist remove from playlist - remove selection from queue - remove from queue + remove selection from { queue | selection } + remove from { queue | selection } create bookmark named create bookmark named on playlist at @@ -1367,8 +1391,7 @@ Playlist and Queue Management: delete playlist delete bookmark - randomize queue - randomize playlist + randomize { queue | playlist | selection } reorder queue move to reorder playlist move to