summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-19 15:49:23 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-06-19 15:49:23 +0200
commit880a0446c465d22ea3e36db838b8df1e594fa4da (patch)
tree150d66a02b7f99b193b6dda816896d15a190cd5a
parent3e76f37c014f867f3b99e482ecb071884322f5d3 (diff)
downloadpianobar-880a0446c465d22ea3e36db838b8df1e594fa4da.tar.gz
pianobar-880a0446c465d22ea3e36db838b8df1e594fa4da.tar.bz2
pianobar-880a0446c465d22ea3e36db838b8df1e594fa4da.zip
"Add more music" implemented
This can add more track/artist seeds to the currently played station
-rw-r--r--libpiano/src/main.c38
-rw-r--r--libpiano/src/piano.h2
-rw-r--r--libpiano/src/xml.c25
-rw-r--r--libpiano/src/xml.h2
-rw-r--r--src/main.c95
5 files changed, 125 insertions, 37 deletions
diff --git a/libpiano/src/main.c b/libpiano/src/main.c
index 99daee1..1d5a6d0 100644
--- a/libpiano/src/main.c
+++ b/libpiano/src/main.c
@@ -464,3 +464,41 @@ PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId) {
return ret;
}
+
+/* FIXME: update station data instead of replacing them */
+/* add more music to existing station; multithreaded apps beware! this alters
+ * station data, don't forget to lock the station pointer you passed to this
+ * function
+ * @public yes
+ * @param piano handle
+ * @param add music to this station
+ * @param music id; can be obtained with PianoSearchMusic ()
+ */
+PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph,
+ PianoStation_t *station, char *musicId) {
+ char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE];
+ char *requestStr, *retStr;
+ PianoReturn_t ret;
+
+ snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>"
+ "<methodCall><methodName>station.addSeed</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,
+ station->id, musicId);
+ requestStr = PianoEncryptString (xmlSendBuf);
+
+ snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s"
+ "&method=addSeed&arg1=%s&arg2=%s", ph->routeId,
+ ph->user.listenerId, station->id, musicId);
+
+ PianoHttpPost (ph->curlHandle, url, requestStr, &retStr);
+ ret = PianoXmlParseAddSeed (ph, retStr, station);
+
+ free (requestStr);
+ free (retStr);
+
+ return ret;
+}
diff --git a/libpiano/src/piano.h b/libpiano/src/piano.h
index bd90c4c..f2b8f95 100644
--- a/libpiano/src/piano.h
+++ b/libpiano/src/piano.h
@@ -162,5 +162,7 @@ PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station);
PianoReturn_t PianoSearchMusic (PianoHandle_t *ph, char *searchStr,
PianoSearchResult_t *searchResult);
PianoReturn_t PianoCreateStation (PianoHandle_t *ph, char *musicId);
+PianoReturn_t PianoStationAddMusic (PianoHandle_t *ph,
+ PianoStation_t *station, char *musicId);
#endif /* _PIANO_H */
diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c
index 1267951..2d9e82d 100644
--- a/libpiano/src/xml.c
+++ b/libpiano/src/xml.c
@@ -348,6 +348,31 @@ PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml) {
return PIANO_RET_OK;
}
+/* parse "add seed" answer, nearly the same as ParseCreateStation
+ * @param piano handle
+ * @param xml document
+ * @param update this station
+ */
+PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml,
+ PianoStation_t *station) {
+ xmlNode *docRoot;
+ xmlDocPtr doc;
+ PianoReturn_t ret;
+
+ if ((ret = PianoXmlInitDoc (xml, &doc, &docRoot)) != PIANO_RET_OK) {
+ return ret;
+ }
+
+ /* get <struct> node */
+ xmlNode *dataRoot = docRoot->children->children->children->children;
+ PianoDestroyStation (station);
+ PianoXmlStructParser (dataRoot, PianoXmlParseStationsCb, station);
+
+ xmlFreeDoc (doc);
+
+ return PIANO_RET_OK;
+}
+
/* parses playlist; used when searching too
* @param piano handle
* @param xml document
diff --git a/libpiano/src/xml.h b/libpiano/src/xml.h
index 1165f12..ebc2df7 100644
--- a/libpiano/src/xml.h
+++ b/libpiano/src/xml.h
@@ -32,6 +32,8 @@ PianoReturn_t PianoXmlParseSearch (char *searchXml,
PianoSearchResult_t *searchResult);
PianoReturn_t PianoXmlParseSimple (char *xml);
PianoReturn_t PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml);
+PianoReturn_t PianoXmlParseAddSeed (PianoHandle_t *ph, char *xml,
+ PianoStation_t *station);
char *PianoXmlEncodeString (const char *s);
diff --git a/src/main.c b/src/main.c
index ba6e7b3..89f25b2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -265,6 +265,50 @@ PianoArtist_t *selectArtist (PianoArtist_t *startArtist) {
return tmpArtist;
}
+char *selectMusicId (PianoHandle_t *ph) {
+ char *musicId = NULL, *lineBuf;
+ char yesnoBuf;
+ PianoSearchResult_t searchResult;
+ PianoArtist_t *tmpArtist;
+ PianoSong_t *tmpSong;
+
+ lineBuf = readline ("Search for artist/title\n");
+ if (lineBuf != NULL && strlen (lineBuf) > 0) {
+ PianoSearchMusic (ph, lineBuf, &searchResult);
+ if (searchResult.songs != NULL && searchResult.artists != NULL) {
+ printf ("Is this an [a]rtist or [t]rack name?\n");
+ read (fileno (stdin), &yesnoBuf, sizeof (yesnoBuf));
+ if (yesnoBuf == 'a') {
+ tmpArtist = selectArtist (searchResult.artists);
+ musicId = strdup (tmpArtist->musicId);
+ printf ("Ok.\n");
+ } else if (yesnoBuf == 't') {
+ tmpSong = selectSong (searchResult.songs);
+ musicId = strdup (tmpSong->musicId);
+ printf ("Ok.\n");
+ }
+ } else if (searchResult.songs != NULL) {
+ printf ("Select song\n");
+ tmpSong = selectSong (searchResult.songs);
+ musicId = strdup (tmpSong->musicId);
+ printf ("Ok.\n");
+ } else if (searchResult.artists != NULL) {
+ printf ("Select artist\n");
+ tmpArtist = selectArtist (searchResult.artists);
+ musicId = strdup (tmpArtist->musicId);
+ printf ("Ok.\n");
+ } else {
+ printf ("Nothing found...\n");
+ }
+ PianoDestroySearchResult (&searchResult);
+ }
+ if (lineBuf != NULL) {
+ free (lineBuf);
+ }
+
+ return musicId;
+}
+
int main (int argc, char **argv) {
PianoHandle_t ph;
struct aacPlayer player;
@@ -333,10 +377,7 @@ int main (int argc, char **argv) {
while (!player.finishedPlayback) {
struct pollfd polls = {fileno (stdin), POLLIN, POLLIN};
char buf, yesnoBuf;
- char *lineBuf;
- PianoSearchResult_t searchResult;
- PianoArtist_t *tmpArtist;
- PianoSong_t *tmpSong;
+ char *lineBuf, *musicId;
if (poll (&polls, 1, 1000) > 0) {
read (fileno (stdin), &buf, sizeof (buf));
@@ -345,6 +386,16 @@ int main (int argc, char **argv) {
printf ("n\tnext track\nq\tquit\ns\tchange station\n");
break;
+ case 'a':
+ musicId = selectMusicId (&ph);
+ if (PianoStationAddMusic (&ph, curStation, musicId) == PIANO_RET_OK) {
+ printf ("Added music to station.\n");
+ } else {
+ printf ("Error while adding music to station.\n");
+ }
+ free (musicId);
+ break;
+
case 'b':
player.doQuit = 1;
if (PianoRateTrack (&ph, curStation, curSong,
@@ -359,39 +410,9 @@ int main (int argc, char **argv) {
break;
case 'c':
- lineBuf = readline ("Search for artist/title\n");
- if (lineBuf != NULL && strlen (lineBuf) > 0) {
- PianoSearchMusic (&ph, lineBuf, &searchResult);
- if (searchResult.songs != NULL && searchResult.artists != NULL) {
- printf ("Is this an [a]rtist or [t]rack name?\n");
- read (fileno (stdin), &yesnoBuf, sizeof (yesnoBuf));
- if (yesnoBuf == 'a') {
- tmpArtist = selectArtist (searchResult.artists);
- PianoCreateStation (&ph, tmpArtist->musicId);
- printf ("Ok.\n");
- } else if (yesnoBuf == 't') {
- tmpSong = selectSong (searchResult.songs);
- PianoCreateStation (&ph, tmpSong->musicId);
- printf ("Ok.\n");
- }
- } else if (searchResult.songs != NULL) {
- printf ("Select song\n");
- tmpSong = selectSong (searchResult.songs);
- PianoCreateStation (&ph, tmpSong->musicId);
- printf ("Ok.\n");
- } else if (searchResult.artists != NULL) {
- printf ("Select artist\n");
- tmpArtist = selectArtist (searchResult.artists);
- PianoCreateStation (&ph, tmpArtist->musicId);
- printf ("Ok.\n");
- } else {
- printf ("Nothing found...\n");
- }
- PianoDestroySearchResult (&searchResult);
- }
- if (lineBuf != NULL) {
- free (lineBuf);
- }
+ musicId = selectMusicId (&ph);
+ PianoCreateStation (&ph, musicId);
+ free (musicId);
break;
case 'd':