playlist/xspf: use tag_table to convert element name to TagType

This commit is contained in:
Max Kellermann 2020-03-11 20:51:47 +01:00
parent 98a7d8da6c
commit 51b1dd8672

View File

@ -23,6 +23,7 @@
#include "song/DetachedSong.hxx"
#include "input/InputStream.hxx"
#include "tag/Builder.hxx"
#include "tag/Table.hxx"
#include "util/StringView.hxx"
#include "lib/expat/ExpatParser.hxx"
#include "Log.hxx"
@ -62,6 +63,19 @@ struct XspfParser {
TagBuilder tag_builder;
};
static constexpr struct tag_table xspf_tag_elements[] = {
{ "title", TAG_TITLE },
/* TAG_COMPOSER would be more correct according to the XSPF
spec */
{ "creator", TAG_ARTIST },
{ "annotation", TAG_COMMENT },
{ "album", TAG_ALBUM },
{ "trackNum", TAG_TRACK },
{ nullptr, TAG_NUM_OF_ITEM_TYPES }
};
static void XMLCALL
xspf_start_element(void *user_data, const XML_Char *element_name,
gcc_unused const XML_Char **atts)
@ -93,18 +107,9 @@ xspf_start_element(void *user_data, const XML_Char *element_name,
case XspfParser::TRACK:
if (strcmp(element_name, "location") == 0)
parser->state = XspfParser::LOCATION;
else if (strcmp(element_name, "title") == 0)
parser->tag_type = TAG_TITLE;
else if (strcmp(element_name, "creator") == 0)
/* TAG_COMPOSER would be more correct
according to the XSPF spec */
parser->tag_type = TAG_ARTIST;
else if (strcmp(element_name, "annotation") == 0)
parser->tag_type = TAG_COMMENT;
else if (strcmp(element_name, "album") == 0)
parser->tag_type = TAG_ALBUM;
else if (strcmp(element_name, "trackNum") == 0)
parser->tag_type = TAG_TRACK;
else
parser->tag_type = tag_table_lookup(xspf_tag_elements,
element_name);
break;