var MAX_ELEMENTS_PER_PAGE = 512;
var isTouch = Modernizr.touch ? 1 : 0;
var filter = '';
+var scrobbler = '';
var app = $.sammy(function () {
function runBrowse() {
app.run();
/* emit initial request for output names */
socket.send('MPD_API_GET_OUTPUTS');
+ socket.send('MPD_API_GET_CHANNELS');
};
socket.onmessage = function got_packet(msg) {
});
last_outputs = obj;
break;
+ case 'channels':
+ scrobbler = '';
+ $('#love').addClass('hide');
+ if (Object.keys(obj.data).length) {
+ $.each(obj.data, function (id, name) {
+ switch (name) {
+ case 'mpdas':
+ case 'mpdscribble':
+ scrobbler = name;
+ $('#love').removeClass('hide');
+ default:
+ break;
+ }
+ });
+ }
+ break;
case 'disconnected':
if ($('.top-right').has('div').length == 0)
$('.top-right')
function clickLove() {
socket.send(
- 'MPD_API_SEND_MESSAGE,mpdas,' +
- ($('#btnlove').hasClass('active') ? 'unlove' : 'love')
- );
- socket.send(
- 'MPD_API_SEND_MESSAGE,mpdscribble,' +
+ 'MPD_API_SEND_MESSAGE,' +
+ scrobbler +
+ ',' +
($('#btnlove').hasClass('active') ? 'unlove' : 'love')
);
if ($('#btnlove').hasClass('active')) $('#btnlove').removeClass('active');
out_send_message:
free(p_charbuf);
break;
+ case MPD_API_GET_CHANNELS:
+ mpd.buf_size = mpd_put_channels(mpd.buf);
+ c->callback_param = NULL;
+ mpd_notify_callback(c, MG_POLL);
+ break;
#ifdef WITH_MPD_HOST_CHANGE
/* Commands allowed when disconnected from MPD server */
case MPD_API_SET_MPDHOST:
return str - buffer;
}
+int mpd_put_channels(char *buffer) {
+ struct mpd_pair *channel;
+ int nchan;
+ char *str, *strend;
+
+ str = buffer;
+ strend = buffer + MAX_SIZE;
+ str += snprintf(str, strend - str, "{\"type\":\"%s\", \"data\":{", "channels");
+
+ mpd_send_channels(mpd.conn);
+ nchan = 0;
+ while ((channel = mpd_recv_channel_pair(mpd.conn)) != NULL) {
+ if (nchan++)
+ *str++ = ',';
+ str += snprintf(str, strend - str, " \"%d\":\"%s\"", nchan, channel->value);
+ mpd_return_pair(mpd.conn, channel);
+ }
+ if (!mpd_response_finish(mpd.conn)) {
+ fprintf(stderr, "MPD outputs: %s\n", mpd_connection_get_error_message(mpd.conn));
+ mpd_connection_clear_error(mpd.conn);
+ return 0;
+ }
+ str += snprintf(str, strend - str, " }}");
+ return str - buffer;
+}
+
int mpd_put_current_song(char *buffer) {
char *cur = buffer;
const char *end = buffer + MAX_SIZE;
X(MPD_API_RM_ALL) \
X(MPD_API_MOVE_TRACK) \
X(MPD_API_SEARCH) \
+ X(MPD_API_GET_CHANNELS) \
X(MPD_API_SEND_MESSAGE) \
X(MPD_API_SET_VOLUME) \
X(MPD_API_SET_PAUSE) \
int mpd_close_handler(struct mg_connection *c);
int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version);
int mpd_put_outputs(char *buffer, int putnames);
+int mpd_put_channels(char *buffer);
int mpd_put_current_song(char *buffer);
int mpd_put_queue(char *buffer, unsigned int offset);
int mpd_put_browse(char *buffer, char *path, unsigned int offset);