From 76011c927cb1cd9e32eeb3c6c5e73ef92c75a156 Mon Sep 17 00:00:00 2001 From: chme Date: Fri, 1 May 2015 11:07:03 +0200 Subject: [PATCH] [mpd] implement command "findadd" --- src/mpd.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/mpd.c b/src/mpd.c index 900e39ae..23a8e23e 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -2113,6 +2113,44 @@ mpd_command_find(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) static int mpd_command_findadd(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) { + struct query_params qp; + struct player_source *ps; + int ret; + + if (argc < 3 || ((argc - 1) % 2) != 0) + { + ret = asprintf(errmsg, "Missing argument(s) for command 'findadd'"); + if (ret < 0) + DPRINTF(E_LOG, L_MPD, "Out of memory\n"); + return ACK_ERROR_ARG; + } + + memset(&qp, 0, sizeof(struct query_params)); + + qp.type = Q_ITEMS; + qp.sort = S_NAME; + qp.idx_type = I_NONE; + + mpd_get_query_params_find(argc - 1, argv + 1, &qp); + + ps = player_queue_make(&qp); + + if (!ps) + { + ret = asprintf(errmsg, "Failed to add songs to playlist"); + if (ret < 0) + DPRINTF(E_LOG, L_MPD, "Out of memory\n"); + return ACK_ERROR_UNKNOWN; + } + + player_queue_add(ps); + + ret = player_playback_start(NULL); + if (ret < 0) + { + DPRINTF(E_LOG, L_MPD, "Could not start playback\n"); + } + return 0; }