code cleanup + relative URLs

This commit is contained in:
IrosTheBeggar 2021-06-15 19:14:33 -04:00
parent bf296d150e
commit 5bc034642f

View File

@ -34,7 +34,10 @@ function createFileplaylistHtml(dataDirectory) {
}
function createMusicfileHtml(fileLocation, title, titleClass) {
return '<div data-file_location="' + fileLocation + '" class="filez"><img class="music-image" src="/assets/img/music-note.svg"> <span class="' + titleClass + '">' + title + '</span></div>';
return `<div data-file_location="${fileLocation}" class="filez">
<svg class="music-image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path d="M9 37.5c-3.584 0-6.5-2.916-6.5-6.5s2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V5.429l25-3.846V29c0 3.584-2.916 6.5-6.5 6.5s-6.5-2.916-6.5-6.5 2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V11.023l-19 2.931V31c0 3.584-2.916 6.5-6.5 6.5z" fill="#8bb7f0"/><path d="M37 2.166V29c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V10.441l-1.152.178-18 2.776-.848.13V31c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V5.858l24-3.692M38 1L12 5v19.683A6.962 6.962 0 009 24a7 7 0 107 7V14.383l18-2.776v11.076A6.962 6.962 0 0031 22a7 7 0 107 7V1z" fill="#4e7ab5"/></svg>
<span class="${titleClass}">${title}</span>
</div>`;
}
$(document).ready(function () {
@ -503,7 +506,6 @@ $(document).ready(function () {
});
}
// function that will receive JSON array of a directory listing. It will then make a list of the directory and tack on classes for functionality
function printdir(response, previousState) {
currentBrowsingList = [];
@ -513,21 +515,7 @@ $(document).ready(function () {
if (response.directories) {
for (const dir of response.directories) {
currentBrowsingList.push({ type: 'directory', name: dir.name })
filelist +=
`<div class="clear relative">
<div data-directory="${dir.name}" class="dirz">
<img class="folder-image" src="/assets/img/folder.svg">
<span class="item-text">${dir.name}</span>
</div>
<div class="song-button-box">
<span title="Add All To Queue" class="recursiveAddDir" data-directory="${dir.name}">
<svg xmlns="http://www.w3.org/2000/svg" height="9" width="9" viewBox="0 0 1280 1276"><path d="M6760 12747 c-80 -5 -440 -10 -800 -11 -701 -2 -734 -4 -943 -57 -330 -84 -569 -281 -681 -563 -103 -256 -131 -705 -92 -1466 12 -241 16 -531 16 -1232 l0 -917 -1587 -4 c-1561 -3 -1590 -3 -1703 -24 -342 -62 -530 -149 -692 -322 -158 -167 -235 -377 -244 -666 -43 -1404 -42 -1813 7 -2355 21 -235 91 -400 233 -548 275 -287 730 -389 1591 -353 1225 51 2103 53 2330 7 l60 -12 6 -1489 c6 -1559 6 -1548 49 -1780 100 -535 405 -835 933 -921 88 -14 252 -17 1162 -24 591 -4 1099 -4 1148 1 159 16 312 56 422 112 118 59 259 181 333 290 118 170 195 415 227 722 18 173 21 593 6 860 -26 444 -32 678 -34 1432 l-2 811 54 7 c30 4 781 6 1670 5 1448 -2 1625 -1 1703 14 151 28 294 87 403 168 214 159 335 367 385 666 15 85 29 393 30 627 0 105 4 242 10 305 43 533 49 1047 15 1338 -44 386 -144 644 -325 835 -131 140 -278 220 -493 270 -92 21 -98 21 -1772 24 l-1680 3 3 1608 c2 1148 0 1635 -8 1706 -49 424 -255 701 -625 841 -243 91 -633 124 -1115 92z" transform="matrix(.1 0 0 -.1 0 1276)"/></svg>
</span>
<span data-directory="${dir.name}" title="Download Directory" class="downloadDir">
<svg width="12" height="12" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path d="M1803 960q0 53-37 90l-651 652q-39 37-91 37-53 0-90-37l-651-652q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l294 294v-704q0-52 38-90t90-38h128q52 0 90 38t38 90v704l294-294q37-37 90-37 52 0 91 37l75 75q37 39 37 91z"/></svg>
</span>
</div>
</div>`;
filelist += renderDirHtml(dir.name);
}
}
@ -557,6 +545,23 @@ $(document).ready(function () {
}
}
function renderDirHtml(name) {
return `<div class="clear relative">
<div data-directory="${name}" class="dirz">
<svg class="folder-image" viewBox="0 0 48 48" version="1.0" xmlns="http://www.w3.org/2000/svg"><path fill="#FFA000" d="M38 12H22l-4-4H8c-2.2 0-4 1.8-4 4v24c0 2.2 1.8 4 4 4h31c1.7 0 3-1.3 3-3V16c0-2.2-1.8-4-4-4z"/><path fill="#FFCA28" d="M42.2 18H15.3c-1.9 0-3.6 1.4-3.9 3.3L8 40h31.7c1.9 0 3.6-1.4 3.9-3.3l2.5-14c.5-2.4-1.4-4.7-3.9-4.7z"/></svg>
<span class="item-text">${name}</span>
</div>
<div class="song-button-box">
<span title="Add All To Queue" class="recursiveAddDir" data-directory="${name}">
<svg xmlns="http://www.w3.org/2000/svg" height="9" width="9" viewBox="0 0 1280 1276"><path d="M6760 12747 c-80 -5 -440 -10 -800 -11 -701 -2 -734 -4 -943 -57 -330 -84 -569 -281 -681 -563 -103 -256 -131 -705 -92 -1466 12 -241 16 -531 16 -1232 l0 -917 -1587 -4 c-1561 -3 -1590 -3 -1703 -24 -342 -62 -530 -149 -692 -322 -158 -167 -235 -377 -244 -666 -43 -1404 -42 -1813 7 -2355 21 -235 91 -400 233 -548 275 -287 730 -389 1591 -353 1225 51 2103 53 2330 7 l60 -12 6 -1489 c6 -1559 6 -1548 49 -1780 100 -535 405 -835 933 -921 88 -14 252 -17 1162 -24 591 -4 1099 -4 1148 1 159 16 312 56 422 112 118 59 259 181 333 290 118 170 195 415 227 722 18 173 21 593 6 860 -26 444 -32 678 -34 1432 l-2 811 54 7 c30 4 781 6 1670 5 1448 -2 1625 -1 1703 14 151 28 294 87 403 168 214 159 335 367 385 666 15 85 29 393 30 627 0 105 4 242 10 305 43 533 49 1047 15 1338 -44 386 -144 644 -325 835 -131 140 -278 220 -493 270 -92 21 -98 21 -1772 24 l-1680 3 3 1608 c2 1148 0 1635 -8 1706 -49 424 -255 701 -625 841 -243 91 -633 124 -1115 92z" transform="matrix(.1 0 0 -.1 0 1276)"/></svg>
</span>
<span data-directory="${name}" title="Download Directory" class="downloadDir">
<svg width="12" height="12" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path d="M1803 960q0 53-37 90l-651 652q-39 37-91 37-53 0-90-37l-651-652q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l294 294v-704q0-52 38-90t90-38h128q52 0 90 38t38 90v704l294-294q37-37 90-37 52 0 91 37l75 75q37 39 37 91z"/></svg>
</span>
</div>
</div>`
}
// when you click 'add directory', add entire directory to the playlist
$("#addall").on('click', function () {
//make an array of all the mp3 files in the current directory
@ -586,7 +591,7 @@ $(document).ready(function () {
if (lowerCase.indexOf(searchVal.toLowerCase()) !== -1) {
if (this.type === 'directory') {
filelist.push('<div class="clear relative"><div data-directory="' + this.name + '" class="dirz"><img class="folder-image" src="/assets/img/folder.svg"><span class="item-text">' + this.name + '</span></div><div data-directory="' + this.name + '" class="song-button-box"><span title="Add All To Queue" class="recursiveAddDir" data-directory="' + this.name + '"><svg xmlns="http://www.w3.org/2000/svg" height="9" width="9" viewBox="0 0 1280 1276"><path d="M6760 12747 c-80 -5 -440 -10 -800 -11 -701 -2 -734 -4 -943 -57 -330 -84 -569 -281 -681 -563 -103 -256 -131 -705 -92 -1466 12 -241 16 -531 16 -1232 l0 -917 -1587 -4 c-1561 -3 -1590 -3 -1703 -24 -342 -62 -530 -149 -692 -322 -158 -167 -235 -377 -244 -666 -43 -1404 -42 -1813 7 -2355 21 -235 91 -400 233 -548 275 -287 730 -389 1591 -353 1225 51 2103 53 2330 7 l60 -12 6 -1489 c6 -1559 6 -1548 49 -1780 100 -535 405 -835 933 -921 88 -14 252 -17 1162 -24 591 -4 1099 -4 1148 1 159 16 312 56 422 112 118 59 259 181 333 290 118 170 195 415 227 722 18 173 21 593 6 860 -26 444 -32 678 -34 1432 l-2 811 54 7 c30 4 781 6 1670 5 1448 -2 1625 -1 1703 14 151 28 294 87 403 168 214 159 335 367 385 666 15 85 29 393 30 627 0 105 4 242 10 305 43 533 49 1047 15 1338 -44 386 -144 644 -325 835 -131 140 -278 220 -493 270 -92 21 -98 21 -1772 24 l-1680 3 3 1608 c2 1148 0 1635 -8 1706 -49 424 -255 701 -625 841 -243 91 -633 124 -1115 92z" transform="matrix(.1 0 0 -.1 0 1276)"/></svg></span><span class="downloadDir"><svg width="12" height="12" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg"><path d="M1803 960q0 53-37 90l-651 652q-39 37-91 37-53 0-90-37l-651-652q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l294 294v-704q0-52 38-90t90-38h128q52 0 90 38t38 90v704l294-294q37-37 90-37 52 0 91 37l75 75q37 39 37 91z"/></svg></span></div></div>');
filelist.push(renderDirHtml(this.name));
} else if (this.type === 'playlist') {
filelist.push('<div data-playlistname="' + encodeURIComponent(this.name) + '" class="playlist_row_container"><span data-playlistname="' + encodeURIComponent(this.name) + '" class="playlistz force-width">' + escapeHtml(this.name) + '</span><div class="song-button-box"><span data-playlistname="' + encodeURIComponent(this.name) + '" class="deletePlaylist">Delete</span></div></div>');
} else if (this.type === 'album') {
@ -594,21 +599,15 @@ $(document).ready(function () {
var albumString = this.name ? this.name : 'SINGLES';
if (this.album_art_file) {
filelist.push('<div ' + artistString + ' data-album="' + this.name + '" class="albumz"><img class="album-art-box" data-original="/album-art/' + this.album_art_file + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + albumString + '</span></div>');
filelist.push('<div ' + artistString + ' data-album="' + this.name + '" class="albumz"><img class="album-art-box" data-original="album-art/' + this.album_art_file + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + albumString + '</span></div>');
} else {
filelist.push('<div ' + artistString + ' data-album="' + this.name + '" class="albumz"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + albumString + '</span></div>');
filelist.push('<div ' + artistString + ' data-album="' + this.name + '" class="albumz"><img class="album-art-box" src="assets/img/default.png"><span class="explorer-label-1">' + albumString + '</span></div>');
}
} else if (this.type === 'artist') {
filelist.push('<div data-artist="' + this.name + '" class="artistz">' + this.name + ' </div>');
} else {
if (programState[programState.length - 1].state === 'playlist') {
if (!this.metadata || !this.metadata.title) {
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + this.filepath + '</span></div>');
} else if (this.metadata['album-art']) {
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="album-art-box" data-original="/album-art/' + this.metadata['album-art'] + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + this.metadata.artist + ' - ' + this.metadata.title + '</span></div>');
} else {
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + this.metadata.artist + ' - ' + this.metadata.title + '</span></div>');
}
filelist.push(renderFileWithMetadataHtml(this.filepath, this.lokiId, this.metadata));
} else if (this.type == "m3u") {
filelist.push(createFileplaylistHtml(this.name));
} else {
@ -885,11 +884,17 @@ $(document).ready(function () {
});
$("#filelist").on('click', '.removePlaylistSong', function () {
var lokiId = $(this).data('lokiid');
const lokiId = $(this).data('lokiid');
MSTREAMAPI.removePlaylistSong(lokiId, function (response, error) {
if (error !== false) {
return boilerplateFailure(response, error);
}
// remove from currentBrowsingList
currentBrowsingList = currentBrowsingList.filter(item =>{
return item.lokiId !== lokiId
});
$('div[data-lokiid="' + lokiId + '"]').remove();
});
});
@ -911,7 +916,7 @@ $(document).ready(function () {
$('#search_folders').val('');
MSTREAMAPI.loadPlaylist(playlistname, function (response, error) {
MSTREAMAPI.loadPlaylist(playlistname, (response, error) => {
if (error !== false) {
$('#filelist').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
@ -920,19 +925,17 @@ $(document).ready(function () {
// Add the playlist name to the modal
$('#playlist_name').val(name);
//parse through the json array and make an array of corresponding divs
var files = [];
$.each(response, function (index, value) {
if (!value.metadata || !value.metadata.title) {
currentBrowsingList.push({ type: 'file', name: value.filepath, metadata: value.metadata });
files.push('<div data-lokiid="'+value.lokiId+'" class="clear relative"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + value.filepath + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
} else if (value.metadata['album-art']) {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-lokiid="'+value.lokiId+'" class="clear relative"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" data-original="/album-art/' + value.metadata['album-art'] + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
} else {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-lokiid="'+value.lokiId+'" class="clear relative"><div data-lokiid="'+value.lokiId+'" data-file_location="' + value.filepath + '" class="filez left"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div><div class="song-button-box"><span data-lokiid="'+value.lokiId+'" class="removePlaylistSong">remove</span></div></div>');
}
const files = [];
response.forEach(value => {
currentBrowsingList.push({
type: 'file',
name: (!value.metadata || !value.metadata.title) ? value.filepath : `${value.metadata.artist} - ${value.metadata.title}`,
metadata: value.metadata,
filepath: value.filepath,
lokiId: value.lokiId
});
files.push(renderFileWithMetadataHtml(value.filepath, value.lokiId, value.metadata));
});
$('#filelist').html(files);
@ -941,6 +944,19 @@ $(document).ready(function () {
});
});
function renderFileWithMetadataHtml(filepath, lokiId, metadata) {
console.log(filepath)
return `<div data-lokiid="${lokiId}" class="clear relative">
<div data-lokiid="${lokiId}" data-file_location="${filepath}" class="filez left">
<img class="album-art-box" ${metadata['album-art'] ? `data-original="/album-art/${metadata['album-art']}?token=${MSTREAMAPI.currentServer.token}"` : 'src="assets/img/default.png"'}>
<span class="explorer-label-1">${(!metadata || !metadata.title) ? filepath : `${metadata.artist} - ${metadata.title}`}</span>
</div>
<div class="song-button-box">
<span data-lokiid="${lokiId}" class="removePlaylistSong">remove</span>
</div>
</div>`;
}
/////////////// Download Playlist
$('#downloadPlaylist').click(function () {
// Loop through array and add each file to the playlist
@ -1023,7 +1039,7 @@ $(document).ready(function () {
state: 'recentlyAdded'
}];
MSTREAMAPI.getRecentlyAdded($('#recently-added-limit').val(), function (response, error) {
MSTREAMAPI.getRecentlyAdded($('#recently-added-limit').val(), (response, error) => {
if (error !== false) {
$('#filelist').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
@ -1031,16 +1047,16 @@ $(document).ready(function () {
//parse through the json array and make an array of corresponding divs
const filelist = [];
$.each(response, function () {
if (this.metadata.title) {
currentBrowsingList.push({ type: 'file', name: this.metadata.artist + ' - ' + this.metadata.title })
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="music-image" src="/assets/img/music-note.svg"> <span class="title">' + this.metadata.artist + ' - ' + this.metadata.title + '</span></div>');
} else {
const filepathArray = this.filepath.split("/");
const filename = filepathArray[filepathArray.length - 1];
currentBrowsingList.push({ type: 'file', name: filename })
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="music-image" src="/assets/img/music-note.svg"> <span class="title">' + filename + '</span></div>');
}
response.forEach(el => {
currentBrowsingList.push({
type: 'file',
name: el.metadata.title ? el.metadata.artist + ' - ' + el.metadata.title : el.filepath.split("/").pop()
});
filelist.push(`<div data-file_location="${el.filepath}" class="filez">
<svg class="music-image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path d="M9 37.5c-3.584 0-6.5-2.916-6.5-6.5s2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V5.429l25-3.846V29c0 3.584-2.916 6.5-6.5 6.5s-6.5-2.916-6.5-6.5 2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V11.023l-19 2.931V31c0 3.584-2.916 6.5-6.5 6.5z" fill="#8bb7f0"/><path d="M37 2.166V29c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V10.441l-1.152.178-18 2.776-.848.13V31c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V5.858l24-3.692M38 1L12 5v19.683A6.962 6.962 0 009 24a7 7 0 107 7V14.383l18-2.776v11.076A6.962 6.962 0 0031 22a7 7 0 107 7V1z" fill="#4e7ab5"/></svg>
<span class="title">${el.metadata.title ? `${el.metadata.artist} - ${el.metadata.title}`: el.filepath.split("/").pop()}</span>
</div>`);
});
$('#filelist').html(filelist);
@ -1064,23 +1080,25 @@ $(document).ready(function () {
state: 'allAlbums'
}];
MSTREAMAPI.albums(function (response, error) {
MSTREAMAPI.albums((response, error) => {
if (error !== false) {
$('#filelist').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
}
//parse through the json array and make an array of corresponding divs
var albums = [];
$.each(response.albums, function (index, value) {
if (value.album_art_file) {
currentBrowsingList.push({ type: 'album', name: value.name, 'album_art_file': value.album_art_file });
const albums = [];
response.albums.forEach(value => {
currentBrowsingList.push({
type: 'album',
name: value.name,
'album_art_file': value.album_art_file
});
albums.push('<div data-album="' + value.name + '" class="albumz"><img class="album-art-box" data-original="/album-art/' + value.album_art_file + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + value.name + '</span></div>');
} else {
currentBrowsingList.push({ type: 'album', name: value.name });
albums.push('<div data-album="' + value.name + '" class="albumz"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + value.name + '</span></div>');
}
albums.push(`<div data-album="${value.name}" class="albumz">
<img class="album-art-box" ${value.album_art_file ? `data-original="/album-art/${value.album_art_file}?token=${MSTREAMAPI.currentServer.token}"` : 'src="assets/img/default.png"'}>
<span class="explorer-label-1">${value.name}</span>
</div>`);
});
$('#filelist').html(albums);
@ -1120,22 +1138,20 @@ $(document).ready(function () {
$('#search_folders').val('');
MSTREAMAPI.albumSongs(album, artist, function (response, error) {
MSTREAMAPI.albumSongs(album, artist, (response, error) => {
if (error !== false) {
$('#filelist').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
}
//parse through the json array and make an array of corresponding divs
var filelist = [];
$.each(response, function () {
if (this.metadata.title) {
currentBrowsingList.push({ type: 'file', name: this.metadata.title })
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="music-image" src="/assets/img/music-note.svg"> <span class="title">' + this.metadata.title + '</span></div>');
} else {
currentBrowsingList.push({ type: 'file', name: this.metadata.filename })
filelist.push('<div data-file_location="' + this.filepath + '" class="filez"><img class="music-image" src="/assets/img/music-note.svg"> <span class="title">' + this.metadata.filename + '</span></div>');
}
const filelist = [];
response.forEach(song => {
currentBrowsingList.push({ type: 'file', name: song.metadata.title ? song.metadata.title : song.metadata.filename });
filelist.push(`<div data-file_location="${song.filepath}" class="filez">
<svg class="music-image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40"><path d="M9 37.5c-3.584 0-6.5-2.916-6.5-6.5s2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V5.429l25-3.846V29c0 3.584-2.916 6.5-6.5 6.5s-6.5-2.916-6.5-6.5 2.916-6.5 6.5-6.5a6.43 6.43 0 012.785.634l.715.34V11.023l-19 2.931V31c0 3.584-2.916 6.5-6.5 6.5z" fill="#8bb7f0"/><path d="M37 2.166V29c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V10.441l-1.152.178-18 2.776-.848.13V31c0 3.308-2.692 6-6 6s-6-2.692-6-6 2.692-6 6-6a5.93 5.93 0 012.57.586l1.43.68V5.858l24-3.692M38 1L12 5v19.683A6.962 6.962 0 009 24a7 7 0 107 7V14.383l18-2.776v11.076A6.962 6.962 0 0031 22a7 7 0 107 7V1z" fill="#4e7ab5"/></svg>
<span class="title">${song.metadata.title ? song.metadata.title : song.metadata.filename}</span>
</div>`);
});
$('#filelist').html(filelist);
@ -1201,20 +1217,22 @@ $(document).ready(function () {
$('#search_folders').val('');
currentBrowsingList = [];
MSTREAMAPI.artistAlbums(artist, function (response, error) {
MSTREAMAPI.artistAlbums(artist, (response, error) => {
if (error !== false) {
$('#filelist').html('<div>Server call failed</div>');
return boilerplateFailure(response, error);
}
var albums = [];
$.each(response.albums, function (index, value) {
var albumString = value.name ? value.name : 'SINGLES';
if (value.album_art_file) {
albums.push('<div data-artist="' + artist + '" data-album="' + value.name + '" class="albumz"><img class="album-art-box" data-original="/album-art/' + value.album_art_file + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">' + albumString + '</span></div>');
} else {
albums.push('<div data-artist="' + artist + '" data-album="' + value.name + '" class="albumz"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">' + albumString + '</span></div>');
}
const albums = [];
response.albums.forEach(value => {
const albumString = value.name ? value.name : 'SINGLES';
albums.push(`<div data-artist="${artist}" data-album="${value.name}" class="albumz">
<img class="album-art-box"
${value.album_art_file ? `data-original="album-art/${value.album_art_file}?token=${MSTREAMAPI.currentServer.token}"`: 'src="assets/img/default.png"'}
>
<span class="explorer-label-1">${albumString}</span>
</div>`);
currentBrowsingList.push({ type: 'album', name: value.name, artist: artist, album_art_file: value.album_art_file })
});
@ -1256,23 +1274,25 @@ $(document).ready(function () {
}
//parse through the json array and make an array of corresponding divs
var files = [];
$.each(response, function (index, value) {
var rating = (value.metadata.rating / 2);
const files = [];
response.forEach(value => {
let rating = (value.metadata.rating / 2);
if (!Number.isInteger(rating)) {
rating = rating.toFixed(1);
}
if (!value.metadata || !value.metadata.title) {
currentBrowsingList.push({ type: 'file', name: value.filepath, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">[' + rating + '] ' + value.filepath + ']</span></div>');
} else if (value.metadata['album-art']) {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" data-original="/album-art/' + value.metadata['album-art'] + '?token=' + MSTREAMAPI.currentServer.token + '"><span class="explorer-label-1">[' + rating + '] ' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div>');
} else {
currentBrowsingList.push({ type: 'file', name: value.metadata.artist + ' - ' + value.metadata.title, metadata: value.metadata });
files.push('<div data-file_location="' + value.filepath + '" class="filez"><img class="album-art-box" src="/assets/img/default.png"><span class="explorer-label-1">[' + rating + '] ' + value.metadata.artist + ' - ' + value.metadata.title + '</span></div>');
}
currentBrowsingList.push({
type: 'file',
name: value.metadata.artist ? value.metadata.artist + ' - ' + value.metadata.title : value.filepath,
metadata: value.metadata
});
files.push(`<div data-file_location="${value.filepath}" class="filez">
<img class="album-art-box"
${value.metadata['album-art'] ? `data-original="album-art/${value.metadata['album-art']}?token=${MSTREAMAPI.currentServer.token}"` : `src="assets/img/default.png"` }
>
<span class="explorer-label-1">[${rating}] ${value.metadata.artist ? `${value.metadata.artist} - ${value.metadata.title}` : value.filepath}</span>
</div>`);
});
$('#filelist').html(files);
@ -1525,7 +1545,7 @@ $(document).ready(function () {
<h3>Jukebox Mode allows you to control this page remotely<h3> <br><br>\
<input value="Connect" type="button" class="jukebox_connect">\
</p>\
<img src="/assets/img/loading.gif" class="hide jukebox-loading">';
<img src="assets/img/loading.gif" class="hide jukebox-loading">';
}
// Add the content