Some code improves, fixed bug with Tracknames without ID3 tags
This commit is contained in:
		@@ -14,6 +14,7 @@ pause.addEventListener('click', function() {
 | 
			
		||||
  audio.pause();
 | 
			
		||||
  }, false);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
audio.addEventListener("timeupdate", function() {
 | 
			
		||||
  var duration = document.getElementById('duration');
 | 
			
		||||
  var s = parseInt(audio.currentTime % 60);
 | 
			
		||||
@@ -24,6 +25,7 @@ audio.addEventListener("timeupdate", function() {
 | 
			
		||||
  if (h < 10) h = '0' + h;
 | 
			
		||||
  duration.innerHTML = h + ':' + m + ':' + s;
 | 
			
		||||
  }, false);
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
$("#volume").mousemove(function(){
 | 
			
		||||
  audio.volume = parseFloat(this.value / 10);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								js/radio.js
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								js/radio.js
									
									
									
									
									
								
							@@ -1,3 +1,11 @@
 | 
			
		||||
var lastfm = new LastFM({
 | 
			
		||||
  apiKey    : '59ab8307ec00a5ec90574ac91885798e',
 | 
			
		||||
  apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var MPDartist, MPDsong, MPDfile, MPDCurr;
 | 
			
		||||
MPDartist = MPDsong = MPDfile = MPDCurr = 'empty';
 | 
			
		||||
 | 
			
		||||
function show()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@@ -17,8 +25,7 @@ function show()
 | 
			
		||||
 | 
			
		||||
  xmlHttpRequest()
 | 
			
		||||
    .then(function(temp){
 | 
			
		||||
      var MPDartist, MPDsong, MPDfile;
 | 
			
		||||
      MPDartist = MPDsong = MPDfile = 'empty';
 | 
			
		||||
      // Получение информации из файла
 | 
			
		||||
      var array = temp.toString().split("\n");
 | 
			
		||||
      // вывод в консоль информации о файле
 | 
			
		||||
      /*
 | 
			
		||||
@@ -26,18 +33,20 @@ function show()
 | 
			
		||||
        console.log(array[i]);} */
 | 
			
		||||
 | 
			
		||||
      // .replace - удаление пробелов в начале и конце строки
 | 
			
		||||
      MPDartist = array[0].replace(/^\s*/,'').replace(/\s*$/,'');
 | 
			
		||||
      MPDartist = array[0];
 | 
			
		||||
      MPDsong = array[1];
 | 
			
		||||
      MPDfile = array[2].replace(/^vk_kun\//,'').replace(/\.mp3/,'');
 | 
			
		||||
      //console.log(MPDartist);
 | 
			
		||||
 | 
			
		||||
      if (MPDartist == '') {
 | 
			
		||||
        $('#title').html(MPDfile);
 | 
			
		||||
        } else {
 | 
			
		||||
      if (MPDartist == '' && MPDCurr != MPDfile) {
 | 
			
		||||
        MPDartist = MPDfile.replace(/\s-.*/,'').replace(/^\s*/,'').replace(/\s*$/,'');
 | 
			
		||||
        MPDsong = MPDfile.replace(/^.*\s-/,'').replace(/^\s*/,'').replace(/\s*$/,'');
 | 
			
		||||
        getLastFM_url(MPDartist, MPDsong);
 | 
			
		||||
      } else if (MPDCurr != MPDfile) {
 | 
			
		||||
          getLastFM_url(MPDartist, MPDsong);
 | 
			
		||||
        }
 | 
			
		||||
      MPDCurr = MPDfile;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$(document).ready(
 | 
			
		||||
@@ -49,19 +58,13 @@ $(document).ready(
 | 
			
		||||
 | 
			
		||||
function getLastFM_url(FMartist, FMsong)
 | 
			
		||||
{
 | 
			
		||||
  var lastfm = new LastFM({
 | 
			
		||||
    apiKey    : '59ab8307ec00a5ec90574ac91885798e',
 | 
			
		||||
    apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  lastfm.artist.getInfo({artist: FMartist}, {success: function(data){
 | 
			
		||||
    var artistLink = data.artist.url;
 | 
			
		||||
    console.log(data.artist.url);
 | 
			
		||||
    // формируем ссылку на артиста в LastFM
 | 
			
		||||
    document.querySelector('a[name="lastFMlink"]').setAttribute('href', artistLink);
 | 
			
		||||
    document.querySelector('a[name="lastFMlink"]').setAttribute('href', data.artist.url);
 | 
			
		||||
    // выводим название артиста и трека ссылкой
 | 
			
		||||
    $('#title').html(FMartist+' - '+FMsong);
 | 
			
		||||
    }, error: function(code, message){
 | 
			
		||||
    console.log('Error #'+code+': '+message);}
 | 
			
		||||
  });
 | 
			
		||||
  console.log('WHAT??!')
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
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);
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
		Reference in New Issue
	
	Block a user