diff --git a/cli/interface.txt b/cli/interface.txt index 6ba0601..6e904e4 100644 --- a/cli/interface.txt +++ b/cli/interface.txt @@ -50,11 +50,14 @@ remove from playlist clear playlist +delete playlist + # Bookmarking create bookmark named create bookmark named on at rename bookmark to +delete bookmark # 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 5fc64bd..9adfa46 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: """ - private static Logger logger = + p2rivate static Logger logger = LoggerFactory.getLogger(CommandLineInterface) private Properties cliConfig @@ -404,6 +404,7 @@ Configuration: case 'list': return processList(rest, currentSelection) case 'select': return processSelect(rest, currentSelection) case 'create': return processCreate(rest, currentSelection) + case 'delete': return processDelete(rest) case 'play': return processPlay(rest, currentSelection) case 'enqueue': return processEnqueue(rest, currentSelection) case 'add': return processAdd(rest, currentSelection) @@ -610,6 +611,18 @@ Configuration: default: invalidOptionsErr('create') } } + private def processDelete(String options) { + switch (options) { + case ~/playlist (.+)/: + Playlist p = getExactlyOne( + Playlist, Matcher.lastMatcher[0][1].trim()) + return library.delete(p) + case ~/bookmark (.+)/: + Bookmark b = getExactlyOne( + Bookmark, Matcher.latMatcher[0][1].trim()) + return library.delete(b) + default: invalidOptionsErr('delete') } } + private Playlist processPlay(String options, List selection) { switch (options) { @@ -670,7 +683,7 @@ Configuration: Playlist p def m = (options =~ /(.+) to playlist (.+)/) - p = getExactlyOne(m[0][2]) + p = getExactlyOne(Playlist, m[0][2]) if (!p) err "No playlist for '${Matcher.lastMatcher[0][1]}'." if (m[0][1] != "selection") selection = select(options, selection) @@ -936,6 +949,7 @@ Available commands: select Select things (into the select buffer, no the play queue). play Play requested media. enqueue Enqueue requested media to the end of the play queue. + create Create a playlist or bookmark. 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. @@ -1074,6 +1088,15 @@ ${cmdStyle}create playlist named from { queue | selection}${normalStyle} current play queue or the current selection. """ + // DELETE + // -------------- + case 'delete': return """\ +${cmdStyle}delete playlist +delete bookmark ${normalStyle} + + Delete a playlist or bookmark. +""" + // PLAY // -------------- case 'play': return """\ @@ -1336,10 +1359,14 @@ Playlist and Queue Management: create bookmark named on playlist at create playlist named from { selection | queue } create playlist named + copy playlist as create bookmark update bookmark + delete playlist + delete bookmark + randomize queue randomize playlist diff --git a/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy b/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy index c084367..f321d83 100644 --- a/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy +++ b/core/src/main/groovy/com/jdbernard/wdiwtlt/db/DbApi.groovy @@ -637,6 +637,11 @@ public class DbApi { return sql.rows(query, sqlParams) .collect { recordToModel(Playlist, it) } } + public int delete(Playlist p) { + return withTransaction { + removeAllFromPlaylist(p.id) + delete((Model) p) } } + public int getNextPlaylistPosition(UUID playlistId) { String query = """\ SELECT COALESCE(MAX(position), 0) + 1 @@ -740,7 +745,8 @@ public class DbApi { logger.debug( 'Finding media file playlist position.\n\tSQL: {}\n\tPARAMS: {}', getPositionQuery, params) - int position = sql.firstRow(getPositionQuery, params)[0] + def row = sql.firstRow(getPositionQuery, params) + int position = row ? row[0] : 0 logger.debug( 'Removing media file from playlist.\n\tSQL: {}\n\tPARAMS: {}',