QueueCommands: new command "rangeid"
Manipulates the playback range of a queued song.
This commit is contained in:
@@ -150,6 +150,7 @@ static const struct command commands[] = {
|
||||
{ "prio", PERMISSION_CONTROL, 2, -1, handle_prio },
|
||||
{ "prioid", PERMISSION_CONTROL, 2, -1, handle_prioid },
|
||||
{ "random", PERMISSION_CONTROL, 1, 1, handle_random },
|
||||
{ "rangeid", PERMISSION_ADD, 2, 2, handle_rangeid },
|
||||
{ "readcomments", PERMISSION_READ, 1, 1, handle_read_comments },
|
||||
{ "readmessages", PERMISSION_READ, 0, 0, handle_read_messages },
|
||||
{ "rename", PERMISSION_CONTROL, 2, 2, handle_rename },
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include "ls.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/UriUtil.hxx"
|
||||
#include "util/NumberParser.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
|
||||
@@ -118,6 +119,59 @@ handle_addid(Client &client, unsigned argc, char *argv[])
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string in the form "START:END", both being (optional)
|
||||
* fractional non-negative time offsets in seconds. Returns both in
|
||||
* integer milliseconds. Omitted values are zero.
|
||||
*/
|
||||
static bool
|
||||
parse_time_range(const char *p, unsigned &start_ms, unsigned &end_ms)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
const float start = ParseFloat(p, &endptr);
|
||||
if (*endptr != ':' || start < 0)
|
||||
return false;
|
||||
|
||||
start_ms = endptr > p
|
||||
? unsigned(start * 1000u)
|
||||
: 0u;
|
||||
|
||||
p = endptr + 1;
|
||||
|
||||
const float end = ParseFloat(p, &endptr);
|
||||
if (*endptr != 0 || end < 0)
|
||||
return false;
|
||||
|
||||
end_ms = endptr > p
|
||||
? unsigned(end * 1000u)
|
||||
: 0u;
|
||||
|
||||
return end_ms == 0 || end_ms > start_ms;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_rangeid(Client &client, gcc_unused unsigned argc, char *argv[])
|
||||
{
|
||||
unsigned id;
|
||||
if (!check_unsigned(client, &id, argv[1]))
|
||||
return CommandResult::ERROR;
|
||||
|
||||
unsigned start_ms, end_ms;
|
||||
if (!parse_time_range(argv[2], start_ms, end_ms)) {
|
||||
command_error(client, ACK_ERROR_ARG, "Bad range");
|
||||
return CommandResult::ERROR;
|
||||
}
|
||||
|
||||
Error error;
|
||||
if (!client.partition.playlist.SetSongIdRange(client.partition.pc,
|
||||
id, start_ms, end_ms,
|
||||
error))
|
||||
return print_error(client, error);
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
||||
CommandResult
|
||||
handle_delete(Client &client, gcc_unused unsigned argc, char *argv[])
|
||||
{
|
||||
|
@@ -30,6 +30,9 @@ handle_add(Client &client, unsigned argc, char *argv[]);
|
||||
CommandResult
|
||||
handle_addid(Client &client, unsigned argc, char *argv[]);
|
||||
|
||||
CommandResult
|
||||
handle_rangeid(Client &client, unsigned argc, char *argv[]);
|
||||
|
||||
CommandResult
|
||||
handle_delete(Client &client, unsigned argc, char *argv[]);
|
||||
|
||||
|
Reference in New Issue
Block a user