TagCommands.cxx 2.01 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "TagCommands.hxx"
21
#include "Request.hxx"
22
#include "client/Client.hxx"
23
#include "client/Response.hxx"
24
#include "tag/ParseName.hxx"
25
#include "queue/Playlist.hxx"
26
#include "util/ConstBuffer.hxx"
27

28 29
#include <fmt/format.h>

30
CommandResult
31
handle_addtagid(Client &client, Request args, Response &r)
32
{
33
	unsigned song_id = args.ParseUnsigned(0);
34

35
	const char *const tag_name = args[1];
36 37
	const TagType tag_type = tag_name_parse_i(tag_name);
	if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
38 39
		r.FmtError(ACK_ERROR_ARG, FMT_STRING("Unknown tag type: {}"),
			   tag_name);
40 41 42
		return CommandResult::ERROR;
	}

43
	const char *const value = args[2];
44

45
	client.GetPlaylist().AddSongIdTag(song_id, tag_type, value);
46 47 48 49
	return CommandResult::OK;
}

CommandResult
50
handle_cleartagid(Client &client, Request args, Response &r)
51
{
52
	unsigned song_id = args.ParseUnsigned(0);
53 54

	TagType tag_type = TAG_NUM_OF_ITEM_TYPES;
55 56
	if (args.size >= 2) {
		const char *const tag_name = args[1];
57 58
		tag_type = tag_name_parse_i(tag_name);
		if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
59 60 61
			r.FmtError(ACK_ERROR_ARG,
				   FMT_STRING("Unknown tag type: {}"),
				   tag_name);
62 63 64 65
			return CommandResult::ERROR;
		}
	}

66
	client.GetPlaylist().ClearSongIdTag(song_id, tag_type);
67 68
	return CommandResult::OK;
}