Backend changes

This commit is contained in:
santic-zombie
2020-04-01 00:41:14 +03:00
parent 2c8ac3901c
commit 129eb040f1
9 changed files with 94 additions and 114 deletions

View File

@@ -1,4 +1,6 @@
var audio = new Audio('http://stream.santic-zombie.ru');
var stream_url = 'http://stream.santic-zombie.ru';
var audio = new Audio(stream_url);
var play = document.getElementById('play');
play.addEventListener('click', function() {
@@ -26,3 +28,5 @@ audio.addEventListener("timeupdate", function() {
$("#volume").mousemove(function(){
audio.volume = parseFloat(this.value / 10);
});
//audio.muted = true;

View File

@@ -1,25 +0,0 @@
/* Create a cache object */
//var cache = new LastFMCache();
/* Create a LastFM object */
var lastfm = new LastFM({
apiKey : '59ab8307ec00a5ec90574ac91885798e',
apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
// cache : cache
});
/* Load some artist info. */
/*
lastfm.artist.getInfo({artist: 'Boris'}, {success: function(data){
$('#curr_artist').html(
$('#lastfmTemplateArtistInfo').render(data.artist));
}, error: function(code, message){
alert('Error #'+code+': '+message);
}});
*/
lastfm.artist.getInfo({artist: 'Boris'}, {success: function(data){
alert(data.artist.url)
}, error: function(code, message){
alert('Error #'+code+': '+message);
}});

View File

@@ -1,19 +1,56 @@
function show()
{
$.ajax({
url: '../trackname.php',
cache: false,
success: function(html){
$('#title').html(html);
}
});
$.ajax({
url: '../online.php',
cache: false,
success: function(html){
$('#listeners').html(html);
}
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(MPDfile);
if (MPDartist !== null) {
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);
MPDartist = null;
}});}
else {
//document.querySelector('a[name="lastFMlink"]').setAttribute('href', null);
//$('#title').html(MPDfile);
alert('WTF!?');}
});
}
$(document).ready(

28
js/radio.js.bak Normal file
View File

@@ -0,0 +1,28 @@
function show()
{
/*
// php-scrip exec mpc current command
$.ajax({
url: '../trackname.php',
cache: false,
success: function(data){
$('#title').html(data);
}
}); */
$.ajax({
url: '../online.php',
cache: false,
success: function(html){
$('#listeners').html(html);
}
});
}
$(document).ready(
() => {
show();
setInterval(show, 5000);
}
);