Files
radio/js/radio.js
2020-04-01 01:17:23 +03:00

63 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function show()
{
var lastfm = new LastFM({
apiKey : '59ab8307ec00a5ec90574ac91885798e',
apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
});
let xmlHttpRequest = function() {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '../trackname');
var temp = 'empty';
xhr.onload = function (e) {
if (xhr.readyState == 4 && xhr.status == 200) {
resolve(xhr.responseText);
}
};
xhr.send();
});
};
xmlHttpRequest()
.then(function(temp){
var MPDartist, MPDsong, MPDfile;
MPDartist = MPDsong = MPDfile = 'empty';
var array = temp.toString().split("\n");
// вывод в консоль информации о файле
/*
for(i in array) {
console.log(array[i]);} */
// .replace - удаление пробелов в начале и конце строки
MPDartist = array[0].replace(/^\s*/,'').replace(/\s*$/,'');
MPDsong = array[1];
MPDfile = array[2].replace(/^vk_kun\//,'').replace(/\.mp3/,'');
//console.log(MPDartist);
if (MPDartist == '') {
$('#title').html(MPDfile);
} else {
lastfm.artist.getInfo({artist: MPDartist}, {success: function(data){
var artistLink = data.artist.url;
// формируем ссылку на артиста в LastFM
document.querySelector('a[name="lastFMlink"]').setAttribute('href', artistLink);
// выводим название артиста и трека ссылкой
$('#title').html(MPDartist+' - '+MPDsong);
}, error: function(code, message){
console.log('Error #'+code+': '+message);}
});
console.log('WHAT??!')
}
});
}
$(document).ready(
() => {
show();
setInterval(show, 5000);
}
);