CLI: Implement create command.

This commit is contained in:
Jonathan Bernard 2016-04-04 04:04:49 -05:00
parent 39276f9a73
commit ed31078d4c
2 changed files with 56 additions and 4 deletions

View File

@ -37,8 +37,8 @@ list playing {albums, artists, files, playlists, tags}
# Playlist management # Playlist management
create playlist create playlist named <playlist name>
create playlist from {selection, queue} create playlist named <playlist name> from {selection, queue}
copy playlist <id | name> as <new name> copy playlist <id | name> as <new name>
rename playlist <old name> to <new name> rename playlist <old name> to <new name>
@ -52,8 +52,8 @@ clear playlist <id | name>
# Bookmarking # Bookmarking
create bookmark create bookmark named <name>
create bookmark on <playlist id | name> at <media file id | name> create bookmark named <name> on <playlist id | name> at <media file id | name>
rename bookmark <old name> to <new name> rename bookmark <old name> to <new name>
# Transport Functions # Transport Functions

View File

@ -401,6 +401,7 @@ Configuration:
case 'scan': return scanMediaLibrary() case 'scan': return scanMediaLibrary()
case 'list': return processList(rest, currentSelection) case 'list': return processList(rest, currentSelection)
case 'select': return processSelect(rest, currentSelection) case 'select': return processSelect(rest, currentSelection)
case 'create': return processCreate(rest, currentSelection)
case 'play': return processPlay(rest, currentSelection) case 'play': return processPlay(rest, currentSelection)
case 'enqueue': return processEnqueue(rest, currentSelection) case 'enqueue': return processEnqueue(rest, currentSelection)
case 'add': return processAdd(rest, currentSelection) case 'add': return processAdd(rest, currentSelection)
@ -549,6 +550,57 @@ Configuration:
case ~/untagged files/: return library.untaggedFiles case ~/untagged files/: return library.untaggedFiles
default: invalidOptionsErr('select') } } default: invalidOptionsErr('select') } }
private def processCreate(String options, List<Model> 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<Model> selection) { private Playlist processPlay(String options, List<Model> selection) {
switch (options) { switch (options) {