From 54e334a2a0cb60b6df4d1c336fdfdee5fbefbeb5 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Wed, 4 Apr 2018 15:04:25 +0200 Subject: [PATCH] Added additional "totalTime" field to "obj" for the queue's total time. --- src/mpd_client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index 1054ede..9679b2b 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -600,6 +600,7 @@ int mpd_put_queue(char *buffer, unsigned int offset) char *cur = buffer; const char *end = buffer + MAX_SIZE; struct mpd_entity *entity; + unsigned long totalTime = 0; if (!mpd_send_list_queue_range_meta(mpd.conn, offset, offset+MAX_ELEMENTS_PER_PAGE)) RETURN_ERROR_AND_RECOVER("mpd_send_list_queue_meta"); @@ -608,16 +609,18 @@ int mpd_put_queue(char *buffer, unsigned int offset) while((entity = mpd_recv_entity(mpd.conn)) != NULL) { const struct mpd_song *song; + unsigned int drtn; if(mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) { song = mpd_entity_get_song(entity); + drtn = mpd_song_get_duration(song); cur += json_emit_raw_str(cur, end - cur, "{\"id\":"); cur += json_emit_int(cur, end - cur, mpd_song_get_id(song)); cur += json_emit_raw_str(cur, end - cur, ",\"pos\":"); cur += json_emit_int(cur, end - cur, mpd_song_get_pos(song)); cur += json_emit_raw_str(cur, end - cur, ",\"duration\":"); - cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); + cur += json_emit_int(cur, end - cur, drtn); cur += json_emit_raw_str(cur, end - cur, ",\"title\":"); cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song)); cur += json_emit_raw_str(cur, end - cur, ",\"artist\":"); @@ -625,6 +628,8 @@ int mpd_put_queue(char *buffer, unsigned int offset) cur += json_emit_raw_str(cur, end - cur, ",\"album\":"); cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song)); cur += json_emit_raw_str(cur, end - cur, "},"); + + totalTime += drtn; } mpd_entity_free(entity); } @@ -632,7 +637,9 @@ int mpd_put_queue(char *buffer, unsigned int offset) /* remove last ',' */ cur--; - cur += json_emit_raw_str(cur, end - cur, "]}"); + cur += json_emit_raw_str(cur, end - cur, "],\"totalTime\":"); + cur += json_emit_int(cur, end - cur, totalTime); + cur += json_emit_raw_str(cur, end - cur, "}"); return cur - buffer; } -- 2.20.1