From f43a0894cb1386bbb5c0c1f068a4f60192070658 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 30 Sep 2017 17:06:41 +0200 Subject: Add tired rating to song Now we can show a tired icon in the history. Closes #637. --- src/libpiano/piano.h | 3 ++- src/libpiano/request.c | 3 ++- src/libpiano/response.c | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/libpiano') diff --git a/src/libpiano/piano.h b/src/libpiano/piano.h index 2dbf607..b595249 100644 --- a/src/libpiano/piano.h +++ b/src/libpiano/piano.h @@ -64,7 +64,8 @@ typedef struct PianoStation { typedef enum { PIANO_RATE_NONE = 0, PIANO_RATE_LOVE = 1, - PIANO_RATE_BAN = 2 + PIANO_RATE_BAN = 2, + PIANO_RATE_TIRED = 3, } PianoSongRating_t; /* UNKNOWN should be 0, because memset sets audio format to 0 */ diff --git a/src/libpiano/request.c b/src/libpiano/request.c index 5d499af..d678aac 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -186,7 +186,8 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, assert (reqData != NULL); assert (reqData->trackToken != NULL); assert (reqData->stationId != NULL); - assert (reqData->rating != PIANO_RATE_NONE); + assert (reqData->rating != PIANO_RATE_NONE && + reqData->rating != PIANO_RATE_TIRED); json_object_object_add (j, "stationToken", json_object_new_string (reqData->stationId)); diff --git a/src/libpiano/response.c b/src/libpiano/response.c index e37824e..48a07db 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -436,8 +436,13 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { break; } + case PIANO_REQUEST_ADD_TIRED_SONG: { + PianoSong_t * const song = req->data; + song->rating = PIANO_RATE_TIRED; + break; + } + case PIANO_REQUEST_ADD_SEED: - case PIANO_REQUEST_ADD_TIRED_SONG: case PIANO_REQUEST_SET_QUICKMIX: case PIANO_REQUEST_BOOKMARK_SONG: case PIANO_REQUEST_BOOKMARK_ARTIST: -- cgit v1.2.3 From ed3ab2743344dfe2b38427733560b9847d259c8c Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 2 Oct 2017 12:12:01 +0200 Subject: Show station in song lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iff song’s station is not the current station. This is only the case for the song history right now. Closes #638 --- contrib/config-example | 2 +- contrib/pianobar.1 | 8 ++++++++ src/libpiano/piano.c | 6 +++++- src/ui.c | 33 +++++++++++++++++++++++++-------- src/ui.h | 7 ++++--- src/ui_act.c | 8 ++++---- 6 files changed, 47 insertions(+), 17 deletions(-) (limited to 'src/libpiano') diff --git a/contrib/config-example b/contrib/config-example index 6a40937..2986d47 100644 --- a/contrib/config-example +++ b/contrib/config-example @@ -57,7 +57,7 @@ #love_icon = <3 #tired_icon = zZ #format_nowplaying_station = Station %n -#format_list_song = %i) %a - %t%r +#format_list_song = %i) %a - %t%r (%d)%@%s # high-quality audio (192k mp3, for Pandora One subscribers only!) #audio_quality = high diff --git a/contrib/pianobar.1 b/contrib/pianobar.1 index 5394e4f..9600859 100644 --- a/contrib/pianobar.1 +++ b/contrib/pianobar.1 @@ -258,6 +258,14 @@ Rating icon .B %d Song duration +.B %@ + +The at_icon + +.B %s + +Song’s station, if not the current station. + .TP .B format_msg_none = %s .TQ diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c index c496ea1..7f1eff9 100644 --- a/src/libpiano/piano.c +++ b/src/libpiano/piano.c @@ -214,7 +214,11 @@ void PianoDestroyRequest (PianoRequest_t *req) { */ PianoStation_t *PianoFindStationById (PianoStation_t * const stations, const char * const searchStation) { - assert (searchStation != NULL); + assert (stations != NULL); + + if (searchStation == NULL) { + return NULL; + } PianoStation_t *currStation = stations; PianoListForeachP (currStation) { diff --git a/src/ui.c b/src/ui.c index 30b62f7..c682ca3 100644 --- a/src/ui.c +++ b/src/ui.c @@ -388,20 +388,21 @@ PianoStation_t *BarUiSelectStation (BarApp_t *app, PianoStation_t *stations, } /* let user pick one song - * @param pianobar settings + * @param app * @param song list * @param input fds * @return pointer to selected item in song list or NULL */ -PianoSong_t *BarUiSelectSong (const BarSettings_t *settings, +PianoSong_t *BarUiSelectSong (const BarApp_t * const app, PianoSong_t *startSong, BarReadline_t rl) { + const BarSettings_t * const settings = &app->settings; PianoSong_t *tmpSong = NULL; char buf[100]; memset (buf, 0, sizeof (buf)); do { - BarUiListSongs (settings, startSong, buf); + BarUiListSongs (app, startSong, buf); BarUiMsg (settings, MSG_QUESTION, "Select song: "); if (BarReadlineStr (buf, sizeof (buf), rl, BAR_RL_DEFAULT) == 0) { @@ -498,7 +499,7 @@ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station, musicId = strdup (tmpArtist->musicId); } } else if (*selectBuf == 't') { - tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + tmpSong = BarUiSelectSong (app, searchResult.songs, app->rl); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -506,7 +507,7 @@ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station, } } else if (searchResult.songs != NULL) { /* songs found */ - tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, + tmpSong = BarUiSelectSong (app, searchResult.songs, app->rl); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); @@ -661,18 +662,34 @@ void BarUiPrintSong (const BarSettings_t *settings, * @param artist/song filter string * @return # of songs */ -size_t BarUiListSongs (const BarSettings_t *settings, +size_t BarUiListSongs (const BarApp_t * const app, const PianoSong_t *song, const char *filter) { + const BarSettings_t * const settings = &app->settings; size_t i = 0; PianoListForeachP (song) { if (filter == NULL || (filter != NULL && (BarStrCaseStr (song->artist, filter) != NULL || BarStrCaseStr (song->title, filter) != NULL))) { + const char * const empty = ""; + const char *stationName = "(deleted)"; + const PianoStation_t * const station = + PianoFindStationById (app->ph.stations, song->stationId); + if (station != NULL) { + if (station != app->curStation) { + stationName = station->name; + } else { + stationName = empty; + } + } + char outstr[512], digits[8], duration[8] = "??:??"; const char *vals[] = {digits, song->artist, song->title, ratingToIcon (settings, song), - duration}; + duration, + stationName != empty ? settings->atIcon : "", + stationName, + }; /* pre-format a few strings */ snprintf (digits, sizeof (digits) / sizeof (*digits), "%2zu", i); @@ -683,7 +700,7 @@ size_t BarUiListSongs (const BarSettings_t *settings, } BarUiCustomFormat (outstr, sizeof (outstr), settings->listSongFormat, - "iatrd", vals); + "iatrd@s", vals); BarUiAppendNewline (outstr, sizeof (outstr)); BarUiMsg (settings, MSG_LIST, "%s", outstr); } diff --git a/src/ui.h b/src/ui.h index 126f6bb..faca48e 100644 --- a/src/ui.h +++ b/src/ui.h @@ -38,14 +38,15 @@ typedef void (*BarUiSelectStationCallback_t) (BarApp_t *app, char *buf); void BarUiMsg (const BarSettings_t *, const BarUiMsg_t, const char *, ...) __attribute__((format(printf, 3, 4))); PianoStation_t *BarUiSelectStation (BarApp_t *, PianoStation_t *, const char *, BarUiSelectStationCallback_t, bool); -PianoSong_t *BarUiSelectSong (const BarSettings_t *, PianoSong_t *, - BarReadline_t); +PianoSong_t *BarUiSelectSong (const BarApp_t * const app, + PianoSong_t *startSong, BarReadline_t rl); PianoArtist_t *BarUiSelectArtist (BarApp_t *, PianoArtist_t *); char *BarUiSelectMusicId (BarApp_t *, PianoStation_t *, const char *); void BarUiPrintStation (const BarSettings_t *, PianoStation_t *); void BarUiPrintSong (const BarSettings_t *, const PianoSong_t *, const PianoStation_t *); -size_t BarUiListSongs (const BarSettings_t *, const PianoSong_t *, const char *); +size_t BarUiListSongs (const BarApp_t * const app, + const PianoSong_t *song, const char *filter); void BarUiStartEventCmd (const BarSettings_t *, const char *, const PianoStation_t *, const PianoSong_t *, const player2_t * const, PianoStation_t *, PianoReturn_t); diff --git a/src/ui_act.c b/src/ui_act.c index a036f19..d834191 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -482,7 +482,7 @@ BarUiActCallback(BarUiActTempBanSong) { BarUiActCallback(BarUiActPrintUpcoming) { PianoSong_t * const nextSong = PianoListNextP (selSong); if (nextSong != NULL) { - BarUiListSongs (&app->settings, nextSong, NULL); + BarUiListSongs (app, nextSong, NULL); } else { BarUiMsg (&app->settings, MSG_INFO, "No songs in queue.\n"); } @@ -563,7 +563,7 @@ BarUiActCallback(BarUiActHistory) { PianoSong_t *histSong; if (app->songHistory != NULL) { - histSong = BarUiSelectSong (&app->settings, app->songHistory, + histSong = BarUiSelectSong (app, app->songHistory, app->rl); if (histSong != NULL) { BarKeyShortcutId_t action; @@ -815,7 +815,7 @@ BarUiActCallback(BarUiActManageStation) { BarUiActDefaultEventcmd ("stationdeleteartistseed"); } } else if (selectBuf[0] == 's') { - PianoSong_t *song = BarUiSelectSong (&app->settings, + PianoSong_t *song = BarUiSelectSong (app, reqData.info.songSeeds, app->rl); if (song != NULL) { PianoRequestDataDeleteSeed_t subReqData; @@ -842,7 +842,7 @@ BarUiActCallback(BarUiActManageStation) { BarUiActDefaultEventcmd ("stationdeletestationseed"); } } else if (selectBuf[0] == 'f') { - PianoSong_t *song = BarUiSelectSong (&app->settings, + PianoSong_t *song = BarUiSelectSong (app, reqData.info.feedback, app->rl); if (song != NULL) { BarUiMsg (&app->settings, MSG_INFO, "Deleting feedback... "); -- cgit v1.2.3 From eebc4b34e9f8b23f384205543e94d1278b6e63d5 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 7 Oct 2017 12:02:57 +0200 Subject: piano: Fetch extended attribs for station info We can show the song length in the feedback list now. --- src/libpiano/request.c | 3 +++ src/libpiano/response.c | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'src/libpiano') diff --git a/src/libpiano/request.c b/src/libpiano/request.c index d678aac..0df7005 100644 --- a/src/libpiano/request.c +++ b/src/libpiano/request.c @@ -156,6 +156,7 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, case PIANO_REQUEST_GET_STATIONS: { /* get stations, user must be authenticated */ assert (ph->user.listenerId != NULL); + method = "user.getStationList"; break; } @@ -398,6 +399,8 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req, json_object_new_string (reqData->station->id)); json_object_object_add (j, "includeExtendedAttributes", json_object_new_boolean (true)); + json_object_object_add (j, "includeExtraParams", + json_object_new_boolean (true)); method = "station.getStation"; break; diff --git a/src/libpiano/response.c b/src/libpiano/response.c index 48a07db..fcc28b1 100644 --- a/src/libpiano/response.c +++ b/src/libpiano/response.c @@ -639,6 +639,11 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) { feedbackSong->rating = getBoolDefault (s, "isPositive", false) ? PIANO_RATE_LOVE : PIANO_RATE_BAN; + json_object *v; + feedbackSong->length = + json_object_object_get_ex (s, "trackLength", &v) ? + json_object_get_int (v) : 0; + info->feedback = PianoListAppendP (info->feedback, feedbackSong); } -- cgit v1.2.3