playlist/rss: use class TagBuilder

This commit is contained in:
Max Kellermann 2013-12-03 12:25:22 +01:00
parent b4f60ee95c
commit 73a861abf1

View File

@ -23,7 +23,7 @@
#include "MemorySongEnumerator.hxx" #include "MemorySongEnumerator.hxx"
#include "InputStream.hxx" #include "InputStream.hxx"
#include "Song.hxx" #include "Song.hxx"
#include "tag/Tag.hxx" #include "tag/TagBuilder.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
@ -65,6 +65,8 @@ struct RssParser {
*/ */
Song *song; Song *song;
TagBuilder tag_builder;
RssParser() RssParser()
:state(ROOT) {} :state(ROOT) {}
}; };
@ -105,18 +107,14 @@ rss_start_element(gcc_unused GMarkupParseContext *context,
attribute_values, attribute_values,
"url"); "url");
if (href != nullptr) { if (href != nullptr) {
/* create new song object, and copy /* create new song object; we cannot
the existing tag over; we cannot
replace the existing song's URI, replace the existing song's URI,
because that attribute is because that attribute is
immutable */ immutable */
Song *song = Song::NewRemote(href); Song *song = Song::NewRemote(href);
if (parser->song != nullptr) { if (parser->song != nullptr)
song->tag = parser->song->tag;
parser->song->tag = nullptr;
parser->song->Free(); parser->song->Free();
}
parser->song = song; parser->song = song;
} }
@ -142,9 +140,11 @@ rss_end_element(gcc_unused GMarkupParseContext *context,
case RssParser::ITEM: case RssParser::ITEM:
if (StringEqualsCaseASCII(element_name, "item")) { if (StringEqualsCaseASCII(element_name, "item")) {
if (strcmp(parser->song->uri, "rss:") != 0) if (strcmp(parser->song->uri, "rss:") != 0) {
assert(parser->song->tag == nullptr);
parser->song->tag = parser->tag_builder.Commit();
parser->songs.emplace_front(parser->song); parser->songs.emplace_front(parser->song);
else } else
parser->song->Free(); parser->song->Free();
parser->state = RssParser::ROOT; parser->state = RssParser::ROOT;
@ -167,12 +167,9 @@ rss_text(gcc_unused GMarkupParseContext *context,
break; break;
case RssParser::ITEM: case RssParser::ITEM:
if (parser->tag_type != TAG_NUM_OF_ITEM_TYPES) { if (parser->tag_type != TAG_NUM_OF_ITEM_TYPES)
if (parser->song->tag == nullptr) parser->tag_builder.AddItem(parser->tag_type,
parser->song->tag = new Tag(); text, text_len);
parser->song->tag->AddItem(parser->tag_type,
text, text_len);
}
break; break;
} }