mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 07:35:57 -05:00
[mpd] implement range support for 'delete' command
This commit is contained in:
parent
b007529678
commit
b2d2e9286f
27
src/mpd.c
27
src/mpd.c
@ -1696,9 +1696,9 @@ mpd_command_clear(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
static int
|
||||
mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
{
|
||||
struct player_status status;
|
||||
uint32_t start_pos;
|
||||
int pos;
|
||||
int start_pos;
|
||||
int end_pos;
|
||||
int count;
|
||||
int ret;
|
||||
|
||||
// If argv[1] is ommited clear the whole queue except the current playing one
|
||||
@ -1709,32 +1709,21 @@ mpd_command_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
}
|
||||
|
||||
// If argument argv[1] is present remove only the specified songs
|
||||
//TODO support ranges for argv[1]
|
||||
ret = safe_atou32(argv[1], &start_pos);
|
||||
ret = mpd_pars_range_arg(argv[1], &start_pos, &end_pos);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = asprintf(errmsg, "Argument doesn't convert to integer: '%s'", argv[1]);
|
||||
ret = asprintf(errmsg, "Argument doesn't convert to integer or range: '%s'", argv[1]);
|
||||
if (ret < 0)
|
||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||
return ACK_ERROR_ARG;
|
||||
}
|
||||
|
||||
player_get_status(&status);
|
||||
count = end_pos - start_pos;
|
||||
|
||||
pos = start_pos - status.pos_pl;
|
||||
|
||||
if (pos < 1)
|
||||
{
|
||||
ret = asprintf(errmsg, "Removing playing or previously played song not supported (song position %d)", pos);
|
||||
if (ret < 0)
|
||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||
return ACK_ERROR_ARG;
|
||||
}
|
||||
|
||||
ret = player_queue_remove_bypos(pos);
|
||||
ret = player_queue_remove_byindex(start_pos, count);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = asprintf(errmsg, "Failed to remove song at position '%d'", pos);
|
||||
ret = asprintf(errmsg, "Failed to remove %d songs starting at position %d", count, start_pos);
|
||||
if (ret < 0)
|
||||
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
|
||||
return ACK_ERROR_UNKNOWN;
|
||||
|
58
src/player.c
58
src/player.c
@ -167,6 +167,12 @@ struct playerqueue_move_param
|
||||
int count;
|
||||
};
|
||||
|
||||
struct playerqueue_remove_param
|
||||
{
|
||||
int from_pos;
|
||||
int count;
|
||||
};
|
||||
|
||||
struct icy_artwork
|
||||
{
|
||||
uint32_t id;
|
||||
@ -211,6 +217,7 @@ struct player_command
|
||||
struct playerqueue_get_param queue_get_param;
|
||||
struct playerqueue_add_param queue_add_param;
|
||||
struct playerqueue_move_param queue_move_param;
|
||||
struct playerqueue_remove_param queue_remove_param;
|
||||
} arg;
|
||||
|
||||
int ret;
|
||||
@ -3490,6 +3497,28 @@ playerqueue_remove_bypos(struct player_command *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
playerqueue_remove_byindex(struct player_command *cmd)
|
||||
{
|
||||
int pos;
|
||||
int count;
|
||||
int i;
|
||||
|
||||
pos = cmd->arg.queue_remove_param.from_pos;
|
||||
count = cmd->arg.queue_remove_param.count;
|
||||
|
||||
DPRINTF(E_DBG, L_PLAYER, "Removing %d items starting from position %d\n", count, pos);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
queue_remove_byindex(queue, pos, 0);
|
||||
|
||||
cur_plversion++;
|
||||
|
||||
listener_notify(LISTENER_PLAYLIST);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
playerqueue_remove_byitemid(struct player_command *cmd)
|
||||
{
|
||||
@ -4287,6 +4316,35 @@ player_queue_remove_bypos(int pos)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes the media item at the given position from the UpNext-queue
|
||||
*
|
||||
* The UpNext-queue consists of all items of the play-queue (shuffle off) or shuffle-queue
|
||||
* (shuffle on) after the current playing item (starting with position 0).
|
||||
*
|
||||
* @param pos Position in the UpNext-queue (0-based)
|
||||
* @return 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
player_queue_remove_byindex(int pos, int count)
|
||||
{
|
||||
struct player_command cmd;
|
||||
int ret;
|
||||
|
||||
command_init(&cmd);
|
||||
|
||||
cmd.func = playerqueue_remove_byindex;
|
||||
cmd.func_bh = NULL;
|
||||
cmd.arg.queue_remove_param.from_pos = pos;
|
||||
cmd.arg.queue_remove_param.count = count;
|
||||
|
||||
ret = sync_command(&cmd);
|
||||
|
||||
command_deinit(&cmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes the item with the given (queueitem) item id from the queue
|
||||
*
|
||||
|
@ -175,6 +175,9 @@ player_queue_move_byitemid(uint32_t item_id, int pos_to);
|
||||
int
|
||||
player_queue_remove_bypos(int pos);
|
||||
|
||||
int
|
||||
player_queue_remove_byindex(int pos, int count);
|
||||
|
||||
int
|
||||
player_queue_remove_byitemid(uint32_t id);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user