diff options
-rw-r--r-- | libpiano/src/piano.c | 61 | ||||
-rw-r--r-- | libpiano/src/piano.h | 3 | ||||
-rw-r--r-- | libpiano/src/xml.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/pianobar.1 | 4 | ||||
-rw-r--r-- | src/settings.c | 6 | ||||
-rw-r--r-- | src/settings.h | 3 | ||||
-rw-r--r-- | src/ui_act.c | 22 | ||||
-rw-r--r-- | src/ui_act.h | 1 |
9 files changed, 100 insertions, 4 deletions
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), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.createBookmark</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, + 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), "<?xml version=\"1.0\"?>" + "<methodCall><methodName>station.createArtistBookmark</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->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); } } @@ -321,7 +321,7 @@ int main (int argc, char **argv) { BarUiActQuit, BarUiActRenameStation, BarUiActSelectStation, BarUiActTempBanSong, BarUiActPrintUpcoming, BarUiActSelectQuickMix, - BarUiActDebug}; + BarUiActDebug, BarUiActBookmark}; idToF[i] (&ph, &player, &settings, &playlist, &curStation, &songHistory, &doQuit, curFd); break; diff --git a/src/pianobar.1 b/src/pianobar.1 index b8f5446..6112bce 100644 --- a/src/pianobar.1 +++ b/src/pianobar.1 @@ -46,6 +46,10 @@ Add more music to current station. You will be asked for a search string. Just follow the instructions. If you're clueless try '?' (without quotes). .TP +.B act_bookmark = b +Bookmark current song or artist. + +.TP .B act_stationcreate = c Create new station. You have to enter a search string and select the song or artist of your choice. diff --git a/src/settings.c b/src/settings.c index 527a150..1136a3a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -92,7 +92,9 @@ void BarSettingsRead (BarSettings_t *settings) { FILE *configfd; /* _must_ have same order as in BarKeyShortcutId_t */ const char defaultKeys[] = {'?', '+', '-', 'a', 'c', 'd', 'e', 'g', - 'h', 'i', 'j', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'x', '$'}; + 'h', 'i', 'j', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'x', '$', + 'b', + }; const char *shortcutFileKeys[] = { "act_help", "act_songlove", "act_songban", "act_stationaddmusic", "act_stationcreate", "act_stationdelete", "act_songexplain", @@ -100,7 +102,7 @@ void BarSettingsRead (BarSettings_t *settings) { "act_addshared", "act_songmove", "act_songnext", "act_songpause", "act_quit", "act_stationrename", "act_stationchange", "act_songtired", "act_upcoming", "act_stationselectquickmix", - "act_debug" + "act_debug", "act_bookmark", }; /* apply defaults */ diff --git a/src/settings.h b/src/settings.h index 2c6f228..4ecc7b2 100644 --- a/src/settings.h +++ b/src/settings.h @@ -57,8 +57,9 @@ typedef enum { BAR_KS_UPCOMING = 18, BAR_KS_SELECTQUICKMIX = 19, BAR_KS_DEBUG = 20, + BAR_KS_BOOKMARK = 21, /* insert new shortcuts _before_ this element and increase its value */ - BAR_KS_COUNT = 21, + BAR_KS_COUNT = 22, } BarKeyShortcutId_t; typedef struct { diff --git a/src/ui_act.c b/src/ui_act.c index 358029e..80f45c4 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -466,3 +466,25 @@ void BarUiActHistory (BAR_KS_ARGS) { "No history yet.\n"); } } + +/* create song bookmark + */ +void BarUiActBookmark (BAR_KS_ARGS) { + char selectBuf[2]; + PianoReturn_t pRet = PIANO_RET_ERR; + + RETURN_IF_NO_SONG; + + BarUiMsg (MSG_QUESTION, "Bookmark [s]ong or [a]rtist? "); + BarReadline (selectBuf, sizeof (selectBuf), "sa", 1, 0, curFd); + if (selectBuf[0] == 's') { + BarUiMsg (MSG_INFO, "Bookmarking song... "); + pRet = BarUiPrintPianoStatus (PianoBookmarkSong (ph, *curSong)); + BarUiStartEventCmd (settings, "songbookmark", *curStation, *curSong, pRet); + } else if (selectBuf[0] == 'a') { + BarUiMsg (MSG_INFO, "Bookmarking artist... "); + pRet = BarUiPrintPianoStatus (PianoBookmarkArtist (ph, *curSong)); + BarUiStartEventCmd (settings, "artistbookmark", *curStation, *curSong, pRet); + } +} + diff --git a/src/ui_act.h b/src/ui_act.h index 4f0945b..2da5883 100644 --- a/src/ui_act.h +++ b/src/ui_act.h @@ -47,5 +47,6 @@ void BarUiActSelectQuickMix (BAR_KS_ARGS); void BarUiActQuit (BAR_KS_ARGS); void BarUiActDebug (BAR_KS_ARGS); void BarUiActHistory (BAR_KS_ARGS); +void BarUiActBookmark (BAR_KS_ARGS); #endif /* _UI_ACT_H */ |