From 7c96aa41979b1c1b0b4c582c8ac31b7ff779b737 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 17 Jul 2008 15:53:01 +0200 Subject: piano: Initial global genre stations support Pandora provides a xml list of genre stations. Read this list and insert its data into our PianoHandle tree if requested. --- libpiano/src/xml.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'libpiano/src/xml.c') diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index a144255..91bb120 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -574,3 +574,88 @@ char *PianoXmlEncodeString (const char *s) { } return sOut; } + +PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph, + char *xmlContent) { + xmlNode *docRoot, *catNode, *genreNode, *attrNodeValue; + xmlDocPtr doc; + xmlAttr *attrNode; + PianoReturn_t ret; + PianoGenreCategory_t *tmpGenreCategory; + PianoStation_t *tmpStation; + + if ((ret = PianoXmlInitDoc (xmlContent, &doc, &docRoot)) != + PIANO_RET_OK) { + return ret; + } + + /* get all nodes */ + for (catNode = docRoot->children; catNode; catNode = catNode->next) { + if (catNode->type == XML_ELEMENT_NODE && + xmlStrEqual ((xmlChar *) "category", catNode->name)) { + tmpGenreCategory = calloc (1, sizeof (*tmpGenreCategory)); + /* get category attributes */ + for (attrNode = catNode->properties; attrNode; + attrNode = attrNode->next) { + for (attrNodeValue = attrNode->children; attrNodeValue; + attrNodeValue = attrNodeValue->next) { + if (attrNodeValue->type == XML_TEXT_NODE && + xmlStrEqual (attrNode->name, + (xmlChar *) "categoryName")) { + tmpGenreCategory->name = + strdup ((char *) attrNodeValue->content); + } + } + } + /* get genre subnodes */ + for (genreNode = catNode->children; genreNode; + genreNode = genreNode->next) { + if (genreNode->type == XML_ELEMENT_NODE && + xmlStrEqual ((xmlChar *) "genre", genreNode->name)) { + tmpStation = calloc (1, sizeof (*tmpStation)); + /* get genre attributes */ + for (attrNode = genreNode->properties; attrNode; + attrNode = attrNode->next) { + for (attrNodeValue = attrNode->children; attrNodeValue; + attrNodeValue = attrNodeValue->next) { + if (attrNodeValue->type == XML_TEXT_NODE) { + if (xmlStrEqual (attrNode->name, + (xmlChar *) "name")) { + tmpStation->name = strdup ((char *) attrNodeValue->content); + } else if (xmlStrEqual (attrNode->name, + (xmlChar *) "stationId")) { + tmpStation->id = strdup ((char *) attrNodeValue->content); + } + } + } + } + /* append station */ + if (tmpGenreCategory->stations == NULL) { + tmpGenreCategory->stations = tmpStation; + } else { + PianoStation_t *curStation = + tmpGenreCategory->stations; + while (curStation->next != NULL) { + curStation = curStation->next; + } + curStation->next = tmpStation; + } + } + } + /* append category */ + if (ph->genreStations == NULL) { + ph->genreStations = tmpGenreCategory; + } else { + PianoGenreCategory_t *curCat = ph->genreStations; + while (curCat->next != NULL) { + curCat = curCat->next; + } + curCat->next = tmpGenreCategory; + } + } + } + + xmlFreeDoc (doc); + + return PIANO_RET_OK; +} -- cgit v1.2.3