diff options
author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-07-02 20:46:38 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-07-02 20:46:38 +0200 |
commit | a711635a5a031107da3ecc0b0e1c939277e34572 (patch) | |
tree | c4f607888402c8d9d62640ab1e47c087fd3f1797 /libpiano/src | |
parent | e3c2af78adaef60de935883bac1155b0e75d4ae1 (diff) | |
download | pianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.tar.gz pianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.tar.bz2 pianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.zip |
client: Initial quickmix station selection support
Diffstat (limited to 'libpiano/src')
-rw-r--r-- | libpiano/src/main.c | 57 | ||||
-rw-r--r-- | libpiano/src/piano.h | 6 | ||||
-rw-r--r-- | libpiano/src/xml.c | 2 |
3 files changed, 63 insertions, 2 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c index 29af6e0..d8d9498 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -596,3 +596,60 @@ PianoReturn_t PianoSongTired (PianoHandle_t *ph, PianoSong_t *song) { return ret; } + +/* set stations use by quickmix + * @param piano handle + * @return _OK or error + */ +PianoReturn_t PianoSetQuickmix (PianoHandle_t *ph) { + char xmlSendBuf[10000], valueBuf[1000], urlArgBuf[1000], + url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + PianoReturn_t ret; + PianoStation_t *curStation = ph->stations; + + memset (urlArgBuf, 0, sizeof (urlArgBuf)); + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.setQuickMix</methodName><params>" + "<param><value><int>%li</int></value></param>" + "<param><value><string>%s</string></value></param>" + "<param><value><string>RANDOM</string></value></param>" + "<param><value><array><data>", time (NULL), ph->user.authToken); + while (curStation != NULL) { + /* quick mix can't contain itself */ + if (!curStation->useQuickMix || curStation->isQuickMix) { + curStation = curStation->next; + continue; + } + /* append to xml doc */ + snprintf (valueBuf, sizeof (valueBuf), + "<value><string>%s</string></value>", curStation->id); + strncat (xmlSendBuf, valueBuf, sizeof (xmlSendBuf) - + strlen (xmlSendBuf) - 1); + /* append to url arg */ + strncat (urlArgBuf, curStation->id, sizeof (urlArgBuf) - + strlen (urlArgBuf) - 1); + curStation = curStation->next; + /* if not last item: append "," */ + if (curStation != NULL) { + strncat (urlArgBuf, "%2C", sizeof (urlArgBuf) - + strlen (urlArgBuf) - 1); + } + } + strncat (xmlSendBuf, + "</data></array></value></param></params></methodCall>", + sizeof (xmlSendBuf) - strlen (xmlSendBuf) - 1); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&" + "method=setQuickMix&arg1=RANDOM&arg2=%s", ph->routeId, + ph->user.listenerId, urlArgBuf); + + PianoHttpPost (ph->curlHandle, url, requestStr, &retStr); + ret = PianoXmlParseSimple (retStr); + + PianoFree (retStr, 0); + PianoFree (requestStr, 0); + + return ret; +} diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h index 121f0db..93c9fc1 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -23,7 +23,7 @@ THE SOFTWARE. #ifndef _PIANO_H #define _PIANO_H -/* this is our public API; don't expect this api to be stable, as long +/* this is our public API; don't expect this api to be stable as long as * pandora does not provide a stable api * all strings _must_ be utf-8 encoded. i won't care, but pandora does. so * be nice and check the encoding of your strings. thanks :) */ @@ -61,7 +61,8 @@ struct PianoStation { /* disabled: isNew */ /* disabled: transformType */ //char *idToken; - //char isQuickMix; + char isQuickMix; + char useQuickMix; /* station will be included in quickmix */ char *name; char *id; struct PianoStation *next; @@ -167,5 +168,6 @@ PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId); PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph, PianoStation_t *station, char *musicId); PianoReturn_t PianoSongTired (PianoHandle_t *ph, PianoSong_t *song); +PianoReturn_t PianoSetQuickmix (PianoHandle_t *ph); #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index 3879f4a..ecd3394 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -210,6 +210,8 @@ void PianoXmlParseStationsCb (char *key, xmlNode *value, void *data) { station->name = strdup (valueStr); } else if (strcmp ("stationId", key) == 0) { station->id = strdup (valueStr); + } else if (strcmp ("isQuickMix", key) == 0) { + station->isQuickMix = (strcmp (valueStr, "1") == 0); } } |