From ed31078d4c5d25b0a7c5d64a49235143d8c770aa Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 4 Apr 2016 04:04:49 -0500 Subject: [PATCH] CLI: Implement create command. --- cli/interface.txt | 8 +-- .../wdiwtlt/cli/CommandLineInterface.groovy | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/cli/interface.txt b/cli/interface.txt index a5e3185..6ba0601 100644 --- a/cli/interface.txt +++ b/cli/interface.txt @@ -37,8 +37,8 @@ list playing {albums, artists, files, playlists, tags} # Playlist management -create playlist -create playlist from {selection, queue} +create playlist named +create playlist named from {selection, queue} copy playlist as rename playlist to @@ -52,8 +52,8 @@ clear playlist # Bookmarking -create bookmark -create bookmark on at +create bookmark named +create bookmark named on at rename bookmark to # Transport Functions 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 f97f6ac..1a6ccbf 100644 --- a/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy +++ b/cli/src/main/groovy/com/jdbernard/wdiwtlt/cli/CommandLineInterface.groovy @@ -401,6 +401,7 @@ Configuration: case 'scan': return scanMediaLibrary() case 'list': return processList(rest, currentSelection) case 'select': return processSelect(rest, currentSelection) + case 'create': return processCreate(rest, currentSelection) case 'play': return processPlay(rest, currentSelection) case 'enqueue': return processEnqueue(rest, currentSelection) case 'add': return processAdd(rest, currentSelection) @@ -549,6 +550,57 @@ Configuration: case ~/untagged files/: return library.untaggedFiles default: invalidOptionsErr('select') } } + private def processCreate(String options, List selection = null) { + logger.debug("Creating something. Options: $options") + + String name + + switch (options) { + case ~/bookmark named (.+) on playlist (.+) at (.+)/: + Playlist p = getExactlyOne(Matcher.lastMatcher[0][2].trim()) + MediaFile mf = getExactlyOne(Matcher.lastMatcher[0][3].trim()) + + Bookmark b = new Bookmark(name: Matcher.lastMatcher[0][1].trim(), + playlistId: p.id, mediaFileId: mf.id) + + b = library.save(b) + msg "New bookmark: ${b.id}: ${b.name}" + return b + + case ~/bookmark named (.+)/: + if (!curMediaFile) err 'Nothing currently playing to bookmark.' + Bookmark b = playBookmark.clone() + b.name = Matcher.lastMatcher[0][1].trim() + b.id = null; + + b = library.save(b) + msg "New bookmark: ${b.id}: ${b.name}" + return b + + case ~/playlist named (.+) from (queue|selection)/: + Playlist p + if (Matcher.lastMatcher[0][2] == 'queue') { + p = playQueue.clone() + p.name = Matcher.lastMatcher[0][1].trim() + p.id = null + p = library.save(p) } + else { + p = new Playlist(name: Matcher.lastMatcher[0][1]) + p = library.save(p) + library.addToPlaylist(p.id, + library.collectMediaFiles(selection).collect { it.id }) } + + return p + + case ~/playlist named (.+)/: + Playlist p = new Playlist( + name: Matcher.lastMatcher[0][1].trim(), + userCreated: true) + + p = library.save(p) + msg "New playlist: ${p.id}: ${p.name}" + return p } } + private Playlist processPlay(String options, List selection) { switch (options) {