diff options
author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-07-17 15:53:01 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-07-17 15:53:01 +0200 |
commit | 7c96aa41979b1c1b0b4c582c8ac31b7ff779b737 (patch) | |
tree | 125ea492c67f2bbf0d3e2b81e935de2c2376dc5d /libpiano/src/xml.c | |
parent | 6b0824285abab829cf97de770c9051a60255106e (diff) | |
download | pianobar-7c96aa41979b1c1b0b4c582c8ac31b7ff779b737.tar.gz pianobar-7c96aa41979b1c1b0b4c582c8ac31b7ff779b737.tar.bz2 pianobar-7c96aa41979b1c1b0b4c582c8ac31b7ff779b737.zip |
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.
Diffstat (limited to 'libpiano/src/xml.c')
-rw-r--r-- | libpiano/src/xml.c | 85 |
1 files changed, 85 insertions, 0 deletions
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 <member> 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; +} |