From 434be2846074731af1e25715ecb817b3efa4068b Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 16 Dec 2017 12:24:45 +0100 Subject: [PATCH] [mpd] Support position parameter in command 'addid' --- src/mpd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mpd.c b/src/mpd.c index 14a1534d..cb2d0355 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -1793,6 +1793,7 @@ static int mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, struct mpd_client_ctx *ctx) { struct media_file_info mfi; + int to_pos = -1; int ret; if (argc < 2) @@ -1801,10 +1802,14 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, return ACK_ERROR_ARG; } - //TODO if argc > 2 add song at position argv[2] if (argc > 2) { - DPRINTF(E_LOG, L_MPD, "Adding at a specified position not supported for 'addid', adding songs at end of queue.\n"); + ret = safe_atoi32(argv[2], &to_pos); + if (ret < 0) + { + *errmsg = safe_asprintf("Argument doesn't convert to integer: '%s'", argv[2]); + return ACK_ERROR_ARG; + } } ret = mpd_queue_add(argv[1], true); @@ -1829,6 +1834,11 @@ mpd_command_addid(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, return ACK_ERROR_UNKNOWN; } + if (to_pos >= 0) + { + db_queue_move_byitemid(ret, to_pos, 0); + } + evbuffer_add_printf(evbuf, "Id: %d\n", ret); // mpd_queue_add returns the item_id of the last inserted queue item