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 "song/DetachedSong.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
#include "tag/Table.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include "lib/expat/ExpatParser.hxx" #include "lib/expat/ExpatParser.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -62,6 +63,19 @@ struct XspfParser {
TagBuilder tag_builder; 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 static void XMLCALL
xspf_start_element(void *user_data, const XML_Char *element_name, xspf_start_element(void *user_data, const XML_Char *element_name,
gcc_unused const XML_Char **atts) gcc_unused const XML_Char **atts)
@ -93,18 +107,9 @@ xspf_start_element(void *user_data, const XML_Char *element_name,
case XspfParser::TRACK: case XspfParser::TRACK:
if (strcmp(element_name, "location") == 0) if (strcmp(element_name, "location") == 0)
parser->state = XspfParser::LOCATION; parser->state = XspfParser::LOCATION;
else if (strcmp(element_name, "title") == 0) else
parser->tag_type = TAG_TITLE; parser->tag_type = tag_table_lookup(xspf_tag_elements,
else if (strcmp(element_name, "creator") == 0) element_name);
/* 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;
break; break;