diff options
-rw-r--r-- | libpiano/src/main.c | 41 | ||||
-rw-r--r-- | libpiano/src/piano.h | 4 | ||||
-rw-r--r-- | libpiano/src/xml.c | 20 | ||||
-rw-r--r-- | libpiano/src/xml.h | 1 | ||||
-rw-r--r-- | src/main.c | 20 |
5 files changed, 85 insertions, 1 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c index d5fa0e7..a4beefd 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -734,3 +734,44 @@ PianoReturn_t PianoGetGenreStations (PianoHandle_t *ph) { return ret; } + +/* make shared stations private, needed to rate songs played on shared + * stations + * @param piano handle + * @param station to transform + * @return _OK or error + */ +PianoReturn_t PianoTransformShared (PianoHandle_t *ph, + PianoStation_t *station) { + char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + PianoReturn_t ret; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.transformShared</methodName>" + "<params><param><value><int>%li</int></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); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&" + "method=transformShared&arg1=%s", ph->routeId, ph->user.listenerId, + station->id); + + if ((ret = PianoHttpPost (ph->curlHandle, url, requestStr, &retStr)) == + PIANO_RET_OK) { + ret = PianoXmlParseTranformStation (retStr); + /* though this call returns a bunch of "new" data only this one is + * changed and important (at the moment) */ + if (ret == PIANO_RET_OK) { + station->isCreator = 1; + } + PianoFree (retStr, 0); + } + + PianoFree (requestStr, 0); + + return ret; +} diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h index 07b9791..172c13d 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -53,7 +53,7 @@ struct PianoUserInfo { typedef struct PianoUserInfo PianoUserInfo_t; struct PianoStation { - //char isCreator; + char isCreator; /* disabled: originalStationId */ //char **genre; //unsigned int originalCreatorId; @@ -183,5 +183,7 @@ PianoReturn_t PianoSetQuickmix (PianoHandle_t *ph); PianoStation_t *PianoFindStationById (PianoStation_t *stations, char *searchStation); PianoReturn_t PianoGetGenreStations (PianoHandle_t *ph); +PianoReturn_t PianoTransformShared (PianoHandle_t *ph, + PianoStation_t *station); #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index 91bb120..d0faca6 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -212,6 +212,8 @@ void PianoXmlParseStationsCb (char *key, xmlNode *value, void *data) { station->id = strdup (valueStr); } else if (strcmp ("isQuickMix", key) == 0) { station->isQuickMix = (strcmp (valueStr, "1") == 0); + } else if (strcmp ("isCreator", key) == 0) { + station->isCreator = (strcmp (valueStr, "1") == 0); } } @@ -659,3 +661,21 @@ PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph, return PIANO_RET_OK; } + +/* dummy function, only checks for errors + * @param xml doc + * @return _OK or error + */ +PianoReturn_t PianoXmlParseTranformStation (char *searchXml) { + xmlNode *docRoot; + xmlDocPtr doc; + PianoReturn_t ret; + + if ((ret = PianoXmlInitDoc (searchXml, &doc, &docRoot)) != PIANO_RET_OK) { + return ret; + } + + xmlFreeDoc (doc); + + return PIANO_RET_OK; +} diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h index 8a4e613..95d9d93 100644 --- a/libpiano/src/xml.h +++ b/libpiano/src/xml.h @@ -36,6 +36,7 @@ PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml, PianoStation_t *station); PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph, char *xmlContent); +PianoReturn_t PianoXmlParseTranformStation (char *searchXml); char *PianoXmlEncodeString (const char *s); @@ -483,6 +483,16 @@ int main (int argc, char **argv) { BarUiMsg ("No song playing.\n"); break; } + if (!curStation->isCreator) { + BarUiMsg ("Transforming station... "); + if (PianoTransformShared (&ph, curStation) == + PIANO_RET_OK) { + BarUiMsg ("Ok.\n"); + } else { + BarUiMsg ("Error.\n"); + break; + } + } BarUiMsg ("Banning song... "); if (PianoRateTrack (&ph, curSong, PIANO_RATE_BAN) == PIANO_RET_OK) { @@ -546,6 +556,16 @@ int main (int argc, char **argv) { BarUiMsg ("Already loved. No need to do this twice.\n"); break; } + if (!curStation->isCreator) { + BarUiMsg ("Transforming station... "); + if (PianoTransformShared (&ph, curStation) == + PIANO_RET_OK) { + BarUiMsg ("Ok.\n"); + } else { + BarUiMsg ("Error.\n"); + break; + } + } BarUiMsg ("Loving song... "); if (PianoRateTrack (&ph, curSong, PIANO_RATE_LOVE) == PIANO_RET_OK) { |