2012-08-07 21:55:11 +02:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 The Music Player Daemon Project
|
2012-08-07 21:55:11 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "DatabaseCommands.hxx"
|
2014-02-01 01:11:50 +01:00
|
|
|
#include "db/DatabaseGlue.hxx"
|
2014-01-24 16:18:50 +01:00
|
|
|
#include "db/DatabaseQueue.hxx"
|
|
|
|
#include "db/DatabasePlaylist.hxx"
|
|
|
|
#include "db/DatabasePrint.hxx"
|
|
|
|
#include "db/Selection.hxx"
|
2012-09-25 12:10:12 +02:00
|
|
|
#include "CommandError.hxx"
|
2014-01-24 00:26:53 +01:00
|
|
|
#include "client/Client.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2012-08-29 19:12:26 +02:00
|
|
|
#include "SongFilter.hxx"
|
2013-01-03 10:33:04 +01:00
|
|
|
#include "protocol/Result.hxx"
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2014-02-28 19:02:23 +01:00
|
|
|
CommandResult
|
|
|
|
handle_listfiles_db(Client &client, const char *uri)
|
|
|
|
{
|
|
|
|
const DatabaseSelection selection(uri, false);
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
if (!db_selection_print(client, selection, false, true, error))
|
|
|
|
return print_error(client, error);
|
|
|
|
|
|
|
|
return CommandResult::OK;
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_lsinfo2(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2014-02-28 07:11:45 +01:00
|
|
|
const char *const uri = argc == 2
|
|
|
|
? argv[1]
|
2012-08-07 21:55:11 +02:00
|
|
|
/* default is root directory */
|
2014-02-28 07:11:45 +01:00
|
|
|
: "";
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2012-08-07 23:06:41 +02:00
|
|
|
const DatabaseSelection selection(uri, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2014-02-28 19:02:23 +01:00
|
|
|
if (!db_selection_print(client, selection, true, false, error))
|
2012-08-07 21:55:11 +02:00
|
|
|
return print_error(client, error);
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
static CommandResult
|
2013-10-29 19:29:22 +01:00
|
|
|
handle_match(Client &client, int argc, char *argv[], bool fold_case)
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2012-08-29 19:27:03 +02:00
|
|
|
SongFilter filter;
|
|
|
|
if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-10-29 19:29:22 +01:00
|
|
|
const DatabaseSelection selection("", true, &filter);
|
2012-08-07 23:22:37 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2014-02-28 19:02:23 +01:00
|
|
|
return db_selection_print(client, selection, true, false, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_find(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2013-10-29 19:29:22 +01:00
|
|
|
return handle_match(client, argc, argv, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_search(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2013-10-29 19:29:22 +01:00
|
|
|
return handle_match(client, argc, argv, true);
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
static CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_match_add(Client &client, int argc, char *argv[], bool fold_case)
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2012-08-29 19:27:03 +02:00
|
|
|
SongFilter filter;
|
|
|
|
if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-01-07 11:33:00 +01:00
|
|
|
const DatabaseSelection selection("", true, &filter);
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2013-10-19 18:48:38 +02:00
|
|
|
return AddFromDatabase(client.partition, selection, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_findadd(Client &client, int argc, char *argv[])
|
2012-08-08 00:44:58 +02:00
|
|
|
{
|
|
|
|
return handle_match_add(client, argc, argv, false);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_searchadd(Client &client, int argc, char *argv[])
|
2012-08-08 00:44:58 +02:00
|
|
|
{
|
|
|
|
return handle_match_add(client, argc, argv, true);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_searchaddpl(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
|
|
|
const char *playlist = argv[1];
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
SongFilter filter;
|
|
|
|
if (!filter.Parse(argc - 2, argv + 2, true)) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2014-02-01 00:26:34 +01:00
|
|
|
const Database *db = client.GetDatabase(error);
|
2014-02-01 01:11:50 +01:00
|
|
|
if (db == nullptr)
|
|
|
|
return print_error(client, error);
|
|
|
|
|
2014-02-07 00:29:07 +01:00
|
|
|
return search_add_to_playlist(*db, *client.GetStorage(),
|
|
|
|
"", playlist, &filter, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_count(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2012-08-29 19:27:03 +02:00
|
|
|
SongFilter filter;
|
|
|
|
if (!filter.Parse(argc - 1, argv + 1, false)) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
|
|
|
return searchStatsForSongsIn(client, "", &filter, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_listall(Client &client, gcc_unused int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
|
|
|
const char *directory = "";
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
|
|
|
return printAllIn(client, directory, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_list(Client &client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2012-08-07 23:59:17 +02:00
|
|
|
unsigned tagType = locate_parse_type(argv[1]);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2012-08-07 23:59:17 +02:00
|
|
|
if (tagType == TAG_NUM_OF_ITEM_TYPES) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]);
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tagType == LOCATE_TAG_ANY_TYPE) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"any\" is not a valid return tag type");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* for compatibility with < 0.12.0 */
|
2012-08-29 19:27:03 +02:00
|
|
|
SongFilter *filter;
|
2012-08-07 21:55:11 +02:00
|
|
|
if (argc == 3) {
|
|
|
|
if (tagType != TAG_ALBUM) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"should be \"%s\" for 3 arguments",
|
|
|
|
tag_item_names[TAG_ALBUM]);
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
filter = new SongFilter((unsigned)TAG_ARTIST, argv[2]);
|
2012-08-08 01:16:40 +02:00
|
|
|
} else if (argc > 2) {
|
2012-08-29 19:27:03 +02:00
|
|
|
filter = new SongFilter();
|
|
|
|
if (!filter->Parse(argc - 2, argv + 2, false)) {
|
|
|
|
delete filter;
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"not able to parse args");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
2012-08-08 01:16:40 +02:00
|
|
|
} else
|
2012-08-29 19:27:03 +02:00
|
|
|
filter = nullptr;
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult ret =
|
2013-08-10 18:02:44 +02:00
|
|
|
listAllUniqueTags(client, tagType, filter, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
|
2012-08-29 19:27:03 +02:00
|
|
|
delete filter;
|
2012-08-07 21:55:11 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2013-10-19 18:48:38 +02:00
|
|
|
handle_listallinfo(Client &client, gcc_unused int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
|
|
|
const char *directory = "";
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
|
|
|
return printInfoForAllIn(client, directory, error)
|
2013-10-20 13:10:54 +02:00
|
|
|
? CommandResult::OK
|
2012-08-07 21:55:11 +02:00
|
|
|
: print_error(client, error);
|
|
|
|
}
|