aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-08-25 13:43:22 +0200
committerMax Kellermann <max@duempel.org>2009-08-25 13:43:22 +0200
commitdf0c26a394be7dd4137c9614dd867122019d78f8 (patch)
tree7f7806e251104c6d473e6bba5be4a50ca6e84ffc
parent1e56c7b8629f5c11eee0680e4584030cac939ce8 (diff)
downloadmpd-df0c26a394be7dd4137c9614dd867122019d78f8.tar.gz
mpd-df0c26a394be7dd4137c9614dd867122019d78f8.tar.xz
mpd-df0c26a394be7dd4137c9614dd867122019d78f8.zip
command: add "findadd" command.
Diffstat (limited to '')
-rw-r--r--NEWS1
-rw-r--r--doc/protocol.xml17
-rw-r--r--src/command.c25
-rw-r--r--src/dbUtils.c22
-rw-r--r--src/dbUtils.h4
5 files changed, 69 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 5175dfaee..ec9b27496 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ ver 0.16 (20??/??/??)
- send song modification time to client
- added "update" idle event
- removed the deprecated "volume" command
+ - added the "findadd" command
* input:
- lastfm: use metadata
* tags:
diff --git a/doc/protocol.xml b/doc/protocol.xml
index 7c93df50f..a08f95f1a 100644
--- a/doc/protocol.xml
+++ b/doc/protocol.xml
@@ -1100,6 +1100,23 @@ OK
</para>
</listitem>
</varlistentry>
+ <varlistentry id="command_findadd">
+ <term>
+ <cmdsynopsis>
+ <command>findadd</command>
+ <arg choice="req"><replaceable>TYPE</replaceable></arg>
+ <arg choice="req"><replaceable>WHAT</replaceable></arg>
+ </cmdsynopsis>
+ </term>
+ <listitem>
+ <para>
+ Finds songs in the db that are exactly
+ <varname>WHAT</varname> and adds them to current playlist.
+ <varname>TYPE</varname> can be any tag supported by MPD.
+ <varname>WHAT</varname> is what to find.
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry id="command_list">
<term>
<cmdsynopsis>
diff --git a/src/command.c b/src/command.c
index c1c330765..58e931650 100644
--- a/src/command.c
+++ b/src/command.c
@@ -870,6 +870,30 @@ handle_find(struct client *client, int argc, char *argv[])
}
static enum command_return
+handle_findadd(struct client *client, int argc, char *argv[])
+{
+ int ret;
+ struct locate_item_list *list =
+ locate_item_list_parse(argv + 1, argc - 1);
+ if (list == NULL || list->length == 0) {
+ if (list != NULL)
+ locate_item_list_free(list);
+
+ command_error(client, ACK_ERROR_ARG, "incorrect arguments");
+ return COMMAND_RETURN_ERROR;
+ }
+
+ ret = findAddIn(client, NULL, list);
+ if (ret == -1)
+ command_error(client, ACK_ERROR_NO_EXIST,
+ "directory or file not found");
+
+ locate_item_list_free(list);
+
+ return ret;
+}
+
+static enum command_return
handle_search(struct client *client, int argc, char *argv[])
{
int ret;
@@ -1671,6 +1695,7 @@ static const struct command commands[] = {
{ "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput },
{ "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput },
{ "find", PERMISSION_READ, 2, -1, handle_find },
+ { "findadd", PERMISSION_READ, 2, -1, handle_findadd},
{ "idle", PERMISSION_READ, 0, -1, handle_idle },
{ "kill", PERMISSION_ADMIN, -1, -1, handle_kill },
{ "list", PERMISSION_READ, 1, -1, handle_list },
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 67eb89ebe..88122649e 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -200,6 +200,28 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file)
}
static int
+findAddInDirectory(struct song *song, void *_data)
+{
+ struct search_data *data = _data;
+
+ if (locate_song_match(song, data->criteria))
+ return directoryAddSongToPlaylist(song, data);
+
+ return 0;
+}
+
+int findAddIn(struct client *client, const char *name,
+ const struct locate_item_list *criteria)
+{
+ struct search_data data;
+
+ data.client = client;
+ data.criteria = criteria;
+
+ return db_walk(name, findAddInDirectory, NULL, &data);
+}
+
+static int
directoryPrintSongInfo(struct song *song, void *data)
{
struct client *client = data;
diff --git a/src/dbUtils.h b/src/dbUtils.h
index 1382c243e..914b6fa84 100644
--- a/src/dbUtils.h
+++ b/src/dbUtils.h
@@ -40,6 +40,10 @@ findSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria);
int
+findAddIn(struct client *client, const char *name,
+ const struct locate_item_list *criteria);
+
+int
searchStatsForSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria);