2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2013-12-02 12:00:32 +01:00
|
|
|
|
|
|
|
#include "TagCommands.hxx"
|
2015-08-11 22:11:28 +02:00
|
|
|
#include "Request.hxx"
|
2014-01-24 00:26:53 +01:00
|
|
|
#include "client/Client.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "client/Response.hxx"
|
2017-02-08 08:57:22 +01:00
|
|
|
#include "tag/ParseName.hxx"
|
2023-03-06 15:17:41 +01:00
|
|
|
#include "tag/Type.hxx"
|
2019-07-05 09:59:00 +02:00
|
|
|
#include "queue/Playlist.hxx"
|
2013-12-02 12:00:32 +01:00
|
|
|
|
2021-05-25 16:11:35 +02:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2013-12-02 12:00:32 +01:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_addtagid(Client &client, Request args, Response &r)
|
2013-12-02 12:00:32 +01:00
|
|
|
{
|
2015-12-18 09:50:48 +01:00
|
|
|
unsigned song_id = args.ParseUnsigned(0);
|
2013-12-02 12:00:32 +01:00
|
|
|
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const tag_name = args[1];
|
2013-12-02 12:00:32 +01:00
|
|
|
const TagType tag_type = tag_name_parse_i(tag_name);
|
|
|
|
if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
2021-05-25 16:11:35 +02:00
|
|
|
r.FmtError(ACK_ERROR_ARG, FMT_STRING("Unknown tag type: {}"),
|
|
|
|
tag_name);
|
2013-12-02 12:00:32 +01:00
|
|
|
return CommandResult::ERROR;
|
|
|
|
}
|
|
|
|
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const value = args[2];
|
2013-12-02 12:00:32 +01:00
|
|
|
|
2017-02-20 12:44:09 +01:00
|
|
|
client.GetPlaylist().AddSongIdTag(song_id, tag_type, value);
|
2013-12-02 12:00:32 +01:00
|
|
|
return CommandResult::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_cleartagid(Client &client, Request args, Response &r)
|
2013-12-02 12:00:32 +01:00
|
|
|
{
|
2015-12-18 09:50:48 +01:00
|
|
|
unsigned song_id = args.ParseUnsigned(0);
|
2013-12-02 12:00:32 +01:00
|
|
|
|
|
|
|
TagType tag_type = TAG_NUM_OF_ITEM_TYPES;
|
2022-07-04 18:38:57 +02:00
|
|
|
if (args.size() >= 2) {
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const tag_name = args[1];
|
2013-12-02 12:00:32 +01:00
|
|
|
tag_type = tag_name_parse_i(tag_name);
|
|
|
|
if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
|
2021-05-25 16:11:35 +02:00
|
|
|
r.FmtError(ACK_ERROR_ARG,
|
|
|
|
FMT_STRING("Unknown tag type: {}"),
|
|
|
|
tag_name);
|
2013-12-02 12:00:32 +01:00
|
|
|
return CommandResult::ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 12:44:09 +01:00
|
|
|
client.GetPlaylist().ClearSongIdTag(song_id, tag_type);
|
2013-12-02 12:00:32 +01:00
|
|
|
return CommandResult::OK;
|
|
|
|
}
|