diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js
index ce2fd8e25..3bb558c06 100644
--- a/htdocs/js/mpd.js
+++ b/htdocs/js/mpd.js
@@ -1,7 +1,7 @@
/* 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.
@@ -42,9 +42,11 @@ 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");
+ $('#panel-heading-info').empty();
+
$('#queue').addClass('active');
}
@@ -67,53 +69,66 @@ 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();
}
- $('#panel-heading').text("Browse database: "+browsepath);
+ $('#panel-heading').text("Browse Database" + (browsepath ? ': ' : '') + browsepath);
+ $('#panel-heading-info').empty();$
+
var path_array = browsepath.split('/');
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');
+ $('#browse > a').attr('href', '#/browse/' + pagination + '/' + browsepath);
});
this.get(/\#\/search\/(.*)/, function() {
- current_app = 'search';
- $('#salamisandwich').find("tr:gt(0)").remove();
- $('#dirble_panel').addClass('hide');
- var searchstr = this.params['splat'][0];
+ var search_str = this.params['splat'][0];
- $('#search > div > input').val(searchstr);
- socket.send('MPD_API_SEARCH,' + searchstr);
+ if (search_str !== "") {
+ current_app = 'search';
- $('#panel-heading').text("Search: "+searchstr);
+ $('#search > div > input').val(search_str);
+
+ $('#salamisandwich').find("tr:gt(0)").remove();
+ $('#dirble_panel').addClass('hide');
+
+ socket.send('MPD_API_SEARCH,' + search_str);
+
+ $('#panel-heading').text("Search: " + search_str);
+ $('#panel-heading-info').empty();$
+ } else if (current_app == null) {
+ app.setLocation('/');
+ }
});
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');
@@ -121,6 +136,8 @@ var app = $.sammy(function() {
$('#dirble_right').find("tr:gt(0)").remove();
$('#panel-heading').text("Dirble");
+ $('#panel-heading-info').empty();
+
$('#dirble').addClass('active');
$('#next').addClass('hide');
@@ -147,6 +164,8 @@ var app = $.sammy(function() {
$('#dirble_right').find("tr:gt(0)").remove();
$('#panel-heading').text("Dirble");
+ $('#panel-heading-info').empty();
+
$('#dirble').addClass('active');
dirble_stations = false;
@@ -175,11 +194,18 @@ $(document).ready(function(){
$('#addstream').on('shown.bs.modal', function () {
$('#streamurl').focus();
- })
- $('#addstream form').on('submit', function (e) {
+ })
+ $('#addstream form').on('submit', function () {
addStream();
});
+ $('#savequeue').on('shown.bs.modal', function () {
+ $('#queuename').focus();
+ });
+ $('#savequeue form').on('submit', function () {
+ saveQueue();
+ });
+
if(!notificationsSupported())
$('#btnnotify').addClass("disabled");
else
@@ -222,6 +248,18 @@ function webSocketConnect() {
if(current_app !== 'queue')
break;
+ if (obj.totalTime > 0) {
+ var hours = Math.floor(obj.totalTime / 3600);
+ var minutes = Math.floor(obj.totalTime / 60) - hours * 60;
+ var seconds = obj.totalTime - hours * 3600 - minutes * 60;
+
+ $('#panel-heading-info').text('Total: ' +
+ (hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') +
+ minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s');
+ } else {
+ $('#panel-heading-info').empty();
+ }
+
$('#salamisandwich > tbody').empty();
for (var song in obj.data) {
var minutes = Math.floor(obj.data[song].duration / 60);
@@ -229,8 +267,8 @@ function webSocketConnect() {
$('#salamisandwich > tbody').append(
"| " + (obj.data[song].pos + 1) + " | " +
- "" + obj.data[song].artist + " " + obj.data[song].album + " | " +
- "" + obj.data[song].title + " | " +
+ "" + obj.data[song].artist + "" + obj.data[song].album + " | " +
+ "" + obj.data[song].title + " | " +
"" + minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
" | |
");
}
@@ -289,7 +327,7 @@ function webSocketConnect() {
});
return $helper;
};
-
+
//Make queue table sortable
$('#salamisandwich > tbody').sortable({
helper: fixHelperModified,
@@ -309,7 +347,14 @@ 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]);
+ /* Only sort if there's a non-empty string to sort after. */
+ if (obj_data[0][0] !== '') { obj_data = obj_data.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';
@@ -346,15 +391,17 @@ function webSocketConnect() {
var minutes = Math.floor(obj.data[item].duration / 60);
var seconds = obj.data[item].duration - minutes * 60;
- if (typeof obj.data[item].artist === 'undefined') {
- var details = "" + obj.data[item].title + " | ";
+ if (obj.data[item].artist == null) {
+ var artist = " colspan=\"2\">";
} else {
- var details = "" + obj.data[item].artist + " " + obj.data[item].album + " | " + obj.data[item].title + " | ";
+ var artist = ">" + obj.data[item].artist +
+ "" + obj.data[item].album + "";
}
- $('#salamisandwich > tbody').append(
+ $('#salamisandwich > tbody').append(
" | " +
- " | " + details +
+ " | " +
+ "" +
" | " + minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
" | |
"
);
@@ -391,9 +438,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() {
@@ -413,8 +462,8 @@ function webSocketConnect() {
case 'dir':
pagination = 0;
browsepath = $(this).attr("uri");
- $("#browse > a").attr("href", '#/browse/'+pagination+'/'+browsepath);
- app.setLocation('#/browse/'+pagination+'/'+browsepath);
+ $("#browse > a").attr("href", '#/browse/' + pagination + '/' + browsepath);
+ app.setLocation('#/browse/' + pagination + '/' + browsepath);
break;
case 'song':
socket.send("MPD_API_ADD_TRACK," + decodeURI($(this).attr("uri")));
@@ -462,7 +511,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")
@@ -525,14 +575,14 @@ 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':
$('#album').text("");
$('#artist').text("");
- $('#btnlove').removeClass("active");
+ $('#btnlove').removeClass("active");
$('#currenttrack').text(" " + obj.data.title);
var notification = "" + obj.data.title + "
";
@@ -553,7 +603,7 @@ function webSocketConnect() {
message:{html: notification},
type: "info",
}).show();
-
+
break;
case 'mpdhost':
$('#mpdhost').val(obj.data.host);
@@ -563,16 +613,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 +658,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 +760,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) {
@@ -776,11 +826,16 @@ 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();
+
+ if (search_str !== "") {
+ app.setLocation("#/search/" + search_str);
+
+ $('#wait').modal('show');
+ setTimeout(function() {
+ $('#wait').modal('hide');
+ }, 10000);
+ }
return false;
});
@@ -817,16 +872,17 @@ $('.page-btn').on('click', function (e) {
function addStream() {
if($('#streamurl').val().length > 0) {
- socket.send('MPD_API_ADD_TRACK,'+$('#streamurl').val());
+ socket.send('MPD_API_ADD_TRACK,' + $('#streamurl').val());
}
$('#streamurl').val("");
$('#addstream').modal('hide');
}
function saveQueue() {
- if($('#playlistname').val().length > 0) {
- socket.send('MPD_API_SAVE_QUEUE,'+$('#playlistname').val());
+ if($('#queuename').val().length > 0) {
+ socket.send('MPD_API_SAVE_QUEUE,' + $('#queuename').val());
}
+ $('#queuename').val("");
$('#savequeue').modal('hide');
}
@@ -858,7 +914,8 @@ function notificationsSupported() {
}
function songNotify(title, artist, album) {
- /*var opt = {
+/*
+ var opt = {
type: "list",
title: title,
message: title,
@@ -907,7 +964,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 +974,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 +995,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 +1003,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 +1012,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 +1023,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 +1040,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 +1059,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 +1081,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 +1097,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 +1170,6 @@ function add_filter () {
$('#filter').append(' ' + c + '');
}
- $('#filter').append(' ');
+ $('#filter').append(
+ ' ');
}
diff --git a/src/mpd_client.c b/src/mpd_client.c
index 1054ede17..81d4b1794 100644
--- a/src/mpd_client.c
+++ b/src/mpd_client.c
@@ -1,7 +1,7 @@
/* 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.
@@ -16,6 +16,7 @@
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include
#include
#include
#include
@@ -36,11 +37,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 +61,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 +163,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 +177,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 +191,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 +207,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 +221,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 +230,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 +244,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 +258,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;
@@ -463,6 +461,32 @@ void mpd_poll(struct mg_server *s)
}
}
+char* mpd_get_sort(const char *path, char *prefix)
+{
+ int i = 0, j;
+ int k = strlen(path);
+ int l = strlen(prefix);
+
+ char *str = malloc((k + l + 1) * (sizeof *str)); str[0] = '\0';
+
+ strncat(str,prefix,l);
+
+ j = l;
+ for ( ; path[i] && j < (k+l); i++) {
+ /* Filter any ".". */
+ if (path[i] == '.') { continue; }
+ /* Limit sorting to current (sub-) directory. */
+ if (path[i] == '/') {
+ str[j=l] = '\0';
+ } else {
+ str[j++] = tolower(path[i]);
+ }
+ }
+ str[j] = '\0';
+
+ return str;
+}
+
char* mpd_get_title(struct mpd_song const *song)
{
char *str;
@@ -481,9 +505,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 +517,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;
}
}
@@ -543,7 +567,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");
@@ -566,7 +590,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)
@@ -587,8 +611,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);
@@ -600,6 +624,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 +633,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 +652,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 +661,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;
}
@@ -649,9 +680,9 @@ 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) {
+ char *srt;
+ const char *pth;
const struct mpd_song *song;
- const struct mpd_directory *dir;
- const struct mpd_playlist *pl;
if(offset > entity_count)
{
@@ -662,9 +693,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;
}
@@ -680,22 +711,33 @@ 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);
+ pth = mpd_directory_get_path(mpd_entity_get_directory(entity));
+ srt = mpd_get_sort(pth,"");
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, pth);
+ 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, "},");
+
+ free(srt);
break;
case MPD_ENTITY_TYPE_PLAYLIST:
- pl = mpd_entity_get_playlist(entity);
+ pth = mpd_playlist_get_path(mpd_entity_get_playlist(entity));
+ srt = mpd_get_sort(pth,"~");
+
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_quoted_str(cur, end - cur, pth);
+ 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, "},");
+
+ free(srt);
break;
}
mpd_entity_free(entity);
@@ -761,7 +803,6 @@ int mpd_search(char *buffer, char *searchstr)
return cur - buffer;
}
-
void mpd_disconnect()
{
mpd.conn_state = MPD_DISCONNECT;
diff --git a/src/mpd_client.h b/src/mpd_client.h
index 447dd563c..5517984e6 100644
--- a/src/mpd_client.h
+++ b/src/mpd_client.h
@@ -1,7 +1,7 @@
/* 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.
@@ -15,7 +15,7 @@
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__
diff --git a/src/ympd.c b/src/ympd.c
index 3aed7e678..f3f05e389 100644
--- a/src/ympd.c
+++ b/src/ympd.c
@@ -1,7 +1,7 @@
/* 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.