<?php
ob_start(function($b){if(strpos($b, "<html")!==false) {return str_replace(PHP_EOL,"",$b);} else {return $b;}});
// Players Windows/Linux/Android Link
$porta = query_string('1');

if(!is_numeric($porta)) {
die ("Error! Missing data.");
}

$verifica_stm = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".$porta."'"));

if($verifica_stm == 0) {
die ("Error! Missing data.");
}

$dados_config = @mysqli_fetch_array(@mysqli_query($conexao,"SELECT * FROM configuracoes"));
$dados_stm = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".$porta."'"));
$dados_servidor = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor"]."'"));

$total_pontos = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM multipoint where codigo_stm = '".$dados_stm["codigo"]."'"));

if($total_pontos > 0) {
$ponto = "/1";
} else {
$ponto = "/stream";
}

$url_streaming = "https://".strtolower($dados_servidor["nome"]).".".$dados_config["dominio_padrao"].":".$dados_stm["porta"]."";

if(query_string('2') == "cover") {

if($dados_stm["tipo_servidor"] == "icecast") {

   $porta_admin_icecast = $dados_stm["porta"]+1;

   $dados_icecast = @file_get_contents("http://".$dados_servidor["ip"].":".$porta_admin_icecast."/status-json.xsl?mount=".$ponto);

   $dados_json_icecast = json_decode($dados_icecast, true);

   $musica_completa = ($dados_json_icecast["icestats"]["source"]["artist"]) ? $dados_json_icecast["icestats"]["source"]["artist"]." - ".$dados_json_icecast["icestats"]["source"]["title"] : $dados_json_icecast["icestats"]["source"]["title"];

} else {
   $musica_completa = @file_get_contents("http://".$dados_servidor["ip"].":".$dados_stm["porta"]."/currentsong?sid=1");
}
  
$musica_completa = str_replace("_"," ",$musica_completa);
$musica_completa = ucwords(strtolower($musica_completa));
$musica_completa = utf8_decode($musica_completa);
  
$musica_completa = str_replace(" e "," & ",$musica_completa);
$musica_completa = str_replace(" E "," & ",$musica_completa);

$musica_partes = explode("-",$musica_completa);

$artista = str_replace("_"," ",$musica_partes[0]);
$artista = rtrim($artista, " \t.");
  
$artista = str_replace(" ","-",$artista);

$artista = ($artista) ? $artista : $musica_completa;

$dados_api_itunes_json = json_decode(@file_get_contents("https://itunes.apple.com/search?term=".$artista."&media=music&limit=1"),true);

if($dados_api_itunes_json["results"][0]["artworkUrl100"]) {
echo $musica_completa."|".str_replace("100x100bb", "600x600bb", $dados_api_itunes_json["results"][0]["artworkUrl100"]);
exit();
}

echo $musica_completa."|/img/img-capa-artista-padrao.gif";

exit();
}
?>
<html>
   <head>
      <title>Player</title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      <link rel="stylesheet" type="text/css" href="/player-repro-delux.css">
      <style>body {transition: opacity ease-in 0.2s; } 
         body[unresolved] {opacity: 0; display: block; overflow: hidden; position: relative; } .metadata-container{white-space:nowrap;position:relative;text-transform:uppercase}.frame-animation{-webkit-animation:moving 11s infinite;animation:moving 11s infinite}.metadata-container h2{display:inline-block;min-width:100%}.waiting{background-color:rgba(0,0,0,.15)}.share-options{position:absolute;top:0;left:0;width:100%;text-align:center;padding:.6em}.share-options>a{padding:0 .4em;border:solid 1px #e6e6e6}.border-sides{border:solid 1px #505050;border-top:none;border-bottom:none}.cover-img{background-size:cover!important;background-position:top center}.content-cover{position:fixed;padding-bottom:9.5em;top:0;left:0;height:100%}h2{font-size:1.6em;margin:.1em 0}.volume{padding-left:48px;position:relative;margin-top:-.1em}.volume .icon{position:absolute;left:4px;font-size:1.6em}.volume .slider{margin-top:1em;padding:1.5em}b{font-weight:400}.volume .ball.highlight{display:none!important}.volume .ball{padding:0!important;margin:-10px -2px!important;width:4px;height:20px;border-radius:0!important}.stream.info{position:fixed;bottom:0;left:0;width:100%;padding:20px 5px;padding-bottom:16px}.nowrap{overflow:hidden;white-space:nowrap}.buttons{margin-top:8px}.buttons .a{font-size:2em;font-weight:400;margin:2px 0}.footer{text-align:center;font-size:.7em;width:100%;position:absolute;bottom:0;padding:.6em;left:0;text-transform:uppercase}#contextmenu{background-color:rgba(12,12,12,.83);color:#fff;font-size:.8em;transition-duration:.1s;border-radius:4px;margin-bottom:10px;border:solid 2px #1b1717;position:fixed;z-index:10000000}#contextmenu li>a{padding:.5em .8em;white-space:nowrap}input[type=range]{display:block;width:250px}input[type=range]:focus{outline:0}input[type=range],input[type=range]::-webkit-slider-runnable-track,input[type=range]::-webkit-slider-thumb{-webkit-appearance:none}input[type=range]::-webkit-slider-thumb{background-color:#777;width:20px;height:20px;border:3px solid #333;border-radius:50%;margin-top:-9px}input[type=range]::-moz-range-thumb{background-color:#777;width:15px;height:15px;border:3px solid #333;border-radius:50%}input[type=range]::-ms-thumb{background-color:#777;width:20px;height:20px;border:3px solid #333;border-radius:50%}input[type=range]::-webkit-slider-runnable-track{background-color:#777;height:3px}input[type=range]:focus::-webkit-slider-runnable-track{outline:0}input[type=range]::-moz-range-track{background-color:#777;height:3px}input[type=range]::-ms-track{background-color:#777;height:3px}input[type=range]::-ms-fill-lower{background-color:#ff69b4}input[type=range]::-ms-fill-upper{background-color:#000}</style>
   </head>
   <body class="size-l">
   <audio id="player" style="visibility: hidden;" src="<?php echo $url_streaming; ?><?php echo $ponto; ?>"></audio>
      <div class="main-0">
         <div id="msie" class="all-height valign container fluid" style="display:none;position:relative;z-index:99909999;background:rgba(255,255,255,0.99)">
            <div class="valign-wrapper all-height container fluid">
               <a href="javascript:void(0)" class="container fluid text-center" style="display:block;font-size:1em;padding:20px 10px;background:rgba(0,0,0,0.9);color:white" id="msie-text">This player is not compatible with Internet Explorer. Go to a modern browser like Google Chrome, Firefox or Opera</a>
            </div>
         </div>
         <div id="audio-checker" class="audio-checker all-height valign container fluid" style="position: relative; z-index: 99999; background: rgba(255, 255, 255, 0.4); display: none;">
            <div class="valign-wrapper all-height container fluid">
               <a href="javascript:void(0)" class="container fluid text-center" style="display:block;font-size:1em;padding:20px 10px;background:rgba(0,0,0,0.9);color:white" id="audio-checker-text">Make click to start playing</a>
            </div>
         </div>
         <div id="all-content">
            <div id="st01"></div>
            <div class="container fluid">
               <div id="capa_atual" class="container fluid gray lighten-3 content-cover" style="display: block;">
                  <div id="capa_atual_imagem" style="background-image:url('/img/img-capa-artista-padrao.gif')" class="container fluid all-height cover-img">
                  </div>
               </div>
               <div class="stream info white text-gray darken-3">
                  <div class="container border-sides">
                     <div class="row" style="margin-bottom:0">
                        <div class="col s12">
                           <div class="container fluid nowrap text-center relative">
                              <div class="text-center">
                                 <h2 id="musica_atual">-</h2>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
                  <div id="sharebox" class="share-options gray lighten-4 z-depth-1 padding" style="display: none;">
                     <a class="waves-effect f1-5em text-blue darken-3 white" target="_blank" event-click="shareClick" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo "https://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>"><i class="fa fa-fw fa-facebook"></i></a>
                     <a class="waves-effect f1-5em text-blue white" target="_blank" event-click="shareClick" href="https://twitter.com/intent/tweet?url=<?php echo "https://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>"><i class="fa fa-fw fa-twitter"></i></a>
                  </div>
                  <div class="container fluid buttons" align="center">
                     <a href="javascript:void(0)" id="botao_stop" style="font-size:1.8em; margin:4px 0;" class="b0 play-button a inline-block waves-effect">
                     <i class="fa fa-stop" style="padding-right: 10px;padding-left: 10px; font-size: 22px;"></i>
                     </a>
                     <a href="javascript:void(0)" id="botao_play" class="b0 play-button a inline-block waves-effect" style="display: inline-block;">
                     <i class="fa fa-play" style="padding-right: 10px;padding-left: 10px; font-size: 22px;"></i>
                     </a>
                     <a href="javascript:void(0)" id="botao_pause" class="text-color-hue-1 b0 play-button a inline-block waves-effect" style="display: none;">
                     <i class="fa fa-pause" style="padding-right: 10px;padding-left: 10px; font-size: 22px;color: #00BCD4"></i>
                     </a>
                     <a href="javascript:$('#sharebox').toggle();" event-click="shareClick" style="font-size:1.8em; margin:4px 0;" class="b0 play-button a inline-block waves-effect">
                     <i class="fa fa-share-alt" style="padding-right: 10px;padding-left: 10px; font-size: 22px;"></i>
                     </a>
                  </div>
                  <div class="container">
                     <a id="volume_on" href="javascript:void(0)" class="icon"><i class="fa fa-volume-up" style="font-size: 18px"></i></a>
                     <a id="volume_off" href="javascript:void(0)" class="icon" style="display: none;"><i class="fa fa-volume-off" style="font-size: 18px"></i></a>
                     <input id="volumeSlider" type="range" min="0" max="1" step="0.1" value="0.7" style="width:100%;margin-top: 10px;" />
                  </div>
               </div>
            </div>
         </div>
      </div>
      <div id="botao_play_geral" class="audio-checker all-height valign container fluid" style="position: relative; z-index: 99999; background: rgba(255, 255, 255, 0.4);">
       <div class="valign-wrapper all-height container fluid">
           <a href="javascript:void(0);" class="container fluid text-center" style="display:block;font-size:1em;padding:20px 10px;background:rgba(0,0,0,0.9);color:white" id="audio-checker-text">Haga click para iniciar el reproductor</a>
       </div>
      </div>
      <script type="text/javascript">
        load_music_cover();
        setInterval(load_music_cover,30000);
        $('#botao_play_geral').click(function() {
         $('#botao_play_geral').hide();
         if ($('#player')[0].paused == false) {
              $('#player')[0].pause();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          } else {
            $('#player')[0].play();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          }
        });
        $('#botao_stop').click(function() {
         if ($('#player')[0].paused == false) {
          $('#player')[0].pause();
          $('#botao_play').toggle();
          $('#botao_pause').toggle();
         }
        });
        $('#botao_play').click(function() {
          if ($('#player')[0].paused == false) {
              $('#player')[0].pause();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          } else {
            $('#player')[0].play();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          }
        });
        $('#botao_pause').click(function() {
          if ($('#player')[0].paused == false) {
              $('#player')[0].pause();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          } else {
            $('#player')[0].play();
            $('#botao_play').toggle();
            $('#botao_pause').toggle();
          }
        });
        $("#volumeSlider").change(function(){
         var volume = $(this).val();
         $('#player')[0].volume = volume ;
        });
        $('#volume_on').click(function() {
          $('#volume_on').toggle();          
          $('#volume_off').toggle();
          $('#player')[0].volume=0;
          $("#volumeSlider").val(0);
        });
        $('#volume_off').click(function() {
          $('#volume_on').toggle();
          $('#volume_off').toggle();
          $('#player')[0].volume=1;
          $("#volumeSlider").val("0.7");
        });
        function load_music_cover() {

         $.ajax({
         url:"/player-repro-delux/<?php echo $dados_stm["porta"]; ?>/cover",
         type:"GET",
         success: function(dados, statusText, errorThrown){
           var dados = dados.split("|");
           $('#musica_atual').fadeOut('fast').html(dados[0]).fadeIn('slow');
           $("#capa_atual_imagem").css('opacity', 0);
           $("#capa_atual_imagem").css("background-image", "url('"+dados[1]+"')").animate({opacity: 1});
         },
         error: function(dados, statusText, errorThrown){
           var dados = dados.split("|");
           $('#musica_atual').fadeOut('fast').html(dados[0]).fadeIn('slow');
           $("#capa_atual_imagem").css('opacity', 0);
           $('#capa_atual_imagem').css('background-image', 'url("/img/img-capa-artista-padrao.gif")').animate({opacity: 1});
         }
         });

         }
      </script>
   </body>
</html>