mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-24 01:50:27 +00:00
Added statistics to about dialog
This commit is contained in:
parent
edd318d026
commit
1da825c712
@ -369,6 +369,25 @@
|
||||
<li>Homepage: <a style="color:#28a745" target="_blank" href="https://github.com/jcorporation/mympd">https://github.com/jcorporation/mympd</a></li>
|
||||
<li>Autor: Juergen Mang <<a style="color:#28a745" href="mailto:mail@jcgames.de">mail@jcgames.de</a>></li>
|
||||
</ul>
|
||||
<hr/>
|
||||
<h5>Database Statistics</h5>
|
||||
<table class="table table-sm">
|
||||
<tbody>
|
||||
<tr><th>Artists</th><td id="mpdstats_artists"></td></tr>
|
||||
<tr><th>Albums</th><td id="mpdstats_albums"></td></tr>
|
||||
<tr><th>Songs</th><td id="mpdstats_songs"></td></tr>
|
||||
<tr><th>DB Play Time</th><td id="mpdstats_dbplaytime"></td></tr>
|
||||
<tr><th>DB Updated</th><td id="mpdstats_dbupdated"></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<hr/>
|
||||
<h5>Play Statistics</h5>
|
||||
<table class="table table-sm">
|
||||
<tbody>
|
||||
<tr><th>Uptime</th><td id="mpdstats_uptime"></td></tr>
|
||||
<tr><th>Play Time</th><td id="mpdstats_playtime"></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
|
@ -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';
|
||||
}
|
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user