aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-02-24 02:00:03 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-02-24 02:00:03 +0000
commit6e64bac7b6954d13f5aa47f068dd149219dfe966 (patch)
tree32c633e43d0bf4d5018ebdff467c64c7b86ba4c3
parent1ae3bdb7e6d5a5c4135f6046be9259d6f716498a (diff)
downloadmpd-6e64bac7b6954d13f5aa47f068dd149219dfe966.tar.gz
mpd-6e64bac7b6954d13f5aa47f068dd149219dfe966.tar.xz
mpd-6e64bac7b6954d13f5aa47f068dd149219dfe966.zip
Adding playlistfind and playlistsearch commands for searching the current
playlist. git-svn-id: https://svn.musicpd.org/mpd/trunk@5420 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/command.c43
-rw-r--r--src/playlist.c33
-rw-r--r--src/playlist.h7
3 files changed, 80 insertions, 3 deletions
diff --git a/src/command.c b/src/command.c
index e544a83bc..dc427629f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -28,7 +28,6 @@
#include "permission.h"
#include "buffer2array.h"
#include "log.h"
-#include "dbUtils.h"
#include "tag.h"
#include "utils.h"
@@ -94,6 +93,8 @@
#define COMMAND_NOTCOMMANDS "notcommands"
#define COMMAND_PLAYLISTCLEAR "playlistclear"
#define COMMAND_PLAYLISTADD "playlistadd"
+#define COMMAND_PLAYLISTFIND "playlistfind"
+#define COMMAND_PLAYLISTSEARCH "playlistsearch"
#define COMMAND_STATUS_VOLUME "volume"
#define COMMAND_STATUS_STATE "state"
@@ -510,6 +511,44 @@ static int handleSearch(int fd, int *permission, int argc, char *argv[])
return ret;
}
+static int handlePlaylistFind(int fd, int *permission, int argc, char *argv[])
+{
+ LocateTagItem *items;
+ int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
+ argc - 1,
+ &items);
+
+ if (numItems <= 0) {
+ commandError(fd, ACK_ERROR_ARG, "incorrect arguments");
+ return -1;
+ }
+
+ findSongsInPlaylist(fd, numItems, items);
+
+ freeLocateTagItemArray(numItems, items);
+
+ return 0;
+}
+
+static int handlePlaylistSearch(int fd, int *permission, int argc, char *argv[])
+{
+ LocateTagItem *items;
+ int numItems = newLocateTagItemArrayFromArgArray(argv + 1,
+ argc - 1,
+ &items);
+
+ if (numItems <= 0) {
+ commandError(fd, ACK_ERROR_ARG, "incorrect arguments");
+ return -1;
+ }
+
+ searchForSongsInPlaylist(fd, numItems, items);
+
+ freeLocateTagItemArray(numItems, items);
+
+ return 0;
+}
+
static int listHandleUpdate(int fd,
int *permission,
int argc,
@@ -1002,6 +1041,8 @@ void initCommands(void)
addCommand(COMMAND_NOTCOMMANDS, PERMISSION_NONE, 0, 0, handleNotcommands, NULL);
addCommand(COMMAND_PLAYLISTCLEAR, PERMISSION_CONTROL, 1, 1, handlePlaylistClear, NULL);
addCommand(COMMAND_PLAYLISTADD, PERMISSION_CONTROL, 2, 2, handlePlaylistAdd, NULL);
+ addCommand(COMMAND_PLAYLISTFIND, PERMISSION_READ, 2, -1, handlePlaylistFind, NULL);
+ addCommand(COMMAND_PLAYLISTSEARCH, PERMISSION_READ, 2, -1, handlePlaylistSearch, NULL);
sortList(commandList);
}
diff --git a/src/playlist.c b/src/playlist.c
index 8f4b17804..9d9c2d60f 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -1679,3 +1679,36 @@ int loadPlaylist(int fd, char *utf8file)
{
return PlaylistIterFunc(fd, utf8file, PlaylistLoadIterFunc);
}
+
+void searchForSongsInPlaylist(int fd, int numItems, LocateTagItem * items)
+{
+ int i;
+ char **originalNeedles = xmalloc(numItems * sizeof(char *));
+
+ for (i = 0; i < numItems; i++) {
+ originalNeedles[i] = items[i].needle;
+ items[i].needle = strDupToUpper(originalNeedles[i]);
+ }
+
+ for (i = 0; i < playlist.length; i++) {
+ if (strstrSearchTags(playlist.songs[i], numItems, items))
+ printPlaylistSongInfo(fd, i);
+ }
+
+ for (i = 0; i < numItems; i++) {
+ free(items[i].needle);
+ items[i].needle = originalNeedles[i];
+ }
+
+ free(originalNeedles);
+}
+
+void findSongsInPlaylist(int fd, int numItems, LocateTagItem * items)
+{
+ int i;
+
+ for (i = 0; i < playlist.length; i++) {
+ if (tagItemsFoundAndMatches(playlist.songs[i], numItems, items))
+ printPlaylistSongInfo(fd, i);
+ }
+}
diff --git a/src/playlist.h b/src/playlist.h
index 286450103..a0737f9ec 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -21,8 +21,7 @@
#include "../config.h"
-#include "song.h"
-#include "mpd_types.h"
+#include "dbUtils.h"
#include <stdio.h>
#include <sys/param.h>
@@ -122,4 +121,8 @@ int playlistChangesPosId(int fd, mpd_uint32 version);
int PlaylistInfo(int fd, char *utf8file, int detail);
+void searchForSongsInPlaylist(int fd, int numItems, LocateTagItem * items);
+
+void findSongsInPlaylist(int fd, int numItems, LocateTagItem * items);
+
#endif