summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-25 14:49:58 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-25 14:50:54 +0200
commita39f7626758a7d26c1bc419b1eaa46cbfee5ecaa (patch)
tree39828b6b9b2d0c3f3859cbd7a3eaa022c1fa3660
parentaf2ceec1e540bae28fdd3ec07158dcd137d3c9da (diff)
downloadpianobar-windows-a39f7626758a7d26c1bc419b1eaa46cbfee5ecaa.tar.gz
pianobar-windows-a39f7626758a7d26c1bc419b1eaa46cbfee5ecaa.tar.bz2
pianobar-windows-a39f7626758a7d26c1bc419b1eaa46cbfee5ecaa.zip
piano/client: Initial ban-for-a-month implementation
Use it when you're tired of hearing a single song again and again...
-rw-r--r--libpiano/src/main.c33
-rw-r--r--libpiano/src/piano.h3
-rw-r--r--libpiano/src/xml.c2
-rw-r--r--src/main.c15
-rw-r--r--src/pianobar.14
5 files changed, 55 insertions, 2 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index 7cb9ad4..29af6e0 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -140,6 +140,7 @@ void PianoDestroyPlaylist (PianoHandle_t *ph) {
PianoFree (curSong->musicId, 0);
PianoFree (curSong->title, 0);
PianoFree (curSong->userSeed, 0);
+ PianoFree (curSong->identity, 0);
lastSong = curSong;
curSong = curSong->next;
PianoFree (lastSong, sizeof (*lastSong));
@@ -563,3 +564,35 @@ PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph,
return ret;
}
+
+/* ban a song temporary (for one month)
+ * @param piano handle
+ * @param song to be banned
+ * @return _OK or error
+ */
+PianoReturn_t PianoSongTired (PianoHandle_t *ph, PianoSong_t *song) {
+ char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE];
+ char *requestStr, *retStr;
+ PianoReturn_t ret;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>listener.addTiredSong</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,
+ song->identity);
+ requestStr = PianoEncryptString (xmlSendBuf);
+
+ snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s&"
+ "method=addTiredSong&arg1=%s", ph->routeId, ph->user.listenerId,
+ song->identity);
+
+ 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 54c54dd..121f0db 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -101,7 +101,7 @@ struct PianoSong {
char *musicId;
char *title;
char *focusTraitId;
- //char *identity;
+ char *identity;
//int score; /* only used for search results */
struct PianoSong *next;
};
@@ -166,5 +166,6 @@ PianoReturn_t PianoSearchMusic (PianoHandle_t *ph, char *searchStr,
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);
#endif /* _PIANO_H */
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 2613f40..3879f4a 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -243,6 +243,8 @@ void PianoXmlParsePlaylistCb (char *key, xmlNode *value, void *data) {
song->focusTraitId = strdup (valueStr);
} else if (strcmp ("songTitle", key) == 0) {
song->title = strdup (valueStr);
+ } else if (strcmp ("identity", key) == 0) {
+ song->identity = strdup (valueStr);
} else if (strcmp ("rating", key) == 0) {
if (strcmp (valueStr, "1") == 0) {
song->rating = PIANO_RATE_LOVE;
diff --git a/src/main.c b/src/main.c
index f6dde4e..ad0049f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -362,7 +362,8 @@ int main (int argc, char **argv) {
"p\tpause/continue\n"
"q\tquit\n"
"r\trename current station\n"
- "s\tchange station\n");
+ "s\tchange station\n"
+ "t\ttired (ban song for 1 month)\n");
break;
case 'a':
@@ -494,6 +495,18 @@ int main (int argc, char **argv) {
printf ("Changed station to %s\n", curStation->name);
}
break;
+
+ case 't':
+ printf ("Putting song on shelf... ");
+ fflush (stdout);
+ if (PianoSongTired (&ph, curSong) == PIANO_RET_OK) {
+ printf ("Ok.\n");
+ player.doQuit = 1;
+ } else {
+ printf ("Error.\n");
+ }
+ break;
+
} /* end case */
} /* end poll */
diff --git a/src/pianobar.1 b/src/pianobar.1
index 6201d8c..af9751a 100644
--- a/src/pianobar.1
+++ b/src/pianobar.1
@@ -59,6 +59,10 @@ Rename currently played station.
.B s
Play another station.
+.TP
+.B t
+Ban song for one month.
+
.SH FILES
.I $XDG_CONFIG_HOME/pianobar/config
or