diff options
author | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-14 16:08:35 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@gmail.com> | 2008-06-14 16:08:35 +0200 |
commit | e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee (patch) | |
tree | b2e54f4e5c95f73fa96f88a624dd358a5477cd0f | |
parent | b1ea463843add37874f9768b606825504cdc8eb2 (diff) | |
download | pianobar-windows-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.tar.gz pianobar-windows-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.tar.bz2 pianobar-windows-e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee.zip |
Finally implemented "create station"
This may be a bit buggy, because no return values are checked or returned. A
big cleanup session is waiting...
-rw-r--r-- | libpiano/main.c | 33 | ||||
-rw-r--r-- | libpiano/piano.h | 3 | ||||
-rw-r--r-- | libpiano/xml.c | 28 | ||||
-rw-r--r-- | libpiano/xml.h | 1 | ||||
-rw-r--r-- | src/main.c | 79 |
5 files changed, 144 insertions, 0 deletions
diff --git a/libpiano/main.c b/libpiano/main.c index cc4e65a..9754e73 100644 --- a/libpiano/main.c +++ b/libpiano/main.c @@ -456,3 +456,36 @@ void PianoSearchMusic (PianoHandle_t *ph, char *searchStr, free (retStr); free (requestStr); } + +/* create new station on server + * @author PromyLOPh + * @added 2008-06-14 + * @public yes + * @param piano handle + * @param music id from artist or track, you may obtain one by calling + * PianoSearchMusic + * @return nothing, yet + */ +void PianoCreateStation (PianoHandle_t *ph, char *musicId) { + char xmlSendBuf[10000], url[PIANO_URL_BUFFER_SIZE]; + char *requestStr, *retStr; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.createStation</methodName>" + "<params><param><value><int>%li</int></value></param>" + "<param><value><string>%s</string></value></param>" + "<param><value><string>mi%s</string></value></param>" + "</params></methodCall>", time (NULL), ph->user.authToken, + musicId); + requestStr = PianoEncryptString (xmlSendBuf); + + snprintf (url, sizeof (url), PIANO_RPC_URL "rid=%s&lid=%s" + "&method=createStation&arg1=mi%s", ph->routeId, + ph->user.listenerId, musicId); + + PianoHttpPost (ph->curlHandle, url, requestStr, &retStr); + PianoXmlParseCreateStation (ph, retStr); + + free (requestStr); + free (retStr); +} diff --git a/libpiano/piano.h b/libpiano/piano.h index 9f2f7d7..0bffce5 100644 --- a/libpiano/piano.h +++ b/libpiano/piano.h @@ -157,5 +157,8 @@ PianoReturn_t PianoRateTrack (PianoHandle_t *ph, PianoStation_t *station, PianoReturn_t PianoRenameStation (PianoHandle_t *ph, PianoStation_t *station, char *newName); PianoReturn_t PianoDeleteStation (PianoHandle_t *ph, PianoStation_t *station); +void PianoSearchMusic (PianoHandle_t *ph, char *searchStr, + PianoSearchResult_t *searchResult); +void PianoCreateStation (PianoHandle_t *ph, char *musicId); #endif /* _PIANO_H */ diff --git a/libpiano/xml.c b/libpiano/xml.c index 6f8cb55..5ac8d97 100644 --- a/libpiano/xml.c +++ b/libpiano/xml.c @@ -245,6 +245,34 @@ void PianoXmlParseStations (PianoHandle_t *ph, char *xml) { xmlFreeDoc (doc); } +void PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml) { + xmlNode *docRoot; + xmlDocPtr doc; + PianoStation_t *tmpStation; + + if (PianoXmlInitDoc (xml, &doc, &docRoot) != PIANO_RET_OK) { + return; + } + + /* get <struct> node */ + xmlNode *dataRoot = docRoot->children->children->children->children; + tmpStation = calloc (1, sizeof (*tmpStation)); + PianoXmlStructParser (dataRoot, PianoXmlParseStationsCb, tmpStation); + /* FIXME: copy & waste */ + /* start new linked list or append */ + if (ph->stations == NULL) { + ph->stations = tmpStation; + } else { + PianoStation_t *curStation = ph->stations; + while (curStation->next != NULL) { + curStation = curStation->next; + } + curStation->next = tmpStation; + } + + xmlFreeDoc (doc); +} + /* parses playlist; used when searching too * @author PromyLOPh * @added 2008-06-12 diff --git a/libpiano/xml.h b/libpiano/xml.h index 140d0ff..f8c9106 100644 --- a/libpiano/xml.h +++ b/libpiano/xml.h @@ -29,6 +29,7 @@ void PianoXmlParsePlaylist (PianoHandle_t *ph, char *xml); void PianoXmlParseSearch (char *searchXml, PianoSearchResult_t *searchResult); PianoReturn_t PianoXmlParseSimple (char *xml); +void PianoXmlParseCreateStation (PianoHandle_t *ph, char *xml); char *PianoXmlEncodeString (const char *s); @@ -232,6 +232,46 @@ PianoStation_t *selectStation (PianoHandle_t *ph) { return curStation; } +PianoSong_t *selectSong (PianoSong_t *startSong) { + PianoSong_t *tmpSong; + size_t i; + + tmpSong = startSong; + i = 0; + while (tmpSong != NULL) { + printf ("%2u) %s - %s\n", i, tmpSong->artist, tmpSong->title); + i++; + tmpSong = tmpSong->next; + } + scanf ("%i", &i); + tmpSong = startSong; + while (tmpSong != NULL && i > 0) { + tmpSong = tmpSong->next; + i--; + } + return tmpSong; +} + +PianoArtist_t *selectArtist (PianoArtist_t *startArtist) { + PianoArtist_t *tmpArtist; + size_t i; + + tmpArtist = startArtist; + i = 0; + while (tmpArtist != NULL) { + printf ("%2u) %s\n", i, tmpArtist->name); + i++; + tmpArtist = tmpArtist->next; + } + scanf ("%i", &i); + tmpArtist = startArtist; + while (tmpArtist != NULL && i > 0) { + tmpArtist = tmpArtist->next; + i--; + } + return tmpArtist; +} + int main (int argc, char **argv) { PianoHandle_t ph; struct aacPlayer player; @@ -278,6 +318,9 @@ int main (int argc, char **argv) { struct pollfd polls = {fileno (stdin), POLLIN, POLLIN}; char buf, yesnoBuf; char *lineBuf; + PianoSearchResult_t searchResult; + PianoArtist_t *tmpArtist; + PianoSong_t *tmpSong; if (poll (&polls, 1, 1000) > 0) { read (fileno (stdin), &buf, sizeof (buf)); @@ -299,6 +342,42 @@ int main (int argc, char **argv) { curSong = NULL; 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); + } + break; + case 'd': printf ("Really delete \"%s\"? [yn]\n", curStation->name); |