From 7eba7e939b87b6bebc16ddca94f799e46b2b0aae Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 13 Feb 2010 13:17:00 +0100 Subject: New feature: Bookmark song/artist (keybinding 'b') --- libpiano/src/piano.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libpiano/src/piano.h | 3 +++ libpiano/src/xml.c | 2 ++ 3 files changed, 66 insertions(+) (limited to 'libpiano') diff --git a/libpiano/src/piano.c b/libpiano/src/piano.c index 5173562..407f5f7 100644 --- a/libpiano/src/piano.c +++ b/libpiano/src/piano.c @@ -148,6 +148,7 @@ void PianoDestroyPlaylist (PianoSong_t *playlist) { PianoFree (curSong->identity, 0); PianoFree (curSong->stationId, 0); PianoFree (curSong->album, 0); + PianoFree (curSong->artistMusicId, 0); lastSong = curSong; curSong = curSong->next; PianoFree (lastSong, sizeof (*lastSong)); @@ -803,6 +804,66 @@ PianoReturn_t PianoSeedSuggestions (PianoHandle_t *ph, const char *musicId, return ret; } +/* Create song bookmark + * @param piano handle + * @param song + */ +PianoReturn_t PianoBookmarkSong (PianoHandle_t *ph, PianoSong_t *song) { + char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], *retStr; + PianoReturn_t ret; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "" + "station.createBookmark" + "%li" + "%s" + "%s" + "%s" + "", time (NULL), ph->user.authToken, + song->stationId, song->musicId); + + snprintf (ph->waith.path, sizeof (ph->waith.path), PIANO_RPC_PATH + "rid=%s&lid=%s&method=method=createBookmark&arg1=%s&arg2=%s", + ph->routeId, ph->user.listenerId, song->stationId, + song->musicId); + + if ((ret = PianoHttpPost (&ph->waith, xmlSendBuf, &retStr)) == + PIANO_RET_OK) { + ret = PianoXmlParseSimple (retStr); + PianoFree (retStr, 0); + } + + return ret; +} + +/* Create artist bookmark + * @param piano handle + * @param song of artist + */ +PianoReturn_t PianoBookmarkArtist (PianoHandle_t *ph, PianoSong_t *song) { + char xmlSendBuf[PIANO_SEND_BUFFER_SIZE], *retStr; + PianoReturn_t ret; + + snprintf (xmlSendBuf, sizeof (xmlSendBuf), "" + "station.createArtistBookmark" + "%li" + "%s" + "%s" + "", time (NULL), ph->user.authToken, + song->artistMusicId); + + snprintf (ph->waith.path, sizeof (ph->waith.path), PIANO_RPC_PATH + "rid=%s&lid=%s&method=method=createArtistBookmark&arg1=%s", + ph->routeId, ph->user.listenerId, song->artistMusicId); + + if ((ret = PianoHttpPost (&ph->waith, xmlSendBuf, &retStr)) == + PIANO_RET_OK) { + ret = PianoXmlParseSimple (retStr); + PianoFree (retStr, 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 ef93c09..80b9e08 100644 --- a/libpiano/src/piano.h +++ b/libpiano/src/piano.h @@ -55,6 +55,7 @@ typedef enum {PIANO_AF_UNKNOWN = 0, PIANO_AF_AACPLUS, PIANO_AF_MP3, typedef struct PianoSong { char *artist; + char *artistMusicId; char *matchingSeed; float fileGain; PianoSongRating_t rating; @@ -138,5 +139,7 @@ PianoReturn_t PianoExplain (PianoHandle_t *, const PianoSong_t *, char **); const char *PianoErrorToStr (PianoReturn_t); PianoReturn_t PianoSeedSuggestions (PianoHandle_t *, const char *, unsigned int, PianoSearchResult_t *); +PianoReturn_t PianoBookmarkSong (PianoHandle_t *, PianoSong_t *); +PianoReturn_t PianoBookmarkArtist (PianoHandle_t *, PianoSong_t *); #endif /* _PIANO_H */ diff --git a/libpiano/src/xml.c b/libpiano/src/xml.c index e3c1749..53eeca5 100644 --- a/libpiano/src/xml.c +++ b/libpiano/src/xml.c @@ -291,6 +291,8 @@ static void PianoXmlParsePlaylistCb (const char *key, const ezxml_t value, } else if (strcmp (valueStr, "mp3-hifi") == 0) { song->audioFormat = PIANO_AF_MP3_HI; } + } else if (strcmp ("artistMusicId", key) == 0) { + song->artistMusicId = strdup (valueStr); } } -- cgit v1.2.3