summaryrefslogtreecommitdiff
path: root/libpiano/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-12 22:36:48 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-12 22:36:48 +0200
commitbfda4e40cce3aa986e4fe8d3881a689cd6ef411f (patch)
tree561b24a1e4f3d54f0cc30c4160322e7a9c4bf74d /libpiano/src
parent4878f5911d05af7bfa1917daf984dab0fd07eb42 (diff)
downloadpianobar-windows-bfda4e40cce3aa986e4fe8d3881a689cd6ef411f.tar.gz
pianobar-windows-bfda4e40cce3aa986e4fe8d3881a689cd6ef411f.tar.bz2
pianobar-windows-bfda4e40cce3aa986e4fe8d3881a689cd6ef411f.zip
Initial "narrative" implementation
"Why did you play this song?"
Diffstat (limited to 'libpiano/src')
-rw-r--r--libpiano/src/main.c31
-rw-r--r--libpiano/src/piano.h2
-rw-r--r--libpiano/src/xml.c17
-rw-r--r--libpiano/src/xml.h1
4 files changed, 51 insertions, 0 deletions
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), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>playlist.narrative</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,
+ 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);