diff --git a/htdocs/index.html b/htdocs/index.html
index 22db5a1..3f85f4c 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -369,6 +369,25 @@
Homepage: https://github.com/jcorporation/mympd
Autor: Juergen Mang <mail@jcgames.de>
+
+ Database Statistics
+
+
+ Artists | |
+ Albums | |
+ Songs | |
+ DB Play Time | |
+ DB Updated | |
+
+
+
+ Play Statistics
+
+
+ Uptime | |
+ Play Time | |
+
+
diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js
index 4f04d78..a68c9d9 100644
--- a/htdocs/js/mpd.js
+++ b/htdocs/js/mpd.js
@@ -30,7 +30,7 @@ var pagination = 0;
var browsepath = "";
var lastSongTitle = "";
var current_song = new Object();
-var MAX_ELEMENTS_PER_PAGE = 5;
+var MAX_ELEMENTS_PER_PAGE = 100;
var isTouch = Modernizr.touch ? 1 : 0;
var filter = "";
var playstate = "";
@@ -149,6 +149,10 @@ $(document).ready(function(){
}
});
+ $('#about').on('shown.bs.modal', function () {
+ socket.send("MPD_API_GET_STATS");
+ })
+
$('#addstream').on('shown.bs.modal', function () {
$('#streamurl').focus();
})
@@ -581,6 +585,16 @@ function webSocketConnect() {
setLocalStream(obj.data.mpdhost,obj.data.streamport);
coverImageFile=obj.data.coverimage;
break;
+ case 'mpdstats':
+ $('#mpdstats_artists').text(obj.data.artists);
+ $('#mpdstats_albums').text(obj.data.albums);
+ $('#mpdstats_songs').text(obj.data.songs);
+ $('#mpdstats_dbplaytime').text(beautifyDuration(obj.data.dbplaytime));
+ $('#mpdstats_playtime').text(beautifyDuration(obj.data.playtime));
+ $('#mpdstats_uptime').text(beautifyDuration(obj.data.uptime));
+ var d = new Date(obj.data.dbupdated * 1000);
+ $('#mpdstats_dbupdated').text(d.toUTCString());
+ break;
case 'error':
showNotification(obj.data,'','','danger');
default:
@@ -1014,4 +1028,15 @@ function chVolume (increment) {
else if (newValue > 100) { newValue=100; }
volumeBar.slider('setValue',newValue);
socket.send("MPD_API_SET_VOLUME,"+newValue);
+}
+
+function beautifyDuration(x) {
+ var days = Math.floor(x / 86400);
+ var hours = Math.floor(x / 3600) - days * 24;
+ var minutes = Math.floor(x / 60) - hours * 60 - days * 1440;
+ var seconds = x - days * 86400 - hours * 3600 - minutes * 60;
+
+ return (days > 0 ? days + '\u2009d ' : '') +
+ (hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') +
+ minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s';
}
\ No newline at end of file
diff --git a/src/mpd_client.c b/src/mpd_client.c
index 0ff7116..3cbb26d 100644
--- a/src/mpd_client.c
+++ b/src/mpd_client.c
@@ -295,7 +295,7 @@ out_search:
if ( (token = strtok(NULL, ",")) == NULL )
goto out_send_message;
- mpd_run_send_message(mpd.conn, p_charbuf, token);
+ mpd_run_send_message(mpd.conn, p_charbuf, token);
out_send_message:
free(p_charbuf);
break;
@@ -305,6 +305,9 @@ out_send_message:
"\"streamport\": \"%d\",\"coverimage\": \"%s\"}"
"}", mpd.host, mpd.port, mpd.password ? "true" : "false", streamport, coverimage);
break;
+ case MPD_API_GET_STATS:
+ n = mympd_get_stats(mpd.buf);
+ break;
}
if(mpd.conn_state == MPD_CONNECTED && mpd_connection_get_error(mpd.conn) != MPD_ERROR_SUCCESS)
@@ -877,6 +880,33 @@ int mpd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *
return cur - buffer;
}
+int mympd_get_stats(char *buffer)
+{
+ char *cur = buffer;
+ const char *end = buffer + MAX_SIZE;
+ struct mpd_stats *stats = mpd_run_stats(mpd.conn);
+ if (stats == NULL)
+ RETURN_ERROR_AND_RECOVER("mympd_get_stats");
+ cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"mpdstats\",\"data\": {");
+ cur += json_emit_raw_str(cur, end - cur, "\"artists\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_number_of_artists(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"albums\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_number_of_albums(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"songs\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_number_of_songs(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"playtime\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_play_time(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"uptime\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_uptime(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"dbupdated\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_db_update_time(stats));
+ cur += json_emit_raw_str(cur, end - cur, ",\"dbplaytime\":");
+ cur += json_emit_int(cur, end - cur, mpd_stats_get_db_play_time(stats));
+ cur += json_emit_raw_str(cur, end - cur, "}}");
+
+ mpd_stats_free(stats);
+ return cur - buffer;
+}
void mpd_disconnect()
{
diff --git a/src/mpd_client.h b/src/mpd_client.h
index ed4f83c..cdd9f16 100644
--- a/src/mpd_client.h
+++ b/src/mpd_client.h
@@ -37,8 +37,8 @@
} while(0)
-#define MAX_SIZE 1024 * 5
-#define MAX_ELEMENTS_PER_PAGE 5
+#define MAX_SIZE 1024 * 100
+#define MAX_ELEMENTS_PER_PAGE 100
#define GEN_ENUM(X) X,
#define GEN_STR(X) #X,
@@ -73,7 +73,8 @@
X(MPD_API_TOGGLE_CROSSFADE) \
X(MPD_API_TOGGLE_REPEAT) \
X(MPD_API_GET_OPTIONS) \
- X(MPD_API_SEND_SHUFFLE)
+ X(MPD_API_SEND_SHUFFLE) \
+ X(MPD_API_GET_STATS)
enum mpd_cmd_ids {
MPD_CMDS(GEN_ENUM)
@@ -123,6 +124,7 @@ int mpd_put_queue(char *buffer, unsigned int offset);
int mpd_put_browse(char *buffer, char *path, unsigned int offset);
int mpd_search(char *buffer, char *searchstr);
int mpd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
+int mympd_get_stats();
void mpd_disconnect();
#endif