mirror of
https://github.com/SuperBFG7/ympd
synced 2024-12-25 02:20:27 +00:00
Fix: improve apitest
This commit is contained in:
parent
08acd687b7
commit
8234b342df
@ -17,7 +17,7 @@
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand navbar-dark fixed-top bg-dark">
|
||||
<a class="navbar-brand" data-toggle="dropdown" href="#">
|
||||
<a class="navbar-brand" href="#">
|
||||
<span class="material-icons header-logo">play_circle_outline</span>myMPD
|
||||
</a>
|
||||
</nav>
|
||||
|
@ -1,68 +1,103 @@
|
||||
"use strict";
|
||||
/* myMPD
|
||||
(c) 2018 Juergen Mang <mail@jcgames.de>
|
||||
This project's homepage is: https://github.com/jcorporation/mympd
|
||||
|
||||
myMPD ist fork of:
|
||||
|
||||
ympd
|
||||
(c) 2013-2014 Andrew Karpow <andy@ndyk.de>
|
||||
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
|
||||
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.
|
||||
*/
|
||||
|
||||
var i = 0;
|
||||
var failed = 0;
|
||||
var ok = 0;
|
||||
var trackId = 0;
|
||||
var outputId = 0;
|
||||
var uri1 = '';
|
||||
var album1 = '';
|
||||
var artist1 = '';
|
||||
var uri2 = '';
|
||||
var album2 = '';
|
||||
var artist2 = '';
|
||||
var searchstr = 'tabula';
|
||||
|
||||
var cmds = [
|
||||
'{"cmd":"MPD_API_WELCOME"}',
|
||||
'{"cmd":"MPD_API_QUEUE_CLEAR"}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK","data":{"uri":"Various-Captain_Future"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"__SEARCHSTR__","plist":""}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK","data":{"uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"__SEARCHSTR__","plist":"queue"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_LIST","data":{"offset":0}}',
|
||||
'{"cmd":"MPD_API_QUEUE_MOVE_TRACK","data":{"from":0,"to":1}}',
|
||||
'{"cmd":"MPD_API_QUEUE_MOVE_TRACK","data":{"from":1,"to":2}}',
|
||||
'{"cmd":"MPD_API_QUEUE_RM_RANGE","data":{"start":1,"end":-1}}',
|
||||
'{"cmd":"MPD_API_PLAYER_PLAY_TRACK","data":{"track":__TRACKID__}}',
|
||||
'{"cmd":"MPD_API_PLAYER_SEEK","data":{"songid":__TRACKID__,"seek":10}}',
|
||||
'{"cmd":"MPD_API_QUEUE_RM_TRACK","data":{"track":__TRACKID__}}',
|
||||
'{"cmd":"MPD_API_QUEUE_SAVE","data":{"plist":"test"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"ch"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_PLAY_TRACK","data":{"uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"__SEARCHSTR__"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_PLAY_TRACK","data":{"uri":"__URI2__"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_SHUFFLE"}',
|
||||
'{"cmd":"MPD_API_QUEUE_REPLACE_TRACK","data":{"uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK_AFTER","data":{"uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3","to":1}',
|
||||
'{"cmd":"MPD_API_QUEUE_REPLACE_TRACK","data":{"uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK_AFTER","data":{"uri":"__URI1__","to":1}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_RENAME","data":{"from":"test","to":"test2"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_CONTENT_LIST","data":{"uri":"test2","offset":0,"filter":""}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_PLAYLIST","data":{"plist":"test2"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_REPLACE_PLAYLIST","data":{"plist":"test2"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_LIST","data":{"offset":0,"filter":""}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_CLEAR","data":{"uri":"test2"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"__SEARCHSTR__","plist":"test2"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_CROP"}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK","data":{"uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_QUEUE_ADD_TRACK","data":{"uri":"__URI2__"}}',
|
||||
'{"cmd":"MPD_API_PLAYER_PLAY"}',
|
||||
'{"cmd":"MPD_API_QUEUE_LAST_PLAYED","data":{"offset":0}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_ADD_TRACK","data":{"plist":"test2","uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_ADD_TRACK","data":{"plist":"test2","uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_ADD_TRACK","data":{"plist":"test2","uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_ADD_TRACK","data":{"plist":"test2","uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_MOVE_TRACK","data":{"plist":"test2","from":1,"to":2}}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_RM_TRACK","data":{"uri":"test2","track":1}',
|
||||
'{"cmd":"MPD_API_PLAYLIST_RM","data":{"uri":"test2"}}',
|
||||
'{"cmd":"MPD_API_SMARTPLS_UPDATE_ALL"}',
|
||||
'{"cmd":"MPD_API_SMARTPLS_SAVE"}',
|
||||
'{"cmd":"MPD_API_SMARTPLS_GET"}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH_ADV","data":{"offset":0,"expression":"(any contains \'ch\')","sort":"Title", "sortdesc":false,"plist":""}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH","data":{"offset":0,"filter":"any","searchstr":"ch","plist":""}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SEARCH_ADV","data":{"offset":0,"expression":"(any contains \'__SEARCHSTR__\')","sort":"Title", "sortdesc":false,"plist":""}}',
|
||||
'{"cmd":"MPD_API_DATABASE_UPDATE"}',
|
||||
'{"cmd":"MPD_API_DATABASE_RESCAN"}',
|
||||
// '{"cmd":"MPD_API_DATABASE_RESCAN"}',
|
||||
'{"cmd":"MPD_API_DATABASE_FILESYSTEM_LIST","data":{"offset":0,"filter":"","path":""}}',
|
||||
'{"cmd":"MPD_API_DATABASE_TAG_LIST","data":{"offset":0,"filter":"","tag":"Artist"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_TAG_ALBUM_LIST","data":{"offset":0,"filter":"","search":"Christian Bruhn","tag":"Artist"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_TAG_ALBUM_TITLE_LIST","data":{"album":"Captain Future","search":"Christian Bruhn","tag":"Artist"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_TAG_ALBUM_LIST","data":{"offset":0,"filter":"","search":"__ARTIST1__","tag":"Artist"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_TAG_ALBUM_TITLE_LIST","data":{"album":"__ALBUM1__","search":"__ARTIST1__","tag":"Artist"}}',
|
||||
'{"cmd":"MPD_API_DATABASE_STATS"}',
|
||||
'{"cmd":"MPD_API_DATABASE_SONGDETAILS","data":{"uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3"}}',
|
||||
'{"cmd":"MPD_API_PLAYER_VOLUME_SET","data":{"volume":10}}',
|
||||
'{"cmd":"MPD_API_DATABASE_SONGDETAILS","data":{"uri":"__URI1__"}}',
|
||||
'{"cmd":"MPD_API_PLAYER_VOLUME_SET","data":{"volume":30}}',
|
||||
'{"cmd":"MPD_API_PLAYER_VOLUME_GET"}',
|
||||
'{"cmd":"MPD_API_PLAYER_PAUSE"}',
|
||||
'{"cmd":"MPD_API_PLAYER_STOP"}',
|
||||
'{"cmd":"MPD_API_PLAYER_PLAY"}',
|
||||
'{"cmd":"MPD_API_PLAYER_NEXT"}',
|
||||
'{"cmd":"MPD_API_PLAYER_CURRENT_SONG"}',
|
||||
'{"cmd":"MPD_API_PLAYER_PREV"}',
|
||||
'{"cmd":"MPD_API_PLAYER_PAUSE"}',
|
||||
'{"cmd":"MPD_API_PLAYER_STOP"}',
|
||||
'{"cmd":"MPD_API_PLAYER_OUTPUT_LIST"}',
|
||||
'{"cmd":"MPD_API_PLAYER_TOGGLE_OUTPUT","data":{"output":"__OUTPUTID__","state":0}}',
|
||||
'{"cmd":"MPD_API_PLAYER_CURRENT_SONG"}',
|
||||
'{"cmd":"MPD_API_PLAYER_TOGGLE_OUTPUT","data":{"output":"__OUTPUTID__","state":1}}',
|
||||
'{"cmd":"MPD_API_PLAYER_STATE"}',
|
||||
'{"cmd":"MPD_API_SETTINGS_GET"}',
|
||||
'{"cmd":"MPD_API_SETTINGS_SET"}',
|
||||
'{"cmd":"MPD_API_LIKE","data":{"uri":"Various-Captain_Future/01.Christian_Bruhn-Captain_Future.mp3","like":2}}',
|
||||
'{"cmd":"MPD_API_SYSCMD"}',
|
||||
'{"cmd":"MPD_API_COLS_SAVE"}'
|
||||
'{"cmd":"MPD_API_SETTINGS_SET", "data":{"random": 0}}',
|
||||
'{"cmd":"MPD_API_LIKE","data":{"uri":"__URI2__","like":2}}',
|
||||
'{"cmd":"MPD_API_SYSCMD", "data":{"cmd": "Echo"}}'
|
||||
// '{"cmd":"MPD_API_COLS_SAVE"}',
|
||||
// '{"cmd":"MPD_API_SMARTPLS_UPDATE_ALL"}',
|
||||
// '{"cmd":"MPD_API_SMARTPLS_SAVE"}',
|
||||
// '{"cmd":"MPD_API_SMARTPLS_GET"}'
|
||||
];
|
||||
|
||||
function setTest(cmd, state, response) {
|
||||
@ -73,7 +108,7 @@ function setTest(cmd, state, response) {
|
||||
document.getElementById('testCount').innerText = 'Test ' + (i + 1) + '/' + cmds.length + ' - ' +
|
||||
ok + ' ok, ' + failed + ' failed';
|
||||
var tr = document.createElement('tr');
|
||||
tr.innerHTML = '<td>' + i + '</td><td>' + cmd + '</td><td class="td-' + state + '"> </td><td>' + response + '</td>';
|
||||
tr.innerHTML = '<td>' + (i + 1) + '</td><td>' + cmd + '</td><td class="td-' + state + '"> </td><td>' + response + '</td>';
|
||||
document.getElementsByTagName('tbody')[0].appendChild(tr);
|
||||
}
|
||||
|
||||
@ -84,15 +119,34 @@ function sendAPI(request, callback) {
|
||||
ajaxRequest.onreadystatechange = function() {
|
||||
if (ajaxRequest.readyState == 4) {
|
||||
if (ajaxRequest.responseText != '') {
|
||||
var obj = JSON.parse(ajaxRequest.responseText);
|
||||
if (obj.type == 'queue' && obj.data.length > 0)
|
||||
trackId = obj.data[0].id;
|
||||
else if (obj.type == 'outputs' && obj.data.length > 0)
|
||||
ouputId = obj.data[0].id;
|
||||
if (obj.type == 'error')
|
||||
setTest(request, 'error', ajaxRequest.responseText);
|
||||
else
|
||||
setTest(request, 'ok', ajaxRequest.responseText);
|
||||
var obj;
|
||||
try {
|
||||
obj = JSON.parse(ajaxRequest.responseText);
|
||||
if (!obj.type)
|
||||
setTest(request, 'error', 'Invalid response: ' + ajaxRequest.responseText);
|
||||
else {
|
||||
if (obj.type == 'search' && obj.data.length > 1) {
|
||||
uri1 = obj.data[0].uri;
|
||||
artist1 = obj.data[0].Arist;
|
||||
album1 = obj.data[0].Album;
|
||||
uri2 = obj.data[1].uri;
|
||||
artist2 = obj.data[1].Arist;
|
||||
album2 = obj.data[1].Album;
|
||||
}
|
||||
else if (obj.type == 'queue' && obj.data.length > 0)
|
||||
trackId = obj.data[0].id;
|
||||
else if (obj.type == 'outputs' && obj.data.length > 0)
|
||||
ouputId = obj.data[0].id;
|
||||
|
||||
if (obj.type == 'error')
|
||||
setTest(request, 'error', ajaxRequest.responseText);
|
||||
else
|
||||
setTest(request, 'ok', ajaxRequest.responseText);
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
setTest(request, 'error', 'JSON parse error: ' + e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
setTest(request, 'error', ajaxRequest.responseText);
|
||||
@ -102,8 +156,15 @@ function sendAPI(request, callback) {
|
||||
sendAPI(cmds[i]);
|
||||
}
|
||||
};
|
||||
request = request.replace(/__TRACKID__/,trackId);
|
||||
request = request.replace(/__OUTPUTID__/,outputId);
|
||||
request = request.replace(/__TRACKID__/, trackId);
|
||||
request = request.replace(/__OUTPUTID__/, outputId);
|
||||
request = request.replace(/__URI1__/, uri1);
|
||||
request = request.replace(/__ARTIST1__/, artist1);
|
||||
request = request.replace(/__ALBUM1__/, album1);
|
||||
request = request.replace(/__URI2__/, uri2);
|
||||
request = request.replace(/__ARTIST2__/, artist2);
|
||||
request = request.replace(/__ALBUM2__/, album2);
|
||||
request = request.replace(/__SEARCHSTR__/, searchstr);
|
||||
ajaxRequest.send(request);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user