Musik/static/musik.js

93 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2018-09-14 08:02:24 -04:00
function load() {
2018-09-20 10:39:23 -04:00
// track has ended
2018-09-14 08:02:24 -04:00
document.getElementById('player').addEventListener('ended', function() {
2018-09-20 10:39:23 -04:00
// shuffle
if (document.getElementById('shuffle').checked) {
2019-06-04 16:11:43 -04:00
fetch(api_uri + '/random').then(function(response) {
return response.json();
}).then(function(json) {
change_track(json);
});
2018-09-14 08:02:24 -04:00
}
});
}
2019-02-05 11:23:41 -05:00
function select_artist(select) {
let params = {
artist: select.value,
};
let query = Object.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
.join('&');
2019-06-04 16:11:43 -04:00
fetch(api_uri + '?' + query).then(function(response) {
return response.json();
}).then(function(json) {
let html_str = '';
for (let i = 0; i < json.length; i++) {
html_str += '<option value="' + json[i] + '">' + json[i] + '</option>';
}
document.getElementById('albumList').innerHTML = html_str;
document.getElementById('trackList').innerHTML = '';
});
2019-02-05 11:23:41 -05:00
}
2019-01-11 11:27:25 -05:00
2019-02-05 11:23:41 -05:00
function select_album(select) {
let params = {
artist: document.getElementById('artistList').value,
album: select.value,
};
let query = Object.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
.join('&');
2019-06-04 16:11:43 -04:00
fetch(api_uri + '?' + query).then(function(response) {
return response.json();
}).then(function(json) {
let html_str = '';
for (let i = 0; i < json.length; i++) {
html_str += '<option data-discnumber="' + json[i][0] + '" data-tracknumber="' + json[i][1]+ '" value="' + json[i][2] + '">' + json[i][0] + '.' + json[i][1] + ' - ' + json[i][2] + '</option>';
}
document.getElementById('trackList').innerHTML = html_str;
});
2018-09-13 14:22:27 -04:00
}
2019-02-05 11:23:41 -05:00
function select_track(select) {
let params = {
artist: document.getElementById('artistList').value,
album: document.getElementById('albumList').value,
discnumber: select.selectedOptions[0].dataset.discnumber,
tracknumber: select.selectedOptions[0].dataset.tracknumber,
};
let query = Object.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
.join('&');
2019-06-04 16:11:43 -04:00
fetch(api_uri + '?' + query).then(function(response) {
return response.json();
}).then(function(json) {
change_track(json);
});
2018-09-14 08:02:24 -04:00
}
function change_track(track) {
let params = {
2019-11-05 09:50:45 -05:00
artist: track.albumartist,
album: track.album,
discnumber: track.discnumber,
tracknumber: track.tracknumber,
};
let query = Object.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
.join('&');
2018-09-13 14:22:27 -04:00
let source = document.getElementById('stream');
source.src = document.location.href + '/stream?' + query;
2018-09-13 14:22:27 -04:00
let player = document.getElementById('player');
player.load();
player.play();
2019-02-07 09:23:26 -05:00
document.getElementById('nowPlayingArtist').innerHTML = track.artist;
document.getElementById('nowPlayingAlbum').innerHTML = track.album;
document.getElementById('nowPlayingTitle').innerHTML = track.title;
2018-09-20 10:39:23 -04:00
2019-09-12 10:52:03 -04:00
document.getElementById('albumCover').firstChild.src = document.location.href + 'coverart?' + query;
2019-10-29 09:37:49 -04:00
document.title = 'Musik | ' + track.artist + ' - ' + track.title;
2018-09-13 14:22:27 -04:00
}