summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-07-02 20:46:38 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-07-02 20:46:38 +0200
commita711635a5a031107da3ecc0b0e1c939277e34572 (patch)
treec4f607888402c8d9d62640ab1e47c087fd3f1797
parente3c2af78adaef60de935883bac1155b0e75d4ae1 (diff)
downloadpianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.tar.gz
pianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.tar.bz2
pianobar-windows-a711635a5a031107da3ecc0b0e1c939277e34572.zip
client: Initial quickmix station selection support
-rw-r--r--libpiano/src/main.c57
-rw-r--r--libpiano/src/piano.h6
-rw-r--r--libpiano/src/xml.c2
-rw-r--r--src/main.c24
-rw-r--r--src/pianobar.14
5 files changed, 89 insertions, 4 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);
}
}
diff --git a/src/main.c b/src/main.c
index 8a96129..744c731 100644
--- a/src/main.c
+++ b/src/main.c
@@ -85,7 +85,8 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph) {
printf ("which station do you want to listen to?\n");
curStation = ph->stations;
while (curStation != NULL) {
- printf ("%2i) %s\n", i, curStation->name);
+ printf ("%2i) %s%s\n", i, curStation->name,
+ curStation->useQuickMix ? " (QuickMix)" : "");
curStation = curStation->next;
i++;
}
@@ -376,7 +377,8 @@ int main (int argc, char **argv) {
"r\trename current station\n"
"s\tchange station\n"
"t\ttired (ban song for 1 month)\n"
- "u\tupcoming songs\n");
+ "u\tupcoming songs\n"
+ "x\tselect quickmix stations\n");
break;
case 'a':
@@ -562,6 +564,24 @@ int main (int argc, char **argv) {
nextSong = nextSong->next;
}
break;
+
+ case 'x':
+ if (curStation->isQuickMix) {
+ PianoStation_t *selStation;
+ while ((selStation =
+ BarUiSelectStation (&ph)) != NULL) {
+ selStation->useQuickMix = !selStation->useQuickMix;
+ }
+ BarUiMsg ("Setting quickmix stations... ");
+ if (PianoSetQuickmix (&ph) == PIANO_RET_OK) {
+ BarUiMsg ("Ok.\n");
+ } else {
+ BarUiMsg ("Error.\n");
+ }
+ } else {
+ BarUiMsg ("Not a QuickMix station.\n");
+ }
+ break;
} /* end case */
} /* end poll */
diff --git a/src/pianobar.1 b/src/pianobar.1
index bcd5f21..99c04e7 100644
--- a/src/pianobar.1
+++ b/src/pianobar.1
@@ -67,6 +67,10 @@ Ban song for one month.
.B u
Show next songs in playlist.
+.TP
+.B x
+Select quickmix stations.
+
.SH FILES
.I $XDG_CONFIG_HOME/pianobar/config
or