Added additional "totalTime" field to "obj" for the queue's total time.
authoreb041592 <35889760+eb041592@users.noreply.github.com>
Wed, 4 Apr 2018 13:04:25 +0000 (15:04 +0200)
committereb041592 <35889760+eb041592@users.noreply.github.com>
Wed, 4 Apr 2018 21:06:19 +0000 (23:06 +0200)
src/mpd_client.c

index 1054ede..9679b2b 100644 (file)
@@ -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;
 }