summaryrefslogtreecommitdiff
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
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?"
-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
-rw-r--r--src/main.c16
-rw-r--r--src/pianobar.14
6 files changed, 70 insertions, 1 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);
diff --git a/src/main.c b/src/main.c
index 67e9319..a2a169d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -511,7 +511,7 @@ int main (int argc, char **argv) {
/* in the meantime: wait for user actions */
struct pollfd polls = {fileno (stdin), POLLIN, POLLIN};
char buf, yesnoBuf;
- char *lineBuf, *musicId;
+ char *lineBuf, *musicId, *explanation;
PianoStation_t *moveStation;
if (poll (&polls, 1, 1000) > 0) {
@@ -522,6 +522,7 @@ int main (int argc, char **argv) {
"b\tban current song\n"
"c\tcreate new station\n"
"d\tdelete current station\n"
+ "e\texplain why this song is played\n"
"g\tadd genre station\n"
"l\tlove current song\n"
"n\tnext song\n"
@@ -597,6 +598,19 @@ int main (int argc, char **argv) {
}
break;
+ case 'e':
+ if (curSong == NULL) {
+ BarUiMsg ("No song playing.\n");
+ break;
+ }
+ BarUiMsg ("Receiving explanation... ");
+ if (BarUiPrintPianoStatus (PianoExplain (&ph, curSong,
+ &explanation)) == PIANO_RET_OK) {
+ printf ("%s\n", explanation);
+ free (explanation);
+ }
+ break;
+
case 'g':
/* use genre station */
BarStationFromGenre (&ph);
diff --git a/src/pianobar.1 b/src/pianobar.1
index 5cf9983..bd0db3c 100644
--- a/src/pianobar.1
+++ b/src/pianobar.1
@@ -35,6 +35,10 @@ artist of your choice.
Delete current station.
.TP
+.B e
+Explain why this song is played.
+
+.TP
.B g
Add genre station provided by pandora.