From bfda4e40cce3aa986e4fe8d3881a689cd6ef411f Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 12 Aug 2008 22:36:48 +0200 Subject: Initial "narrative" implementation "Why did you play this song?" --- libpiano/src/main.c | 31 +++++++++++++++++++++++++++++++ libpiano/src/piano.h | 2 ++ libpiano/src/xml.c | 17 +++++++++++++++++ libpiano/src/xml.h | 1 + 4 files changed, 51 insertions(+) (limited to 'libpiano/src') diff --git a/libpiano/src/main.c b/libpiano/src/main.c index 7887132..2b51303 100644 --- a/libpiano/src/main.c +++ b/libpiano/src/main.c @@ -779,6 +779,37 @@ PianoReturn_t PianoTransformShared (PianoHandle_t *ph, return ret; } +PianoReturn_t PianoExplain (const PianoHandle_t *ph, const PianoSong_t *song, + char **retExplain) { + char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + PianoReturn_t ret; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "" + "playlist.narrative" + "%li" + "%s" + "%s" + "%s" + "", time (NULL), ph->user.authToken, + song->stationId, song->musicId); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&" + "method=method=narrative&arg1=%s&arg2=%s", ph->routeId, + ph->user.listenerId, song->stationId, song->musicId); + + if ((ret = PianoHttpPost (ph->curlHandle, url, requestStr, &retStr)) == + PIANO_RET_OK) { + ret = PianoXmlParseNarrative (retStr, retExplain); + PianoFree (retStr, 0); + } + + PianoFree (requestStr, 0); + + return ret; +} + /* convert return value to human-readable string * @param enum * @return error string diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h index 3a7c740..b0e741e 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -186,6 +186,8 @@ PianoStation_t *PianoFindStationById (PianoStation_t *stations, PianoReturn_t PianoGetGenreStations (PianoHandle_t *ph); PianoReturn_t PianoTransformShared (PianoHandle_t *ph, PianoStation_t *station); +PianoReturn_t PianoExplain (const PianoHandle_t *ph, const PianoSong_t *song, + char **retExplain); const char *PianoErrorToStr (PianoReturn_t ret); #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index c0d388f..6d4dad8 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -744,3 +744,20 @@ PianoReturn_t PianoXmlParseTranformStation (const char *searchXml) { return PIANO_RET_OK; } + +PianoReturn_t PianoXmlParseNarrative (const char *xml, char **retNarrative) { + xmlNode *docRoot; + xmlDocPtr doc; + PianoReturn_t ret; + + if ((ret = PianoXmlInitDoc (xml, &doc, &docRoot)) != PIANO_RET_OK) { + return ret; + } + + xmlNode *val = docRoot->children->children->children->children; + *retNarrative = strdup ((char *) val->content); + + xmlFreeDoc (doc); + + return ret; +} diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h index 5ee7e7c..2d44ab3 100644 --- a/libpiano/src/xml.h +++ b/libpiano/src/xml.h @@ -38,6 +38,7 @@ PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, const char *xml, PianoReturn_t PianoXmlParseGenreExplorer (PianoHandle_t *ph, const char *xmlContent); PianoReturn_t PianoXmlParseTranformStation (const char *searchXml); +PianoReturn_t PianoXmlParseNarrative (const char *xml, char **retNarrative); char *PianoXmlEncodeString (const char *s); -- cgit v1.2.3