From 7b311d95f2e12c9e60b27292d57d58229466aa69 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Tue, 3 Apr 2018 12:52:43 +0200 Subject: [PATCH 01/19] Removed compiler warning regarding a "comparison of constant -1 with expression of type 'enum mpd_cmd_ids' is always false"; bit of clean-up --- src/mpd_client.c | 41 +++++++++++++++++++---------------------- src/mpd_client.h | 6 +++--- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index 1054ede17..dd43cbd56 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -1,14 +1,14 @@ /* ympd (c) 2013-2014 Andrew Karpow This project's homepage is: http://www.ympd.org - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along @@ -36,11 +36,11 @@ const char * mpd_cmd_strs[] = { }; char * get_arg1 (char *p) { - return strchr(p, ',') + 1; + return strchr(p, ',') + 1; } char * get_arg2 (char *p) { - return get_arg1(get_arg1(p)); + return get_arg1(get_arg1(p)); } static inline enum mpd_cmd_ids get_cmd_id(char *cmd) @@ -60,9 +60,6 @@ int callback_mpd(struct mg_connection *c) int int_buf; char *p_charbuf = NULL, *token; - if(cmd_id == -1) - return MG_TRUE; - if(mpd.conn_state != MPD_CONNECTED && cmd_id != MPD_API_SET_MPDHOST && cmd_id != MPD_API_GET_MPDHOST && cmd_id != MPD_API_SET_MPDPASS && cmd_id != MPD_API_GET_DIRBLEAPITOKEN) @@ -165,11 +162,11 @@ int callback_mpd(struct mg_connection *c) if((token = strtok(NULL, ",")) == NULL) goto out_browse; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); n = mpd_put_browse(mpd.buf, get_arg2(p_charbuf), uint_buf); out_browse: - free(p_charbuf); + free(p_charbuf); break; case MPD_API_ADD_TRACK: p_charbuf = strdup(c->content); @@ -179,7 +176,7 @@ int callback_mpd(struct mg_connection *c) if((token = strtok(NULL, ",")) == NULL) goto out_add_track; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); mpd_run_add(mpd.conn, get_arg1(p_charbuf)); out_add_track: @@ -193,7 +190,7 @@ int callback_mpd(struct mg_connection *c) if((token = strtok(NULL, ",")) == NULL) goto out_play_track; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); int_buf = mpd_run_add_id(mpd.conn, get_arg1(p_charbuf)); if(int_buf != -1) @@ -209,7 +206,7 @@ int callback_mpd(struct mg_connection *c) if((token = strtok(NULL, ",")) == NULL) goto out_playlist; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); mpd_run_load(mpd.conn, get_arg1(p_charbuf)); out_playlist: @@ -223,7 +220,7 @@ int callback_mpd(struct mg_connection *c) if((token = strtok(NULL, ",")) == NULL) goto out_save_queue; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); mpd_run_save(mpd.conn, get_arg1(p_charbuf)); out_save_queue: @@ -232,12 +229,12 @@ int callback_mpd(struct mg_connection *c) case MPD_API_SEARCH: p_charbuf = strdup(c->content); if(strcmp(strtok(p_charbuf, ","), "MPD_API_SEARCH")) - goto out_search; + goto out_search; if((token = strtok(NULL, ",")) == NULL) goto out_search; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(c->content); n = mpd_search(mpd.buf, get_arg1(p_charbuf)); out_search: @@ -246,12 +243,12 @@ int callback_mpd(struct mg_connection *c) case MPD_API_SEND_MESSAGE: p_charbuf = strdup(c->content); if(strcmp(strtok(p_charbuf, ","), "MPD_API_SEND_MESSAGE")) - goto out_send_message; + goto out_send_message; if((token = strtok(NULL, ",")) == NULL) goto out_send_message; - free(p_charbuf); + free(p_charbuf); p_charbuf = strdup(get_arg1(c->content)); if ( strtok(p_charbuf, ",") == NULL ) @@ -260,7 +257,7 @@ int callback_mpd(struct mg_connection *c) 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; @@ -481,9 +478,9 @@ char* mpd_get_artist(struct mpd_song const *song) str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0); if (str == NULL) { - return ""; + return ""; } else { - return str; + return str; } } @@ -493,9 +490,9 @@ char* mpd_get_album(struct mpd_song const *song) str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0); if (str == NULL) { - return ""; + return ""; } else { - return str; + return str; } } diff --git a/src/mpd_client.h b/src/mpd_client.h index 447dd563c..d35db2bce 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -1,21 +1,21 @@ /* ympd (c) 2013-2014 Andrew Karpow This project's homepage is: http://www.ympd.org - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + #ifndef __MPD_CLIENT_H__ #define __MPD_CLIENT_H__ From 5c3f660f8ff580063c18904b921848fccd52bf54 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Tue, 3 Apr 2018 13:20:56 +0200 Subject: [PATCH 02/19] Fixed typo; bit of clean-up --- htdocs/js/mpd.js | 45 +++++++++++++++++++++++---------------------- src/mpd_client.c | 1 - src/ympd.c | 4 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index ce2fd8e25..f284532eb 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -1,14 +1,14 @@ /* ympd (c) 2013-2014 Andrew Karpow This project's homepage is: https://www.ympd.org - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along @@ -82,7 +82,7 @@ var app = $.sammy(function() { add_all_songs.show(); } - $('#panel-heading').text("Browse database: "+browsepath); + $('#panel-heading').text("Browse Database: "+browsepath); var path_array = browsepath.split('/'); var full_path = ""; $.each(path_array, function(index, chunk) { @@ -289,7 +289,7 @@ function webSocketConnect() { }); return $helper; }; - + //Make queue table sortable $('#salamisandwich > tbody').sortable({ helper: fixHelperModified, @@ -352,7 +352,7 @@ function webSocketConnect() { var details = "" + obj.data[item].artist + "
" + obj.data[item].album + "" + obj.data[item].title + ""; } - $('#salamisandwich > tbody').append( + $('#salamisandwich > tbody').append( "" + "" + details + "" + minutes + ":" + (seconds < 10 ? '0' : '') + seconds + @@ -494,13 +494,13 @@ function webSocketConnect() { case 'outputnames': $('#btn-outputs-block button').remove(); if (obj.data.length > 1) { - $.each(obj.data, function(id, name){ + $.each(obj.data, function(id, name){ var btn = $(''); btn.appendTo($('#btn-outputs-block')); }); - } else { + } else { $('#btn-outputs-block').addClass('hide'); - } + } /* remove cache, since the buttons have been recreated */ last_outputs = ''; break; @@ -532,7 +532,7 @@ function webSocketConnect() { $('#album').text(""); $('#artist').text(""); - $('#btnlove').removeClass("active"); + $('#btnlove').removeClass("active"); $('#currenttrack').text(" " + obj.data.title); var notification = "

" + obj.data.title + "

"; @@ -553,7 +553,7 @@ function webSocketConnect() { message:{html: notification}, type: "info", }).show(); - + break; case 'mpdhost': $('#mpdhost').val(obj.data.host); @@ -563,16 +563,16 @@ function webSocketConnect() { break; case 'dirbleapitoken': dirble_api_token = obj.data; - - if (dirble_api_token) { - $('#dirble').removeClass('hide'); + + if (dirble_api_token) { + $('#dirble').removeClass('hide'); if (dirble_stations) { dirble_load_stations(); } else { dirble_load_categories(); } } else { $('#dirble').addClass('hide'); - } + } break; case 'error': $('.top-right').notify({ @@ -608,9 +608,9 @@ function get_appropriate_ws_url() var separator; /* - /* We open the websocket encrypted if this page came on an - /* https:// url itself, otherwise unencrypted - /*/ + * We open the websocket encrypted if this page came + * on a https:// url itself, otherwise unencrypted + */ if (u.substring(0, 5) == "https") { pcol = "wss://"; @@ -710,10 +710,10 @@ function basename(path) { function clickLove() { socket.send("MPD_API_SEND_MESSAGE,mpdas," + ($('#btnlove').hasClass('active') ? "unlove" : "love")); - if ( $('#btnlove').hasClass('active') ) - $('#btnlove').removeClass("active"); - else - $('#btnlove').addClass("active"); + if ( $('#btnlove').hasClass('active') ) + $('#btnlove').removeClass("active"); + else + $('#btnlove').addClass("active"); } $('#btnrandom').on('click', function (e) { @@ -858,7 +858,8 @@ function notificationsSupported() { } function songNotify(title, artist, album) { - /*var opt = { +/* + var opt = { type: "list", title: title, message: title, diff --git a/src/mpd_client.c b/src/mpd_client.c index dd43cbd56..58efb8d0b 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -758,7 +758,6 @@ int mpd_search(char *buffer, char *searchstr) return cur - buffer; } - void mpd_disconnect() { mpd.conn_state = MPD_DISCONNECT; diff --git a/src/ympd.c b/src/ympd.c index 3aed7e678..56a5ac216 100644 --- a/src/ympd.c +++ b/src/ympd.c @@ -1,14 +1,14 @@ /* ympd (c) 2013-2014 Andrew Karpow This project's homepage is: http://www.ympd.org - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along From 87c596c60ca58c9bb8a2643e184830fb870094f6 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Wed, 4 Apr 2018 21:32:01 +0200 Subject: [PATCH 03/19] Make sorting while browsing the database case insensitive. --- htdocs/js/mpd.js | 16 ++++++++++++---- src/mpd_client.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index f284532eb..a4eaebcb2 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -82,7 +82,8 @@ var app = $.sammy(function() { add_all_songs.show(); } - $('#panel-heading').text("Browse Database: "+browsepath); + $('#panel-heading').text("Browse Database" + (browsepath ? ': ' : '') + browsepath); + var path_array = browsepath.split('/'); var full_path = ""; $.each(path_array, function(index, chunk) { @@ -309,7 +310,12 @@ function webSocketConnect() { if ($('#salamisandwich > tbody').is(':ui-sortable')) { $('#salamisandwich > tbody').sortable('destroy'); } - for (var item in obj.data) { + + var obj_data = obj.data.map((x,i) => [x.srt,i]).sort(); + + for (var i = 0; i < obj_data.length; i++) { + var item = obj_data[i][1]; + switch(obj.data[item].type) { case 'directory': var clazz = 'dir'; @@ -494,8 +500,10 @@ function webSocketConnect() { case 'outputnames': $('#btn-outputs-block button').remove(); if (obj.data.length > 1) { - $.each(obj.data, function(id, name){ - var btn = $(''); + $.each(obj.data, function(id, name){ + var btn = $(''); btn.appendTo($('#btn-outputs-block')); }); } else { diff --git a/src/mpd_client.c b/src/mpd_client.c index 58efb8d0b..017d11cb4 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -16,6 +16,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include @@ -540,7 +541,7 @@ int mpd_put_outputs(char *buffer, int names) char *str, *strend; str = buffer; - strend = buffer+MAX_SIZE; + strend = buffer + MAX_SIZE; str += snprintf(str, strend-str, "{\"type\":\"%s\", \"data\":{", names ? "outputnames" : "outputs"); @@ -563,7 +564,7 @@ int mpd_put_outputs(char *buffer, int names) return 0; } str += snprintf(str, strend-str, " }}"); - return str-buffer; + return str - buffer; } int mpd_put_current_song(char *buffer) @@ -584,8 +585,8 @@ int mpd_put_current_song(char *buffer) cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song)); 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, "}}"); + mpd_song_free(song); mpd_response_finish(mpd.conn); @@ -646,8 +647,10 @@ int mpd_put_browse(char *buffer, char *path, unsigned int offset) cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"browse\",\"data\":[ "); while((entity = mpd_recv_entity(mpd.conn)) != NULL) { + int i = 0, j = 0; + char srt[256] = ""; + const char *dir; const struct mpd_song *song; - const struct mpd_directory *dir; const struct mpd_playlist *pl; if(offset > entity_count) @@ -659,9 +662,9 @@ int mpd_put_browse(char *buffer, char *path, unsigned int offset) else if(offset + MAX_ELEMENTS_PER_PAGE - 1 < entity_count) { mpd_entity_free(entity); - cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\",\"count\":"); + cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\",\"count\":"); cur += json_emit_int(cur, end - cur, entity_count); - cur += json_emit_raw_str(cur, end - cur, "} "); + cur += json_emit_raw_str(cur, end - cur, ",\"srt\":\"\"}"); break; } @@ -677,22 +680,36 @@ int mpd_put_browse(char *buffer, char *path, unsigned int offset) cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song)); 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, "},"); + cur += json_emit_raw_str(cur, end - cur, ",\"srt\":\"\"},"); break; case MPD_ENTITY_TYPE_DIRECTORY: - dir = mpd_entity_get_directory(entity); + dir = mpd_directory_get_path(mpd_entity_get_directory(entity)); + + for (; dir[i]; i++) { + /* Filter any ".". */ + if (dir[i] == '.') { continue; } + /* Limit sorting string to current (sub-) directory. */ + if (dir[i] == '/') { + srt[0] = '\0'; j = 0; + } else { + srt[j++] = tolower(dir[i]); + if (j > 254) { srt[255] = '\0'; break; } + } + } cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"directory\",\"dir\":"); - cur += json_emit_quoted_str(cur, end - cur, mpd_directory_get_path(dir)); + cur += json_emit_quoted_str(cur, end - cur, dir); + cur += json_emit_raw_str(cur, end - cur, ",\"srt\":"); + cur += json_emit_quoted_str(cur, end - cur, srt); cur += json_emit_raw_str(cur, end - cur, "},"); break; case MPD_ENTITY_TYPE_PLAYLIST: - pl = mpd_entity_get_playlist(entity); + pl = mpd_entity_get_playlist(entity); cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"playlist\",\"plist\":"); cur += json_emit_quoted_str(cur, end - cur, mpd_playlist_get_path(pl)); - cur += json_emit_raw_str(cur, end - cur, "},"); + cur += json_emit_raw_str(cur, end - cur, ",\"srt\":\"zzzzz\"},"); break; } mpd_entity_free(entity); From c077de4ea3c0bae8f6cd14ab2dd12e52a6caaace Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Wed, 4 Apr 2018 19:49:51 +0200 Subject: [PATCH 04/19] Empty search string doesn't trigger an actual search anymore, since it would just timeout anyways; split-up of a few very long lines. --- htdocs/js/mpd.js | 104 +++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index ce2fd8e25..2e110ee26 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -42,7 +42,7 @@ var app = $.sammy(function() { $('#filter').addClass('hide'); $('#salamisandwich').removeClass('hide').find("tr:gt(0)").remove(); $('#dirble_panel').addClass('hide'); - socket.send('MPD_API_GET_QUEUE,'+pagination); + socket.send('MPD_API_GET_QUEUE,' + pagination); $('#panel-heading').text("Queue"); $('#queue').addClass('active'); @@ -67,17 +67,18 @@ var app = $.sammy(function() { browsepath = this.params['splat'][1]; pagination = parseInt(this.params['splat'][0]); current_app = 'browse'; - $('#breadcrump').removeClass('hide').empty().append("
  • root
  • "); + $('#breadcrump').removeClass('hide').empty().append( + "
  • root
  • "); $('#filter').removeClass('hide'); $('#salamisandwich').removeClass('hide').find("tr:gt(0)").remove(); $('#dirble_panel').addClass('hide'); - socket.send('MPD_API_GET_BROWSE,'+pagination+','+(browsepath ? browsepath : "/")); + socket.send('MPD_API_GET_BROWSE,' + pagination + ',' + (browsepath ? browsepath : "/")); // Don't add all songs from root if (browsepath) { var add_all_songs = $('#add-all-songs'); add_all_songs.off(); // remove previous binds add_all_songs.on('click', function() { - socket.send('MPD_API_ADD_TRACK,'+browsepath); + socket.send('MPD_API_ADD_TRACK,' + browsepath); }); add_all_songs.show(); } @@ -87,12 +88,12 @@ var app = $.sammy(function() { var full_path = ""; $.each(path_array, function(index, chunk) { if(path_array.length - 1 == index) { - $('#breadcrump').append("
  • "+ chunk + "
  • "); + $('#breadcrump').append("
  • " + chunk + "
  • "); return; } full_path = full_path + chunk; - $('#breadcrump').append("
  • "+chunk+"
  • "); + $('#breadcrump').append("
  • " + chunk + "
  • "); full_path += "/"; }); $('#browse').addClass('active'); @@ -102,18 +103,20 @@ var app = $.sammy(function() { current_app = 'search'; $('#salamisandwich').find("tr:gt(0)").remove(); $('#dirble_panel').addClass('hide'); - var searchstr = this.params['splat'][0]; - - $('#search > div > input').val(searchstr); - socket.send('MPD_API_SEARCH,' + searchstr); + var search_str = this.params['splat'][0]; - $('#panel-heading').text("Search: "+searchstr); + $('#search > div > input').val(search_str); + if (search_str !== "") { + socket.send('MPD_API_SEARCH,' + search_str); + $('#panel-heading').text("Search: " + search_str); + } }); this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() { prepare(); current_app = 'dirble'; - $('#breadcrump').removeClass('hide').empty().append("
  • Categories
  • "+dirble_selected_cat+"
  • "); + $('#breadcrump').removeClass('hide').empty().append( + "
  • Categories
  • " + dirble_selected_cat + "
  • "); $('#salamisandwich').addClass('hide'); $('#dirble_panel').removeClass('hide'); $('#dirble_loading').removeClass('hide'); @@ -391,9 +394,11 @@ function webSocketConnect() { }).fadeTo('fast',1); } - if ( isTouch ) { - appendClickableIcon($("#salamisandwich > tbody > tr.dir > td:last-child"), 'MPD_API_ADD_TRACK', 'plus'); - appendClickableIcon($("#salamisandwich > tbody > tr.song > td:last-child"), 'MPD_API_ADD_TRACK', 'play'); + if (isTouch) { + appendClickableIcon( + $("#salamisandwich > tbody > tr.dir > td:last-child"), 'MPD_API_ADD_TRACK', 'plus'); + appendClickableIcon( + $("#salamisandwich > tbody > tr.song > td:last-child"), 'MPD_API_ADD_TRACK', 'play'); } else { $('#salamisandwich > tbody > tr').on({ mouseenter: function() { @@ -462,7 +467,8 @@ function webSocketConnect() { total_minutes + ":" + (total_seconds < 10 ? '0' : '') + total_seconds); $('#salamisandwich > tbody > tr').removeClass('active').css("font-weight", ""); - $('#salamisandwich > tbody > tr[trackid='+obj.data.currentsongid+']').addClass('active').css("font-weight", "bold"); + $('#salamisandwich > tbody > tr[trackid=' + + obj.data.currentsongid + ']').addClass('active').css("font-weight", "bold"); if(obj.data.random) $('#btnrandom').addClass("active") @@ -494,13 +500,15 @@ function webSocketConnect() { case 'outputnames': $('#btn-outputs-block button').remove(); if (obj.data.length > 1) { - $.each(obj.data, function(id, name){ - var btn = $(''); + $.each(obj.data, function(id, name){ + var btn = $(''); btn.appendTo($('#btn-outputs-block')); }); - } else { + } else { $('#btn-outputs-block').addClass('hide'); - } + } /* remove cache, since the buttons have been recreated */ last_outputs = ''; break; @@ -525,7 +533,7 @@ function webSocketConnect() { break; case 'update_queue': if(current_app === 'queue') - socket.send('MPD_API_GET_QUEUE,'+pagination); + socket.send('MPD_API_GET_QUEUE,' + pagination); break; case 'song_change': @@ -776,11 +784,15 @@ function getHost() { } $('#search').submit(function () { - app.setLocation("#/search/"+$('#search > div > input').val()); - $('#wait').modal('show'); - setTimeout(function() { - $('#wait').modal('hide'); - }, 10000); + var search_str = $('#search > div > input').val(); + app.setLocation("#/search/" + search_str); + + if (search_str !== "") { + $('#wait').modal('show'); + setTimeout(function() { + $('#wait').modal('hide'); + }, 10000); + } return false; }); @@ -907,7 +919,7 @@ function dirble_load_categories() { dirble_page = 1; - $.getJSON( "https://api.dirble.com/v2/categories?token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/categories?token=" + dirble_api_token, function( data ) { $('#dirble_loading').addClass('hide'); @@ -917,20 +929,20 @@ function dirble_load_categories() { var max = data.length - data.length%2; - for(i = 0; i < max; i+=2) { + for(i = 0; i < max; i += 2) { $('#dirble_left > tbody').append( - ""+data[i].title+"" + "" + data[i].title + "" ); $('#dirble_right > tbody').append( - ""+data[i+1].title+"" + "" + data[i+1].title + "" ); } if (max != data.length) { $('#dirble_left > tbody').append( - ""+data[max].title+"" + "" + data[max].title + "" ); } @@ -938,7 +950,7 @@ function dirble_load_categories() { click: function() { dirble_selected_cat = $(this).text(); dirble_catid = $(this).attr("catid"); - app.setLocation("#/dirble/"+dirble_catid+"/"+dirble_page); + app.setLocation("#/dirble/" + dirble_catid + "/" + dirble_page); } }); @@ -946,7 +958,7 @@ function dirble_load_categories() { click: function() { dirble_selected_cat = $(this).text(); dirble_catid = $(this).attr("catid"); - app.setLocation("#/dirble/"+dirble_catid+"/"+dirble_page); + app.setLocation("#/dirble/" + dirble_catid + "/" + dirble_page); } }); }); @@ -955,7 +967,8 @@ function dirble_load_categories() { function dirble_load_stations() { - $.getJSON( "https://api.dirble.com/v2/category/"+dirble_catid+"/stations?page="+dirble_page+"&per_page=20&token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/category/" + dirble_catid + + "/stations?page=" + dirble_page + "&per_page=20&token=" + dirble_api_token, function( data ) { $('#dirble_loading').addClass('hide'); if (data.length == 20) $('#next').removeClass('hide'); @@ -965,16 +978,16 @@ function dirble_load_stations() { for(i = 0; i < max; i+=2) { $('#dirble_left > tbody').append( - ""+data[i].name+"" + "" + data[i].name + "" ); $('#dirble_right > tbody').append( - ""+data[i+1].name+"" + "" + data[i+1].name + "" ); } if (max != data.length) { $('#dirble_left > tbody').append( - ""+data[max].name+"" + "" + data[max].name + "" ); } @@ -982,7 +995,8 @@ function dirble_load_stations() { click: function() { var _this = $(this); - $.getJSON( "https://api.dirble.com/v2/station/"+$(this).attr("radioid")+"?token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/station/" + + $(this).attr("radioid") + "?token=" + dirble_api_token, function( data ) { socket.send("MPD_API_ADD_TRACK," + data.streams[0].stream); $('.top-right').notify({ @@ -1000,7 +1014,8 @@ function dirble_load_stations() { "").find('a').click(function(e) { e.stopPropagation(); - $.getJSON( "https://api.dirble.com/v2/station/"+_this.attr("radioid")+"?token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/station/" + + _this.attr("radioid") + "?token=" + dirble_api_token, function( data ) { socket.send("MPD_API_ADD_PLAY_TRACK," + data.streams[0].stream); $('.top-right').notify({ @@ -1021,7 +1036,8 @@ function dirble_load_stations() { click: function() { var _this = $(this); - $.getJSON( "https://api.dirble.com/v2/station/"+$(this).attr("radioid")+"?token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/station/" + + $(this).attr("radioid") + "?token=" + dirble_api_token, function( data ) { socket.send("MPD_API_ADD_TRACK," + data.streams[0].stream); $('.top-right').notify({ @@ -1036,10 +1052,11 @@ function dirble_load_stations() { $(this).last().append( "" + - "").find('a').click(function(e) { + "").find('a').click(function(e) { e.stopPropagation(); - $.getJSON( "https://api.dirble.com/v2/station/"+_this.attr("radioid")+"?token=" + dirble_api_token, function( data ) { + $.getJSON("https://api.dirble.com/v2/station/" + + _this.attr("radioid") + "?token=" + dirble_api_token, function( data ) { socket.send("MPD_API_ADD_PLAY_TRACK," + data.streams[0].stream); $('.top-right').notify({ @@ -1108,5 +1125,6 @@ function add_filter () { $('#filter').append(' ' + c + ''); } - $('#filter').append(' '); + $('#filter').append( + ' '); } From 54e334a2a0cb60b6df4d1c336fdfdee5fbefbeb5 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Wed, 4 Apr 2018 15:04:25 +0200 Subject: [PATCH 05/19] Added additional "totalTime" field to "obj" for the queue's total time. --- src/mpd_client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mpd_client.c b/src/mpd_client.c index 1054ede17..9679b2b85 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -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; } From 0faf70ad05b90731638c6d760a59a0036ecc6d36 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Wed, 4 Apr 2018 19:40:12 +0200 Subject: [PATCH 06/19] Add queue's total time to panel header. --- htdocs/index.html | 9 +++++---- htdocs/js/mpd.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index 6bf5c60cc..eb3319a3e 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -81,10 +81,11 @@
    - +
    -
    Queue
    +
    Queue +

    @@ -218,7 +219,7 @@

    ympd uses following excellent software:
    Mongoose GPLv2

    libMPDClient BSD License
    -
    +
    '); + $.each(obj.data, function(id, name){ + var btn = $(''); btn.appendTo($('#btn-outputs-block')); }); - } else { + } else { $('#btn-outputs-block').addClass('hide'); - } + } /* remove cache, since the buttons have been recreated */ last_outputs = ''; break; diff --git a/src/mpd_client.c b/src/mpd_client.c index acee301d4..81d4b1794 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -8,7 +8,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along diff --git a/src/mpd_client.h b/src/mpd_client.h index d35db2bce..5517984e6 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -8,7 +8,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along diff --git a/src/ympd.c b/src/ympd.c index 56a5ac216..f3f05e389 100644 --- a/src/ympd.c +++ b/src/ympd.c @@ -8,7 +8,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along From 1ebb14abbe0b955c4b591c3c8306ed527f780479 Mon Sep 17 00:00:00 2001 From: eb041592 <35889760+eb041592@users.noreply.github.com> Date: Mon, 9 Apr 2018 12:29:47 +0200 Subject: [PATCH 18/19] Set focus on text input after clicking "Save Queue"; clear input after saving queue --- htdocs/index.html | 6 +++--- htdocs/js/mpd.js | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index eb3319a3e..312d3c430 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -308,9 +308,9 @@