Commit b1b630a4 authored by Max Kellermann's avatar Max Kellermann

command/database: support "sort" and "window" in more commands

parent c60d374f
ver 0.22 (not yet released) ver 0.22 (not yet released)
* protocol
- "findadd"/"searchadd"/"searchaddpl" support the "sort" and
"window" parameters
* input * input
- ffmpeg: allow partial reads - ffmpeg: allow partial reads
* filter * filter
......
...@@ -849,7 +849,7 @@ The music database ...@@ -849,7 +849,7 @@ The music database
.. _command_findadd: .. _command_findadd:
:command:`findadd {FILTER}` :command:`findadd {FILTER} [sort {TYPE}] [window {START:END}]`
Search the database for songs matching Search the database for songs matching
``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
the queue. Parameters have the same meaning as for the queue. Parameters have the same meaning as for
...@@ -961,14 +961,14 @@ The music database ...@@ -961,14 +961,14 @@ The music database
.. _command_searchadd: .. _command_searchadd:
:command:`searchadd {FILTER}` :command:`searchadd {FILTER} [sort {TYPE}] [window {START:END}]`
Search the database for songs matching Search the database for songs matching
``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
the queue. the queue.
Parameters have the same meaning as for :ref:`search <command_search>`. Parameters have the same meaning as for :ref:`search <command_search>`.
:command:`searchaddpl {NAME} {FILTER}` :command:`searchaddpl {NAME} {FILTER} [sort {TYPE}] [window {START:END}]`
Search the database for songs matching Search the database for songs matching
``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to ``FILTER`` (see :ref:`Filters <filter_syntax>`) and add them to
the playlist named ``NAME``. the playlist named ``NAME``.
......
...@@ -140,55 +140,37 @@ handle_search(Client &client, Request args, Response &r) ...@@ -140,55 +140,37 @@ handle_search(Client &client, Request args, Response &r)
} }
static CommandResult static CommandResult
handle_match_add(Client &client, Request args, Response &r, bool fold_case) handle_match_add(Client &client, Request args, bool fold_case)
{ {
SongFilter filter; SongFilter filter;
try { const auto selection = ParseDatabaseSelection(args, fold_case, filter);
filter.Parse(args, fold_case);
} catch (...) {
r.Error(ACK_ERROR_ARG,
GetFullMessage(std::current_exception()).c_str());
return CommandResult::ERROR;
}
filter.Optimize();
auto &partition = client.GetPartition(); auto &partition = client.GetPartition();
const ScopeBulkEdit bulk_edit(partition);
const DatabaseSelection selection("", true, &filter);
AddFromDatabase(partition, selection); AddFromDatabase(partition, selection);
return CommandResult::OK; return CommandResult::OK;
} }
CommandResult CommandResult
handle_findadd(Client &client, Request args, Response &r) handle_findadd(Client &client, Request args, Response &)
{ {
return handle_match_add(client, args, r, false); return handle_match_add(client, args, false);
} }
CommandResult CommandResult
handle_searchadd(Client &client, Request args, Response &r) handle_searchadd(Client &client, Request args, Response &)
{ {
return handle_match_add(client, args, r, true); return handle_match_add(client, args, true);
} }
CommandResult CommandResult
handle_searchaddpl(Client &client, Request args, Response &r) handle_searchaddpl(Client &client, Request args, Response &)
{ {
const char *playlist = args.shift(); const char *playlist = args.shift();
SongFilter filter; SongFilter filter;
try { const auto selection = ParseDatabaseSelection(args, true, filter);
filter.Parse(args, true);
} catch (...) {
r.Error(ACK_ERROR_ARG,
GetFullMessage(std::current_exception()).c_str());
return CommandResult::ERROR;
}
filter.Optimize();
const Database &db = client.GetDatabaseOrThrow(); const Database &db = client.GetDatabaseOrThrow();
const DatabaseSelection selection("", true, &filter);
search_add_to_playlist(db, client.GetStorage(), search_add_to_playlist(db, client.GetStorage(),
playlist, selection); playlist, selection);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment