mirror of
https://github.com/SuperBFG7/ympd
synced 2025-01-13 19:00:37 +00:00
New Settings API replaces Options API, Smaller Stats API
This commit is contained in:
parent
f122355c38
commit
8c423f4c77
@ -515,7 +515,7 @@
|
||||
<h4><a class="text-success" href="https://github.com/jcorporation/ympd"><span class="material-icons">play_circle_outline</span> myMPD</a> – <small>MPD Web GUI - written in C, utilizing Websockets and Bootstrap/JS</small></h4>
|
||||
<p>myMPD is a lightweight MPD web client that runs without a dedicated webserver or interpreter. It's tuned for minimal resource usage and requires only very litte dependencies. myMPD is a fork of <a style="color:#28a745" href="http://www.ympd.org">ympd</a>.</p>
|
||||
<ul>
|
||||
<li>Version: 2.1.1</li>
|
||||
<li>Version: <span id="mympdVersion"></span></li>
|
||||
<li>Homepage: <a class="text-success" target="_blank" href="https://github.com/jcorporation/mympd">https://github.com/jcorporation/mympd</a></li>
|
||||
<li>Autor: Juergen Mang <<a class="text-success" href="mailto:mail@jcgames.de">mail@jcgames.de</a>></li>
|
||||
</ul>
|
||||
|
129
htdocs/js/mpd.js
129
htdocs/js/mpd.js
@ -210,11 +210,16 @@ $(document).ready(function(){
|
||||
|
||||
$('#about').on('shown.bs.modal', function () {
|
||||
socket.send("MPD_API_GET_STATS");
|
||||
})
|
||||
})
|
||||
|
||||
$('#settings').on('shown.bs.modal', function () {
|
||||
socket.send("MPD_API_GET_SETTINGS");
|
||||
})
|
||||
|
||||
$('#addstream').on('shown.bs.modal', function () {
|
||||
$('#streamurl').focus();
|
||||
})
|
||||
})
|
||||
|
||||
$('#addstream form').on('submit', function (e) {
|
||||
addStream();
|
||||
});
|
||||
@ -249,8 +254,8 @@ function webSocketConnect() {
|
||||
showNotification('Connected to myMPD','','','success');
|
||||
$('#modalConnectionError').modal('hide');
|
||||
app.run();
|
||||
/* emit request for mympd options */
|
||||
socket.send('MPD_API_GET_OPTIONS');
|
||||
/* emit request for mympd settings */
|
||||
socket.send('MPD_API_GET_SETTINGS');
|
||||
/* emit initial request for output names */
|
||||
socket.send('MPD_API_GET_OUTPUTS');
|
||||
|
||||
@ -534,62 +539,7 @@ function webSocketConnect() {
|
||||
$('#queueList > tbody > tr[trackid='+obj.data.currentsongid+'] > td').eq(0).addClass('material-icons').text('play_arrow');
|
||||
$('#queueList > tbody > tr[trackid='+obj.data.currentsongid+']').addClass('active').css("font-weight", "bold");
|
||||
|
||||
if(obj.data.random)
|
||||
$('#btnrandom').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnrandom').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.consume)
|
||||
$('#btnconsume').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnconsume').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.single)
|
||||
$('#btnsingle').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnsingle').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.crossfade != undefined) {
|
||||
if (!last_state) {
|
||||
$('#inputCrossfade').removeAttr('disabled');
|
||||
$('#inputCrossfade').val(obj.data.crossfade);
|
||||
} else if(obj.data.crossfade != last_state.data.crossfade) {
|
||||
$('#inputCrossfade').removeAttr('disabled');
|
||||
$('#inputCrossfade').val(obj.data.crossfade);
|
||||
}
|
||||
} else {
|
||||
$('#inputCrossfade').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.mixrampdb != undefined) {
|
||||
if (!last_state) {
|
||||
$('#inputMixrampdb').removeAttr('disabled');
|
||||
$('#inputMixrampdb').val(obj.data.mixrampdb);
|
||||
} else if(obj.data.mixrampdb != last_state.data.mixrampdb) {
|
||||
$('#inputMixrampdb').removeAttr('disabled');
|
||||
$('#inputMixrampdb').val(obj.data.mixrampdb);
|
||||
}
|
||||
} else {
|
||||
$('#inputMixrampdb').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.mixrampdelay != undefined) {
|
||||
if (!last_state) {
|
||||
$('#inputMixrampdelay').removeAttr('disabled');
|
||||
$('#inputMixrampdelay').val(obj.data.mixrampdelay);
|
||||
} else if(obj.data.mixrampdelay != last_state.data.mixrampdelay) {
|
||||
$('#inputMixrampdelay').removeAttr('disabled');
|
||||
$('#inputMixrampdelay').val(obj.data.mixrampdelay);
|
||||
}
|
||||
} else {
|
||||
$('#inputMixrampdb').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.repeat)
|
||||
$('#btnrepeat').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnrepeat').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
last_state = obj;
|
||||
break;
|
||||
case 'outputnames':
|
||||
@ -629,7 +579,48 @@ function webSocketConnect() {
|
||||
case "song_change":
|
||||
songChange(obj.data.title, obj.data.artist, obj.data.album, obj.data.uri);
|
||||
break;
|
||||
case 'mpdoptions':
|
||||
case 'settings':
|
||||
if(obj.data.random)
|
||||
$('#btnrandom').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnrandom').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.consume)
|
||||
$('#btnconsume').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnconsume').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.single)
|
||||
$('#btnsingle').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnsingle').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
if(obj.data.crossfade != undefined) {
|
||||
$('#inputCrossfade').removeAttr('disabled');
|
||||
$('#inputCrossfade').val(obj.data.crossfade);
|
||||
} else {
|
||||
$('#inputCrossfade').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.mixrampdb != undefined) {
|
||||
$('#inputMixrampdb').removeAttr('disabled');
|
||||
$('#inputMixrampdb').val(obj.data.mixrampdb);
|
||||
} else {
|
||||
$('#inputMixrampdb').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.mixrampdelay != undefined) {
|
||||
$('#inputMixrampdelay').removeAttr('disabled');
|
||||
$('#inputMixrampdelay').val(obj.data.mixrampdelay);
|
||||
} else {
|
||||
$('#inputMixrampdb').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
if(obj.data.repeat)
|
||||
$('#btnrepeat').removeClass('btn-secondary').addClass("btn-success")
|
||||
else
|
||||
$('#btnrepeat').removeClass("btn-success").addClass("btn-secondary");
|
||||
|
||||
setLocalStream(obj.data.mpdhost,obj.data.streamport);
|
||||
coverImageFile=obj.data.coverimage;
|
||||
break;
|
||||
@ -642,6 +633,7 @@ function webSocketConnect() {
|
||||
$('#mpdstats_uptime').text(beautifyDuration(obj.data.uptime));
|
||||
var d = new Date(obj.data.dbupdated * 1000);
|
||||
$('#mpdstats_dbupdated').text(d.toUTCString());
|
||||
$('#mympdVersion').text(obj.data.mympd_version);
|
||||
break;
|
||||
case 'error':
|
||||
showNotification(obj.data,'','','danger');
|
||||
@ -810,20 +802,31 @@ function basename(path) {
|
||||
return path.split('/').reverse()[0];
|
||||
}
|
||||
|
||||
$('#btnrandom').on('click', function (e) {
|
||||
socket.send("MPD_API_TOGGLE_RANDOM," + ($(this).hasClass('btn-success') ? 0 : 1));
|
||||
function toggleBtn(btn) {
|
||||
if ($(btn).hasClass('btn-success')) {
|
||||
$(btn).removeClass('btn-success').addClass('btn-secondary');
|
||||
}
|
||||
else {
|
||||
$(btn).removeClass('btn-secondary').addClass('btn-success');
|
||||
}
|
||||
}
|
||||
|
||||
$('#btnrandom').on('click', function (e) {
|
||||
socket.send("MPD_API_TOGGLE_RANDOM," + ($(this).hasClass('btn-success') ? 0 : 1));
|
||||
toggleBtn(this);
|
||||
});
|
||||
$('#btnconsume').on('click', function (e) {
|
||||
socket.send("MPD_API_TOGGLE_CONSUME," + ($(this).hasClass('btn-success') ? 0 : 1));
|
||||
|
||||
toggleBtn(this);
|
||||
});
|
||||
$('#btnsingle').on('click', function (e) {
|
||||
socket.send("MPD_API_TOGGLE_SINGLE," + ($(this).hasClass('btn-success') ? 0 : 1));
|
||||
toggleBtn(this);
|
||||
});
|
||||
|
||||
$('#btnrepeat').on('click', function (e) {
|
||||
socket.send("MPD_API_TOGGLE_REPEAT," + ($(this).hasClass('btn-success') ? 0 : 1));
|
||||
toggleBtn(this);
|
||||
});
|
||||
|
||||
function confirmSettings() {
|
||||
|
@ -25,8 +25,9 @@
|
||||
#ifndef __CONFIG_H__
|
||||
#define __CONFIG_H__
|
||||
|
||||
#define YMPD_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}
|
||||
#define YMPD_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}
|
||||
#define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
|
||||
#define MYMPD_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}
|
||||
#define MYMPD_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}
|
||||
#define MYMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
|
||||
#define MYMPD_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}"
|
||||
#define SRC_PATH "${ASSETS_PATH}"
|
||||
#endif
|
||||
|
@ -331,11 +331,8 @@ out_send_message:
|
||||
out_rm_playlist:
|
||||
free(p_charbuf);
|
||||
break;
|
||||
case MPD_API_GET_OPTIONS:
|
||||
n = snprintf(mpd.buf, MAX_SIZE, "{\"type\":\"mpdoptions\", \"data\": "
|
||||
"{\"mpdhost\" : \"%s\", \"mpdport\": \"%d\", \"passwort_set\": %s, "
|
||||
"\"streamport\": \"%d\",\"coverimage\": \"%s\"}"
|
||||
"}", mpd.host, mpd.port, mpd.password ? "true" : "false", streamport, coverimage);
|
||||
case MPD_API_GET_SETTINGS:
|
||||
n = mympd_put_settings(mpd.buf);
|
||||
break;
|
||||
case MPD_API_GET_STATS:
|
||||
n = mympd_get_stats(mpd.buf);
|
||||
@ -563,26 +560,17 @@ int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsign
|
||||
|
||||
len = snprintf(buffer, MAX_SIZE,
|
||||
"{\"type\":\"state\", \"data\":{"
|
||||
" \"state\":%d, \"volume\":%d, \"repeat\":%d,"
|
||||
" \"single\":%d, \"crossfade\":%d, \"consume\":%d, \"random\":%d, "
|
||||
" \"songpos\": %d, \"elapsedTime\": %d, \"totalTime\":%d, "
|
||||
" \"currentsongid\": %d, \"kbitrate\": %d, \"mixrampdb\": %lf, "
|
||||
" \"mixrampdelay\": %lf, \"queue_length\": %d, \"nextsongpos\": %d"
|
||||
"\"state\":%d, \"volume\":%d, \"songpos\": %d, \"elapsedTime\": %d, "
|
||||
"\"totalTime\":%d, \"currentsongid\": %d, \"kbitrate\": %d, "
|
||||
"\"queue_length\": %d, \"nextsongpos\": %d"
|
||||
"}}",
|
||||
mpd_status_get_state(status),
|
||||
mpd_status_get_volume(status),
|
||||
mpd_status_get_repeat(status),
|
||||
mpd_status_get_single(status),
|
||||
mpd_status_get_crossfade(status),
|
||||
mpd_status_get_consume(status),
|
||||
mpd_status_get_random(status),
|
||||
mpd_status_get_song_pos(status),
|
||||
mpd_status_get_elapsed_time(status),
|
||||
mpd_status_get_total_time(status),
|
||||
mpd_status_get_song_id(status),
|
||||
mpd_status_get_kbit_rate(status),
|
||||
mpd_status_get_mixrampdb(status),
|
||||
mpd_status_get_mixrampdelay(status),
|
||||
mpd_status_get_queue_length(status),
|
||||
mpd_status_get_next_song_pos(status)
|
||||
);
|
||||
@ -594,6 +582,38 @@ int mpd_put_state(char *buffer, int *current_song_id, int *next_song_id, unsign
|
||||
return len;
|
||||
}
|
||||
|
||||
int mympd_put_settings(char *buffer)
|
||||
{
|
||||
struct mpd_status *status;
|
||||
int len;
|
||||
|
||||
status = mpd_run_status(mpd.conn);
|
||||
if (!status) {
|
||||
fprintf(stderr, "MPD mpd_run_status: %s\n", mpd_connection_get_error_message(mpd.conn));
|
||||
mpd.conn_state = MPD_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = snprintf(buffer, MAX_SIZE,
|
||||
"{\"type\":\"settings\", \"data\":{"
|
||||
"\"repeat\":%d, \"single\":%d, \"crossfade\":%d, \"consume\":%d, \"random\":%d, "
|
||||
"\"mixrampdb\": %lf, \"mixrampdelay\": %lf, \"mpdhost\" : \"%s\", \"mpdport\": \"%d\", \"passwort_set\": %s, "
|
||||
"\"streamport\": \"%d\",\"coverimage\": \"%s\""
|
||||
"}}",
|
||||
mpd_status_get_repeat(status),
|
||||
mpd_status_get_single(status),
|
||||
mpd_status_get_crossfade(status),
|
||||
mpd_status_get_consume(status),
|
||||
mpd_status_get_random(status),
|
||||
mpd_status_get_mixrampdb(status),
|
||||
mpd_status_get_mixrampdelay(status),
|
||||
mpd.host, mpd.port, mpd.password ? "true" : "false", streamport, coverimage
|
||||
);
|
||||
mpd_status_free(status);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int mpd_put_outputs(char *buffer, int names)
|
||||
{
|
||||
struct mpd_output *out;
|
||||
@ -964,7 +984,9 @@ int mympd_get_stats(char *buffer)
|
||||
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_int(cur, end - cur, mpd_stats_get_db_play_time(stats));
|
||||
cur += json_emit_raw_str(cur, end - cur, ",\"mympd_version\":");
|
||||
cur += json_emit_quoted_str(cur, end - cur, MYMPD_VERSION);
|
||||
cur += json_emit_raw_str(cur, end - cur, "}}");
|
||||
|
||||
mpd_stats_free(stats);
|
||||
|
@ -72,7 +72,7 @@
|
||||
X(MPD_API_TOGGLE_SINGLE) \
|
||||
X(MPD_API_SET_CROSSFADE) \
|
||||
X(MPD_API_TOGGLE_REPEAT) \
|
||||
X(MPD_API_GET_OPTIONS) \
|
||||
X(MPD_API_GET_SETTINGS) \
|
||||
X(MPD_API_SEND_SHUFFLE) \
|
||||
X(MPD_API_GET_STATS) \
|
||||
X(MPD_API_SET_MIXRAMPDB) \
|
||||
@ -131,7 +131,8 @@ int mpd_put_playlists(char *buffer, unsigned int offset);
|
||||
int mpd_put_browse(char *buffer, char *path, unsigned int offset);
|
||||
int mpd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
||||
int mpd_search_queue(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
||||
int mympd_get_stats();
|
||||
int mympd_get_stats(char *buffer);
|
||||
int mympd_put_settings(char *buffer);
|
||||
void mpd_disconnect();
|
||||
#endif
|
||||
|
||||
|
@ -146,8 +146,8 @@ int main(int argc, char **argv)
|
||||
case 'v':
|
||||
fprintf(stdout, "myMPD %d.%d.%d\n"
|
||||
"Copyright (C) 2018 Juergen Mang <mail@jcgames.de>\n"
|
||||
"built " __DATE__ " "__TIME__ " ("__VERSION__")\n",
|
||||
YMPD_VERSION_MAJOR, YMPD_VERSION_MINOR, YMPD_VERSION_PATCH);
|
||||
"built " __DATE__ " "__TIME__ "\n",
|
||||
MYMPD_VERSION_MAJOR, MYMPD_VERSION_MINOR, MYMPD_VERSION_PATCH);
|
||||
return EXIT_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user