diff options
author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-19 15:49:23 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-19 15:49:23 +0200 |
commit | 880a0446c465d22ea3e36db838b8df1e594fa4da (patch) | |
tree | 150d66a02b7f99b193b6dda816896d15a190cd5a /libpiano/src | |
parent | 3e76f37c014f867f3b99e482ecb071884322f5d3 (diff) | |
download | pianobar-windows-880a0446c465d22ea3e36db838b8df1e594fa4da.tar.gz pianobar-windows-880a0446c465d22ea3e36db838b8df1e594fa4da.tar.bz2 pianobar-windows-880a0446c465d22ea3e36db838b8df1e594fa4da.zip |
"Add more music" implemented
This can add more track/artist seeds to the currently played station
Diffstat (limited to 'libpiano/src')
-rw-r--r-- | libpiano/src/main.c | 38 | ||||
-rw-r--r-- | libpiano/src/piano.h | 2 | ||||
-rw-r--r-- | libpiano/src/xml.c | 25 | ||||
-rw-r--r-- | libpiano/src/xml.h | 2 |
4 files changed, 67 insertions, 0 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c index 99daee1..1d5a6d0 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -464,3 +464,41 @@ PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId) { return ret; } + +/* FIXME: update station data instead of replacing them */ +/* add more music to existing station; multithreaded apps beware! this alters + * station data, don't forget to lock the station pointer you passed to this + * function + * @public yes + * @param piano handle + * @param add music to this station + * @param music id; can be obtained with PianoSearchMusic () + */ +PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph, + PianoStation_t *station, char *musicId) { + char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + PianoReturn_t ret; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.addSeed</methodName><params>" + "<param><value><int>%li</int></value></param>" + "<param><value><string>%s</string></value></param>" + "<param><value><string>%s</string></value></param>" + "<param><value><string>%s</string></value></param>" + "</params></methodCall>", time (NULL), ph->user.authToken, + station->id, musicId); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s" + "&method=addSeed&arg1=%s&arg2=%s", ph->routeId, + ph->user.listenerId, station->id, musicId); + + PianoHttpPost (ph->curlHandle, url, requestStr, &retStr); + ret = PianoXmlParseAddSeed (ph, retStr, station); + + free (requestStr); + free (retStr); + + return ret; +} diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h index bd90c4c..f2b8f95 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -162,5 +162,7 @@ PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station); PianoReturn_t PianoSearchMusic (PianoHandle_t *ph, char *searchStr, PianoSearchResult_t *searchResult); PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId); +PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph, + PianoStation_t *station, char *musicId); #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index 1267951..2d9e82d 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -348,6 +348,31 @@ PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml) { return PIANO_RET_OK; } +/* parse "add seed" answer, nearly the same as ParseCreateStation + * @param piano handle + * @param xml document + * @param update this station + */ +PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml, + PianoStation_t *station) { + xmlNode *docRoot; + xmlDocPtr doc; + PianoReturn_t ret; + + if ((ret = PianoXmlInitDoc (xml, &doc, &docRoot)) != PIANO_RET_OK) { + return ret; + } + + /* get <struct> node */ + xmlNode *dataRoot = docRoot->children->children->children->children; + PianoDestroyStation (station); + PianoXmlStructParser (dataRoot, PianoXmlParseStationsCb, station); + + xmlFreeDoc (doc); + + return PIANO_RET_OK; +} + /* parses playlist; used when searching too * @param piano handle * @param xml document diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h index 1165f12..ebc2df7 100644 --- a/libpiano/src/xml.h +++ b/libpiano/src/xml.h @@ -32,6 +32,8 @@ PianoReturn_t PianoXmlParseSearch (char *searchXml, PianoSearchResult_t *searchResult); PianoReturn_t PianoXmlParseSimple (char *xml); PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml); +PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml, + PianoStation_t *station); char *PianoXmlEncodeString (const char *s); |