mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-24 01:50:27 +00:00
Select tags for queue search
Queue toolbar improvements
This commit is contained in:
parent
2d57aa43f1
commit
577bc7843e
@ -98,18 +98,23 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="btn-toolbar" id="queue-buttons" role="toolbar">
|
||||
<div id="trashmode" class="btn-group mr-2" data-toggle="radio">
|
||||
<button id="btntrashmodeup" type="button" class="btn btn-secondary" title="Delete upward">
|
||||
<span class="material-icons">vertical_align_top</span>
|
||||
<span class="material-icons">delete</span>
|
||||
</button>
|
||||
<button id="btntrashmodesingle" type="button" class="btn btn-success" title="Delete single">
|
||||
<span class="material-icons">delete</span>
|
||||
</button>
|
||||
<button id="btntrashmodedown" type="button" class="btn btn-secondary" title="Delete downward">
|
||||
<span class="material-icons">delete</span>
|
||||
<span class="material-icons">vertical_align_bottom</span>
|
||||
</button>
|
||||
<div id="trashmode" class="btn-group mr-2">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown"><span class="material-icons">delete</span></button>
|
||||
<div class="dropdown-menu bg-dark px-2" id="trashmodebtns">
|
||||
<h6 class="dropdown-header text-light">Trashmode</h6>
|
||||
<button id="btntrashmodeup" type="button" class="btn btn-secondary btn-block">
|
||||
<span class="material-icons" style="float:left;">vertical_align_top</span>
|
||||
<span style="margin-left:1rem;">Delete upward</span>
|
||||
</button>
|
||||
<button id="btntrashmodesingle" type="button" class="btn btn-success btn-block">
|
||||
<span class="material-icons" style="float:left;">delete</span>
|
||||
<span style="margin-left:1rem;">Delete single</span>
|
||||
</button>
|
||||
<button id="btntrashmodedown" type="button" class="btn btn-secondary btn-block">
|
||||
<span class="material-icons" style="float:left;">vertical_align_bottom</span>
|
||||
<span style="margin-left:1rem;">Delete downward</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="queue-actions" class="btn-group mr-2">
|
||||
<button type="button" class="btn btn-secondary" onclick="socket.send('MPD_API_SEND_SHUFFLE');" title="Shuffle queue">
|
||||
@ -122,8 +127,20 @@
|
||||
<span class="material-icons">save</span>
|
||||
</button>
|
||||
</div>
|
||||
<form id="searchqueue" role="search" class="btn btn-secondary">
|
||||
<input type="text" class="form-control" placeholder="Search"/>
|
||||
<form id="searchqueue" role="search">
|
||||
<div class="input-group mr-2">
|
||||
<input type="text" class="form-control" placeholder="Search Queue" id="searchqueuestr"/>
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown"><span class="material-icons">search</span></button>
|
||||
<div class="dropdown-menu bg-dark dropdown-menu-right px-2" id="searchqueuetag">
|
||||
<h6 class="dropdown-header text-light">Search in Tag</h6>
|
||||
<button type="button" class="btn btn-success btn-block">Any Tag</button>
|
||||
<button type="button" class="btn btn-secondary btn-block">Title</button>
|
||||
<button type="button" class="btn btn-secondary btn-block">Artist</button>
|
||||
<button type="button" class="btn btn-secondary btn-block">Album</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@ -372,7 +389,7 @@
|
||||
|
||||
<script src="js/jquery-3.3.1.min.js"></script>
|
||||
<script src="js/js.cookie.js"></script>
|
||||
<script src="js/bootstrap.min.js"></script>
|
||||
<script src="js/bootstrap.bundle.min.js"></script>
|
||||
<script src="js/bootstrap-slider.min.js"></script>
|
||||
<script src="js/bootstrap-notify.min.js"></script>
|
||||
<script src="js/sammy.js"></script>
|
||||
|
2529
htdocs/js/bootstrap.js → htdocs/js/bootstrap.bundle.js
vendored
2529
htdocs/js/bootstrap.js → htdocs/js/bootstrap.bundle.js
vendored
File diff suppressed because it is too large
Load Diff
1
htdocs/js/bootstrap.bundle.js.map
Normal file
1
htdocs/js/bootstrap.bundle.js.map
Normal file
File diff suppressed because one or more lines are too long
7
htdocs/js/bootstrap.bundle.min.js
vendored
Normal file
7
htdocs/js/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
htdocs/js/bootstrap.bundle.min.js.map
Normal file
1
htdocs/js/bootstrap.bundle.min.js.map
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
7
htdocs/js/bootstrap.min.js
vendored
7
htdocs/js/bootstrap.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -206,19 +206,21 @@ function webSocketConnect() {
|
||||
case 'queue':
|
||||
if(current_app !== 'queue')
|
||||
break;
|
||||
|
||||
if (obj.totalTime > 0) {
|
||||
$('#panel-heading-queue').empty();
|
||||
|
||||
if (obj.totalSongs > 0) {
|
||||
$('#panel-heading-queue').text(obj.totalSongs+' Songs');
|
||||
}
|
||||
if (typeof(obj.totalTime) != undefined && obj.totalTime > 0 ) {
|
||||
var days = Math.floor(obj.totalTime / 86400);
|
||||
var hours = Math.floor(obj.totalTime / 3600) - days * 24;
|
||||
var minutes = Math.floor(obj.totalTime / 60) - hours * 60 - days * 1440;
|
||||
var seconds = obj.totalTime - days * 86400 - hours * 3600 - minutes * 60;
|
||||
|
||||
$('#panel-heading-queue').text(obj.totalSongs+' Songs – ' +
|
||||
|
||||
$('#panel-heading-queue').append(' – ' +
|
||||
(days > 0 ? days + '\u2009d ' : '') +
|
||||
(hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') +
|
||||
minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s');
|
||||
} else {
|
||||
$('#panel-heading-queue').empty();
|
||||
}
|
||||
|
||||
$('#queueList > tbody').empty();
|
||||
@ -694,8 +696,8 @@ function toggleoutput(button, id) {
|
||||
socket.send("MPD_API_TOGGLE_OUTPUT,"+id+"," + ($(button).hasClass('btn-success') ? 0 : 1));
|
||||
}
|
||||
|
||||
$('#trashmode').children("button").on('click', function(e) {
|
||||
$('#trashmode').children("button").removeClass("btn-success").addClass('btn-secondary');
|
||||
$('#trashmodebtns > button').on('click', function(e) {
|
||||
$('#trashmodebtns').children("button").removeClass("btn-success").addClass('btn-secondary');
|
||||
$(this).removeClass("btn-secondary").addClass("btn-success");
|
||||
});
|
||||
|
||||
@ -738,15 +740,30 @@ $('#search').submit(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#searchqueue > input').keyup(function (event) {
|
||||
var searchstr=$('#searchqueue > input').val();
|
||||
$('#searchqueuestr').keyup(function (event) {
|
||||
doQueueSearch();
|
||||
});
|
||||
|
||||
$('#searchqueuetag > button').on('click',function (e) {
|
||||
$('#searchqueuetag > button').removeClass('btn-success').addClass('btn-secondary');
|
||||
$(this).removeClass('btn-secondary').addClass('btn-success');
|
||||
doQueueSearch();
|
||||
});
|
||||
|
||||
function doQueueSearch() {
|
||||
var searchstr=$('#searchqueuestr').val();
|
||||
var mpdtag='Any Tag';
|
||||
$('#searchqueuetag > button').each(function() {
|
||||
if ($(this).hasClass('btn-success')) { mpdtag=$(this).text(); }
|
||||
});
|
||||
|
||||
if (searchstr.length >= 3) {
|
||||
socket.send('MPD_API_SEARCH_QUEUE,' + searchstr);
|
||||
socket.send('MPD_API_SEARCH_QUEUE,' + mpdtag + ',' + searchstr);
|
||||
}
|
||||
if (searchstr.length == 0) {
|
||||
socket.send('MPD_API_GET_QUEUE,0');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#searchqueue').submit(function () {
|
||||
return false;
|
||||
|
103
src/mpd_client.c
103
src/mpd_client.c
@ -65,6 +65,8 @@ int callback_mpd(struct mg_connection *c)
|
||||
unsigned int uint_buf, uint_buf_2;
|
||||
int int_buf;
|
||||
char *p_charbuf = NULL, *token;
|
||||
char *mpdtagtype = NULL;
|
||||
char *searchstr = NULL;
|
||||
|
||||
fprintf(stdout,"%s\n",c->content);
|
||||
|
||||
@ -233,16 +235,27 @@ out_save_queue:
|
||||
free(p_charbuf);
|
||||
break;
|
||||
case MPD_API_SEARCH_QUEUE:
|
||||
|
||||
p_charbuf = strdup(c->content);
|
||||
if(strcmp(strtok(p_charbuf, ","), "MPD_API_SEARCH_QUEUE"))
|
||||
goto out_search_queue;
|
||||
|
||||
if((token = strtok(NULL, ",")) == NULL)
|
||||
if((token = strtok(NULL, ",")) == NULL) {
|
||||
goto out_search_queue;
|
||||
} else {
|
||||
mpdtagtype = strdup(token);
|
||||
}
|
||||
|
||||
if((token = strtok(NULL, ",")) == NULL) {
|
||||
free(mpdtagtype);
|
||||
goto out_search;
|
||||
} else {
|
||||
searchstr = strdup(token);
|
||||
}
|
||||
|
||||
free(p_charbuf);
|
||||
p_charbuf = strdup(c->content);
|
||||
n = mpd_search_queue(mpd.buf, get_arg1(p_charbuf));
|
||||
//free(p_charbuf);
|
||||
//p_charbuf = strdup(c->content);
|
||||
n = mpd_search_queue(mpd.buf, mpdtagtype, searchstr);
|
||||
free(searchstr);
|
||||
out_search_queue:
|
||||
free(p_charbuf);
|
||||
break;
|
||||
@ -254,7 +267,7 @@ out_search_queue:
|
||||
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:
|
||||
@ -745,10 +758,10 @@ int mpd_put_browse(char *buffer, char *path, unsigned int offset)
|
||||
|
||||
int mpd_search(char *buffer, char *searchstr)
|
||||
{
|
||||
int i = 0;
|
||||
char *cur = buffer;
|
||||
const char *end = buffer + MAX_SIZE;
|
||||
struct mpd_song *song;
|
||||
unsigned long totalSongs = 0;
|
||||
|
||||
if(mpd_search_db_songs(mpd.conn, false) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_db_songs");
|
||||
@ -760,56 +773,71 @@ int mpd_search(char *buffer, char *searchstr)
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"search\",\"data\":[ ");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\"");
|
||||
// cur += json_emit_raw_str(cur, end - cur, ",\"uri\":");
|
||||
// cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(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, ",\"artist\":");
|
||||
cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
|
||||
totalSongs ++;
|
||||
if (totalSongs <=300) {
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\"");
|
||||
cur += json_emit_raw_str(cur, end - cur, ",\"uri\":");
|
||||
cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(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, ",\"artist\":");
|
||||
cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
|
||||
// cur += json_emit_raw_str(cur, end - cur, ",\"album_artist\":");
|
||||
// cur += json_emit_quoted_str(cur, end - cur, mpd_get_album_artist(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_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, "},");
|
||||
mpd_song_free(song);
|
||||
|
||||
/* Maximum results */
|
||||
if(i++ >= 300)
|
||||
{
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},");
|
||||
break;
|
||||
cur += json_emit_raw_str(cur, end - cur, ",\"duration\":");
|
||||
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, "},");
|
||||
}
|
||||
mpd_song_free(song);
|
||||
}
|
||||
|
||||
/* Maximum results */
|
||||
if(totalSongs++ > 300)
|
||||
{
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},");
|
||||
}
|
||||
|
||||
/* remove last ',' */
|
||||
cur--;
|
||||
|
||||
cur += json_emit_raw_str(cur, end - cur, "]}");
|
||||
cur += json_emit_raw_str(cur, end - cur, "]");
|
||||
cur += json_emit_raw_str(cur, end - cur, ",\"totalSongs\":");
|
||||
cur += json_emit_int(cur, end - cur, totalSongs);
|
||||
cur += json_emit_raw_str(cur, end - cur, "}");
|
||||
}
|
||||
return cur - buffer;
|
||||
}
|
||||
|
||||
int mpd_search_queue(char *buffer, char *searchstr)
|
||||
int mpd_search_queue(char *buffer, char *mpdtagtype, char *searchstr)
|
||||
{
|
||||
int i = 0;
|
||||
char *cur = buffer;
|
||||
const char *end = buffer + MAX_SIZE;
|
||||
struct mpd_song *song;
|
||||
unsigned long totalSongs = 0;
|
||||
|
||||
if(mpd_search_queue_songs(mpd.conn, false) == false)
|
||||
if(mpd_search_queue_songs(mpd.conn, false) == false) {
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_queue_songs");
|
||||
else if(mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
||||
else if(mpd_search_commit(mpd.conn) == false)
|
||||
}
|
||||
|
||||
if (mpd_tag_name_parse(mpdtagtype) != MPD_TAG_UNKNOWN) {
|
||||
if (mpd_search_add_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, mpd_tag_name_parse(mpdtagtype), searchstr) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_tag_constraint");
|
||||
}
|
||||
else {
|
||||
if (mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
|
||||
}
|
||||
|
||||
if(mpd_search_commit(mpd.conn) == false)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_search_commit");
|
||||
else {
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"queuesearch\",\"data\":[ ");
|
||||
|
||||
while((song = mpd_recv_song(mpd.conn)) != NULL) {
|
||||
if(i++ <= 100) {
|
||||
totalSongs ++;
|
||||
if(totalSongs <= 100) {
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\"");
|
||||
// cur += json_emit_raw_str(cur, end - cur, ",\"uri\":");
|
||||
// cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song));
|
||||
@ -832,12 +860,15 @@ int mpd_search_queue(char *buffer, char *searchstr)
|
||||
}
|
||||
}
|
||||
|
||||
if (i > 100) {
|
||||
if (totalSongs > 100) {
|
||||
cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},");
|
||||
}
|
||||
cur--;
|
||||
|
||||
cur += json_emit_raw_str(cur, end - cur, "]}");
|
||||
cur += json_emit_raw_str(cur, end - cur, "]");
|
||||
cur += json_emit_raw_str(cur, end - cur, ",\"totalSongs\":");
|
||||
cur += json_emit_int(cur, end - cur, totalSongs);
|
||||
cur += json_emit_raw_str(cur, end - cur, "}");
|
||||
}
|
||||
return cur - buffer;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ 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);
|
||||
int mpd_search(char *buffer, char *searchstr);
|
||||
int mpd_search_queue(char *buffer, char *searchstr);
|
||||
int mpd_search_queue(char *buffer, char *mp3tag, char *searchstr);
|
||||
void mpd_disconnect();
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user