Some code improves, fixed bug with Tracknames without ID3 tags

master
santic-zombie 5 years ago
parent 1a5e774948
commit d35971887c
  1. 7
      css/style.css
  2. 4
      index.html
  3. 2
      js/audio.js
  4. 33
      js/radio.js
  5. 28
      js/radio.js.bak

@ -1,9 +1,11 @@
body { body {
background-color: rgb(62, 50, 64); background-color: rgb(62, 50, 64);
/*
background-image: url("/pic/bg.jpg"); background-image: url("/pic/bg.jpg");
background-repeat: no-repeat; background-repeat: no-repeat;
background-attachment: fixed;
background-position: center center; background-position: center center;
background-size: cover; background-size: cover; */
} }
.parent { .parent {
@ -11,12 +13,15 @@ body {
height: 100%; height: 100%;
position: fixed; position: fixed;
top: 0; top: 0;
background: url(/pic/bg.jpg) no-repeat center center / cover;
left: 0; left: 0;
display: flex; display: flex;
align-items: center; align-items: center;
align-content: center; align-content: center;
justify-content: center; justify-content: center;
overflow: auto; overflow: auto;
} }
#song{ #song{

@ -4,7 +4,7 @@
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
<link rel="stylesheet" type="text/css" href="/css/style1.css"> <link rel="stylesheet" type="text/css" href="/css/style.css">
<title>My Test Radio</title> <title>My Test Radio</title>
<script <script
src="https://code.jquery.com/jquery-3.4.1.js" src="https://code.jquery.com/jquery-3.4.1.js"
@ -47,7 +47,7 @@
<input id="volume" type="range" min="0" max="10" value="5" step="0.1" /> <input id="volume" type="range" min="0" max="10" value="5" step="0.1" />
</div> </div>
<span id="duration"></span> <!-- <span id="duration"></span> -->
<br> <br>
</div> </div>
</div> </div>

@ -14,6 +14,7 @@ pause.addEventListener('click', function() {
audio.pause(); audio.pause();
}, false); }, false);
/*
audio.addEventListener("timeupdate", function() { audio.addEventListener("timeupdate", function() {
var duration = document.getElementById('duration'); var duration = document.getElementById('duration');
var s = parseInt(audio.currentTime % 60); var s = parseInt(audio.currentTime % 60);
@ -24,6 +25,7 @@ audio.addEventListener("timeupdate", function() {
if (h < 10) h = '0' + h; if (h < 10) h = '0' + h;
duration.innerHTML = h + ':' + m + ':' + s; duration.innerHTML = h + ':' + m + ':' + s;
}, false); }, false);
*/
$("#volume").mousemove(function(){ $("#volume").mousemove(function(){
audio.volume = parseFloat(this.value / 10); audio.volume = parseFloat(this.value / 10);

@ -1,3 +1,11 @@
var lastfm = new LastFM({
apiKey : '59ab8307ec00a5ec90574ac91885798e',
apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
});
var MPDartist, MPDsong, MPDfile, MPDCurr;
MPDartist = MPDsong = MPDfile = MPDCurr = 'empty';
function show() function show()
{ {
@ -17,8 +25,7 @@ function show()
xmlHttpRequest() xmlHttpRequest()
.then(function(temp){ .then(function(temp){
var MPDartist, MPDsong, MPDfile; // Получение информации из файла
MPDartist = MPDsong = MPDfile = 'empty';
var array = temp.toString().split("\n"); var array = temp.toString().split("\n");
// вывод в консоль информации о файле // вывод в консоль информации о файле
/* /*
@ -26,18 +33,20 @@ function show()
console.log(array[i]);} */ console.log(array[i]);} */
// .replace - удаление пробелов в начале и конце строки // .replace - удаление пробелов в начале и конце строки
MPDartist = array[0].replace(/^\s*/,'').replace(/\s*$/,''); MPDartist = array[0];
MPDsong = array[1]; MPDsong = array[1];
MPDfile = array[2].replace(/^vk_kun\//,'').replace(/\.mp3/,''); MPDfile = array[2].replace(/^vk_kun\//,'').replace(/\.mp3/,'');
//console.log(MPDartist); //console.log(MPDartist);
if (MPDartist == '') { if (MPDartist == '' && MPDCurr != MPDfile) {
$('#title').html(MPDfile); MPDartist = MPDfile.replace(/\s-.*/,'').replace(/^\s*/,'').replace(/\s*$/,'');
} else { MPDsong = MPDfile.replace(/^.*\s-/,'').replace(/^\s*/,'').replace(/\s*$/,'');
getLastFM_url(MPDartist, MPDsong);
} else if (MPDCurr != MPDfile) {
getLastFM_url(MPDartist, MPDsong); getLastFM_url(MPDartist, MPDsong);
} }
MPDCurr = MPDfile;
}); });
} }
$(document).ready( $(document).ready(
@ -49,19 +58,13 @@ $(document).ready(
function getLastFM_url(FMartist, FMsong) function getLastFM_url(FMartist, FMsong)
{ {
var lastfm = new LastFM({
apiKey : '59ab8307ec00a5ec90574ac91885798e',
apiSecret : 'e09bec215fdc3100ff998167e5b401f8',
});
lastfm.artist.getInfo({artist: FMartist}, {success: function(data){ lastfm.artist.getInfo({artist: FMartist}, {success: function(data){
var artistLink = data.artist.url; console.log(data.artist.url);
// формируем ссылку на артиста в LastFM // формируем ссылку на артиста в LastFM
document.querySelector('a[name="lastFMlink"]').setAttribute('href', artistLink); document.querySelector('a[name="lastFMlink"]').setAttribute('href', data.artist.url);
// выводим название артиста и трека ссылкой // выводим название артиста и трека ссылкой
$('#title').html(FMartist+' - '+FMsong); $('#title').html(FMartist+' - '+FMsong);
}, error: function(code, message){ }, error: function(code, message){
console.log('Error #'+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);
}
);
Loading…
Cancel
Save