2012-08-07 21:55:11 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2012 The Music Player Daemon Project
|
|
|
|
* 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"
|
2012-08-07 22:57:18 +02:00
|
|
|
#include "DatabaseQueue.hxx"
|
|
|
|
#include "DatabasePlaylist.hxx"
|
2012-08-07 23:10:34 +02:00
|
|
|
#include "DatabasePrint.hxx"
|
2012-08-07 23:06:41 +02:00
|
|
|
#include "DatabaseSelection.hxx"
|
2012-08-07 21:55:11 +02:00
|
|
|
#include "CommandError.h"
|
|
|
|
#include "client_internal.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "uri.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "locate.h"
|
|
|
|
#include "protocol/result.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_lsinfo2(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *uri;
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
uri = argv[1];
|
|
|
|
else
|
|
|
|
/* default is root directory */
|
|
|
|
uri = "";
|
|
|
|
|
2012-08-07 23:06:41 +02:00
|
|
|
const DatabaseSelection selection(uri, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
|
|
|
GError *error = NULL;
|
2012-08-07 23:10:34 +02:00
|
|
|
if (!db_selection_print(client, selection, true, &error))
|
2012-08-07 21:55:11 +02:00
|
|
|
return print_error(client, error);
|
|
|
|
|
|
|
|
return COMMAND_RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:44:58 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_match(struct client *client, int argc, char *argv[], bool fold_case)
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
|
|
|
struct locate_item_list *list =
|
2012-08-08 00:44:58 +02:00
|
|
|
locate_item_list_parse(argv + 1, argc - 1, fold_case);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2012-08-07 23:37:38 +02:00
|
|
|
if (list == NULL) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-08-07 23:22:37 +02:00
|
|
|
const DatabaseSelection selection("", true, list);
|
|
|
|
|
2012-08-07 21:55:11 +02:00
|
|
|
GError *error = NULL;
|
2012-08-07 23:22:37 +02:00
|
|
|
enum command_return ret =
|
|
|
|
db_selection_print(client, selection, true, &error)
|
2012-08-07 21:55:11 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
2012-08-08 00:44:58 +02:00
|
|
|
handle_find(struct client *client, int argc, char *argv[])
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
2012-08-08 00:44:58 +02:00
|
|
|
return handle_match(client, argc, argv, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_search(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
2012-08-08 00:44:58 +02:00
|
|
|
return handle_match(client, argc, argv, true);
|
2012-08-07 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 00:44:58 +02:00
|
|
|
static enum command_return
|
|
|
|
handle_match_add(struct client *client, int argc, char *argv[], bool fold_case)
|
2012-08-07 21:55:11 +02:00
|
|
|
{
|
|
|
|
struct locate_item_list *list =
|
2012-08-08 00:44:58 +02:00
|
|
|
locate_item_list_parse(argv + 1, argc - 1, fold_case);
|
2012-08-07 23:37:38 +02:00
|
|
|
if (list == NULL) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
2012-08-07 23:59:17 +02:00
|
|
|
enum command_return ret =
|
|
|
|
findAddIn(client->player_control, "", list, &error)
|
2012-08-07 21:55:11 +02:00
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:44:58 +02:00
|
|
|
enum command_return
|
|
|
|
handle_findadd(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return handle_match_add(client, argc, argv, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_searchadd(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
return handle_match_add(client, argc, argv, true);
|
|
|
|
}
|
|
|
|
|
2012-08-07 21:55:11 +02:00
|
|
|
enum command_return
|
|
|
|
handle_searchaddpl(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *playlist = argv[1];
|
|
|
|
|
|
|
|
struct locate_item_list *list =
|
2012-08-07 23:25:42 +02:00
|
|
|
locate_item_list_parse(argv + 2, argc - 2, true);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2012-08-07 23:37:38 +02:00
|
|
|
if (list == NULL) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
|
|
|
search_add_to_playlist("", playlist, list, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_count(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct locate_item_list *list =
|
2012-08-07 23:25:42 +02:00
|
|
|
locate_item_list_parse(argv + 1, argc - 1, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
2012-08-07 23:37:38 +02:00
|
|
|
if (list == NULL) {
|
2012-08-07 21:55:11 +02:00
|
|
|
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
|
|
|
searchStatsForSongsIn(client, "", list, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
|
|
|
locate_item_list_free(list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_listall(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *directory = "";
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
return printAllIn(client, directory, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_list(struct client *client, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct locate_item_list *conditionals;
|
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]);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tagType == LOCATE_TAG_ANY_TYPE) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"\"any\" is not a valid return tag type");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for compatibility with < 0.12.0 */
|
|
|
|
if (argc == 3) {
|
|
|
|
if (tagType != TAG_ALBUM) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"should be \"%s\" for 3 arguments",
|
|
|
|
tag_item_names[TAG_ALBUM]);
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-08-07 23:36:21 +02:00
|
|
|
conditionals =
|
|
|
|
locate_item_list_new_single((unsigned)TAG_ARTIST,
|
|
|
|
argv[2]);
|
2012-08-08 01:16:40 +02:00
|
|
|
} else if (argc > 2) {
|
2012-08-07 21:55:11 +02:00
|
|
|
conditionals =
|
2012-08-07 23:25:42 +02:00
|
|
|
locate_item_list_parse(argv + 2, argc - 2, false);
|
2012-08-07 21:55:11 +02:00
|
|
|
if (conditionals == NULL) {
|
|
|
|
command_error(client, ACK_ERROR_ARG,
|
|
|
|
"not able to parse args");
|
|
|
|
return COMMAND_RETURN_ERROR;
|
|
|
|
}
|
2012-08-08 01:16:40 +02:00
|
|
|
} else
|
|
|
|
conditionals = nullptr;
|
2012-08-07 21:55:11 +02:00
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
enum command_return ret =
|
|
|
|
listAllUniqueTags(client, tagType, conditionals, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
|
2012-08-08 01:16:40 +02:00
|
|
|
if (conditionals != nullptr)
|
|
|
|
locate_item_list_free(conditionals);
|
2012-08-07 21:55:11 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum command_return
|
|
|
|
handle_listallinfo(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|
|
|
{
|
|
|
|
const char *directory = "";
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
directory = argv[1];
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
return printInfoForAllIn(client, directory, &error)
|
|
|
|
? COMMAND_RETURN_OK
|
|
|
|
: print_error(client, error);
|
|
|
|
}
|