diff --git a/NEWS b/NEWS index d6d14361e..3e559dcfc 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ver 0.24 (not yet released) * protocol + - new command "searchcount" (case-insensitive "count") - "playlistfind"/"playlistsearch" have "sort" and "window" parameters - "save" can append to or replace an existing playlist - filter "prio" (for "playlistfind"/"playlistsearch") diff --git a/doc/protocol.rst b/doc/protocol.rst index aa2cbb272..80bd5d67e 100644 --- a/doc/protocol.rst +++ b/doc/protocol.rst @@ -1286,6 +1286,16 @@ The music database The ``position`` parameter specifies where the songs will be inserted. [#since_0_23_4]_ +.. _command_searchcount: + +:command:`searchcount {FILTER} [group {GROUPTYPE}]` + Count the number of songs and their total playtime in + the database matching ``FILTER`` (see + :ref:`Filters `). + + Parameters have the same meaning as for :ref:`count ` + except the search is not case sensitive. + .. _command_update: :command:`update [URI]` diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 2828beffa..dcd616493 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -189,6 +189,7 @@ static constexpr struct command commands[] = { { "search", PERMISSION_READ, 1, -1, handle_search }, { "searchadd", PERMISSION_ADD, 1, -1, handle_searchadd }, { "searchaddpl", PERMISSION_CONTROL, 2, -1, handle_searchaddpl }, + { "searchcount", PERMISSION_READ, 1, -1, handle_searchcount }, #endif { "seek", PERMISSION_PLAYER, 2, 2, handle_seek }, { "seekcur", PERMISSION_PLAYER, 1, 1, handle_seekcur }, diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx index 3775e4622..19291cbb8 100644 --- a/src/command/DatabaseCommands.cxx +++ b/src/command/DatabaseCommands.cxx @@ -231,8 +231,8 @@ handle_searchaddpl(Client &client, Request args, Response &) return CommandResult::OK; } -CommandResult -handle_count(Client &client, Request args, Response &r) +static CommandResult +handle_count_internal(Client &client, Request args, Response &r, bool fold_case) { TagType group = TAG_NUM_OF_ITEM_TYPES; if (args.size() >= 2 && StringIsEqual(args[args.size() - 2], "group")) { @@ -251,7 +251,7 @@ handle_count(Client &client, Request args, Response &r) SongFilter filter; if (!args.empty()) { try { - filter.Parse(args, false); + filter.Parse(args, fold_case); } catch (...) { r.Error(ACK_ERROR_ARG, GetFullMessage(std::current_exception()).c_str()); @@ -265,6 +265,18 @@ handle_count(Client &client, Request args, Response &r) return CommandResult::OK; } +CommandResult +handle_count(Client &client, Request args, Response &r) +{ + return handle_count_internal(client, args, r, false); +} + +CommandResult +handle_searchcount(Client &client, Request args, Response &r) +{ + return handle_count_internal(client, args, r, true); +} + CommandResult handle_listall(Client &client, Request args, Response &r) { diff --git a/src/command/DatabaseCommands.hxx b/src/command/DatabaseCommands.hxx index 6f7ac3882..a2875a6c8 100644 --- a/src/command/DatabaseCommands.hxx +++ b/src/command/DatabaseCommands.hxx @@ -47,6 +47,9 @@ handle_searchadd(Client &client, Request request, Response &response); CommandResult handle_searchaddpl(Client &client, Request request, Response &response); +CommandResult +handle_searchcount(Client &client, Request request, Response &response); + CommandResult handle_count(Client &client, Request request, Response &response);