Ajutor pagina web

Diverse
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Ajutor pagina web

Unread postby Levy » 04 Mar 2017 22:29

Cum as putea sa citesc datele de pe un server radio si sa le afisez intr-o pagina web.
Datele care ma intereseaza sint doar numele DJ-ului si numarul de ascultatori, eventual si numele melodiei curente.

Are cineva solutie pentru asta ??
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 11 Mar 2017 11:34

Am gasit datele care trebuiesc citite din server.
Ele se pot gasi aici.

Primul numar este numarul curent de ascultatori.
Al doilea numar nu stiu ce inseamna.
Al treilea numar afiseaza numarul maxim de ascultatori care au fost vreodata pe server.
Al patrulea numar nu stiu ce inseamna.
Al cincilea numar este bitrateul cu care transmite DJ-ul.
Si la final este afisat numele DJ-ului.

Cum se pot afisa (citite separat) aceste date pe o alta pagina ?
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 11 Mar 2017 11:38

Iar la aceasta pagina se poate gasi numele melodiei redate in acest moment.
In cazul in care nu se vede nimic din numele melodiei, DJ-ul are setarile ca sa nu se vada numele melodiei redate.
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
ASiX88796
Site Admin
Posts: 2945
Joined: 12 Oct 2013 17:02
Location: Timișoara

Re: Ajutor pagina web

Unread postby ASiX88796 » 11 Mar 2017 16:15

»
Cu PHP ar merge, depinde cât de mult te pricepi la PHP și dacă serverul tău rulează PHP.
De exeplu funcția file_get_contents încarcă întreg conținutul unui fișier într-o variabilă, variabilă pe care o poți prelucra cu alte funcții și să afișezi doar ce ai nevoie.

Code: Select all

<?php
$radio = file_get_contents('http://212.108.200.53:7210/7.html');
echo $radio;
echo substr($radio, 0, 2);
?>
___________________________ ____ ___ __ _
» Mulţi vorbesc, puţini comunică.
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 11 Mar 2017 22:21

Nu ma pricep deloc la PHP, de aia am cerut ajutor aici :)

Am bagat liniile respective in pagina, insa nu afiseaza nimic in pagina, plus ca afisarea ar trebui sa se produca la un interval prestabilit 5-10 secunde..
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
ASiX88796
Site Admin
Posts: 2945
Joined: 12 Oct 2013 17:02
Location: Timișoara

Re: Ajutor pagina web

Unread postby ASiX88796 » 12 Mar 2017 00:27

»
The only problem with file_get_contents is that some web hosts have url access blocked in the file methods, for security reasons.

Da, se pare că file_get_contents nu merge pe orice pagină...
___________________________ ____ ___ __ _
» Mulţi vorbesc, puţini comunică.
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 13 Mar 2017 22:54

Nu avem nici un "meserias"in javascript sau PHP pe aici ? :P
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 18 Mar 2017 19:58

Am gasit doua script-uri care promit sa face cea ce vreau eu, insa nu inteleg cum se foloseste, direct embedd in pagina nu functioneaza...


Primul

Code: Select all

 <?php

// last10.php -- get and display last n tracks...
// URL syntax:
// last10.php?host={http://s3.myradiostream.com}&port={58074}&n={lastN}
//
// {bracketed} items need to be replaced or they will default as below.
//
// I can return Javascript or HTML only.
//

/* keep warnings from our output */
error_reporting(E_ERROR);

// -- Server Info here -- //

$yourIP    = 'http://212.108.200.53';
$yourPORT  = '7210';

// -- Tweak Display Here -- //

$bgcolor   = '#ffffff'; // Page background color
$tablew    = '400';     // Table width
$toprow    = '#c0c0c0'; // Top background color
$bottom    = '#ffffff'; // Bottom background color
$border    = '#000000'; // Border color
$thickness = '2';       // Border thickness
$padding   = '4';       // Cell padding
$font      = 'Verdana'; // Font
$fontsize  = '2';       // Font size

$refresh   = '30';      // How often should it refresh? (seconds)

// Return JavaScript or HTML
$jsOutput=FALSE; // TRUE=js | FALSE=HTML

// try to get the target from the url...
$host = $_REQUEST***91;host***93;;
if (!$host) $host = $yourIP;
$port = $_REQUEST***91;port***93;;
if (!$port) $port = $yourPORT;

$lf = chr(10); // 0x0A ***91;\n***93;

// The lastN is configurable at the DNAS with, ShowLastSongs= it defaults to 10 and has a maximum of 20
$t_max = $_REQUEST***91;n***93;;
if (!t_max || $t_max<1 || $t_max>19) $t_max=10;
//19 is the max here because 20=current_track+19

// Let's get /index.html first... to keep this short, there is no code to handle the dnas being down
// or not running, so the script will display nothing in those cases.

$connect_timeout=5;
$success=0;

$fp1 = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout); //open connection
if(!$fp1) { //if this fails, I'm done....
fclose($fp1);
$success++;
} else {
$request="GET /index.html HTTP/1.1\r\nHost:" . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status ***91;index***93; * (Mozilla/PHP)\r\nConnection: close\r\n\r\n"; //get index.html
fputs($fp1,$request,strlen($request));
$page='';
while(!feof($fp1)) {
$page .= fread($fp1, 16384);
}
fclose($fp1);

// now I have the entire /index.html in $page -- all I want from here is the current track...
// (hint-hint)

$song00 = ereg_replace("</b></td>.*", "", ereg_replace(".*Current Song: </font></td><td><font class=default><b>", "", $page)); // easy, right <img src="images/smilies/smile.gif" border="0" alt="">

// now let's get /played.html... (this is kinda long)
$fp = fsockopen($host, $port, &$errno, &$errstr, $connect_timeout);
if(!$fp) { //if connection could not be made
fclose($fp);
$success++;

} else {
$request="GET /played.html HTTP/1.1\r\nHost: " . $host . ":" . $port . "\r\nUser-Agent: SHOUTcast DNAS Status ***91;played***93; * (Mozilla/PHP)\r\n"."Connection: close\r\n\r\n";
fputs($fp,$request,strlen($request));
$page='';
while (!feof($fp)) {
$page .= fread($fp, 16384);
}
fclose($fp); //close connection
$played_html=$page;

if ($played_html) {
$played_html= ereg_replace('<x>','|-|',ereg_replace('</tr>','',ereg_replace('</td><td>','<x>',ereg_replace('<tr><td>','',ereg_replace('</tr>','</tr>' . $lf,ereg_replace('-->','--***93;',ereg_replace('<!--','***91;!--',ereg_replace('</table><br><br>.*','',ereg_replace('.*<b>Current Song</b></td></tr>','',$played_html)))))))));
$xxn=strlen($played_html);
$r=2;
$t_count=0;
$reading=0;
$track***91;0***93;=$song00;
while ($r<$xxn & $t_count<=$t_max){
$cur=substr($played_html,$r,1);
if ($cur==$lf) $reading=0;
if ($reading==1) $track***91;$t_count***93; .= $cur;
if ($cur=="|" & substr($played_html,$r-1,1)=="-" & substr($played_html,$r-2,1)=="|") {
$reading=1;
$t_count++;
}
$r++;
}
}
}
}

// I now have $track***91;0-N***93; containg the current plus last N tracks...
// Output time...

if ($success==0) {

if ($jsOutput) { // JavaScript - used as <script src=...></script>
header('Content-type: text/javascript');
} else { // HTML... (iFrames anyone?)
echo '<HTML>
<HEAD><TITLE>TITLE OF YOUR PAGE HERE - Now Playing: ' . $track***91;0***93; . '</title>
<meta http-equiv="refresh" content="' . $refresh . ';URL=' . $_SERVER***91;'PHP_SELF'***93; . '?host=' . $host . '&port=' . $port . '">
</head>
<BODY bgcolor=' . $bgcolor . '>';
}

$r=0;
$output_string='';

//tweak the output string (the table init) here....
$output_string .= '<table width="' . $tablew . '" style="border-collapse: collapse" border="' . $thickness . '" bordercolor="' . $border . '"><tr bgcolor="' . $toprow . '"><td>
<table width="100%" border="0" cellpadding="' . $padding . '"><tr><td>
<font face=' . $font . ' size=' . $fontsize . '>'; //Now playing... 

while ($r<=$t_max){
if ($r==0) $output_string .= 'Now Playing:<br> <b>'.str_replace("'", "'",str_replace('"', '"',$track***91;$r***93;)).'</b></td></tr></table></td></tr><tr><td><table bgcolor=' . $bottom . ' width="100%" border="0" cellpadding="' . $padding . '"><tr><td><br><font face=' . $font . ' size=' . $fontsize . '><i>Before that you heard:</i><br><br>';
else $output_string .= str_replace("'", "'",str_replace('"', '"',$track***91;$r***93;)) . '<br>';

$r++;
}

// I also want to close the table code now....
$output_string .= '</td></tr></table></td></tr></font></td></tr></table>';

if ($jsOutput) {
echo "document.write('" . $output_string . "');";
} else {
echo $output_string . '</body></html>';
}

} else { // I couldn't connect to the DNAS
   if ($jsOutput) echo "document.write('Off Air');";
   else echo "<HTML><HEAD><TITLE>Off-Air</title></head>
<BODY bgcolor=" . $bgcolor . "><font face=" . $font . " size=" . $fontsize . ">Server is <b>Off-Air</b>, try again later.</body></html>";

}
?>


si al doilea

Code: Select all

<?php

// by dstjohn a t spacialaudio.com

// there are many ways to do this, below are 4.



//change to shoutcast server url location

$host = "212.108.200.53"



$port = "7210";

$fp = @fsockopen("$host", $port, &$errno, &$errstr, 30); //open connection

if(!$fp) {

$success=2; //set if no connection

}

if($success!=2){ //if connection

fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: SHOUTcast Playing (Mozilla Compat

ible)\r\n\r\n"); //get 7.html

while(!feof($fp)) {

$page .= fgets($fp, 1000);

}

@fclose($fp); //close connection

$page = ereg_replace(".*<body>", "", $page); //extract data

$page = ereg_replace("</body>.*", ",", $page); //extract data

$numbers = explode(",",$page); //extract data

$currentlisteners = $numbers[0]; //set variable

$whatsplaying = $numbers[6]; //set variable



echo 'Now Playing : ';

echo $whatsplaying;

?>


Are cineva idee cum se adauga aceste PHP-uri intr-o pagina web ??
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 18 Mar 2017 21:23

Am mai gasit ceva aici, dar cu datele introduse corect nu functioneaza.

Desi am facut totul dupa indicatiile din acea pagina.

Code: Select all

<!DOCTYPE html>
   <html>
   <head>
      <title>My Radio Station</title>
   </head>
   <body>
     
      <h1 data-shoutcast-value="servertitle"></h1>
     
      <p>Now Playing: <span data-shoutcast-value="songtitle"></span></p>
      <p>Listeners: <span data-shoutcast-value="currentlisteners"></span>/<span data-shoutcast-value="maxlisteners"></span></p>
     
      <h2>You just missed</h2>
      <ul id="played"></ul>
     
     
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
      <script src="jquery.shoutcast.easy.min.js?host=212.108.200.53&port=7210"></script>
   </body>
   </html>
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image
User avatar
Levy
Gold User
Posts: 1537
Joined: 02 Oct 2013 15:07
Location: ABSURDISTAN

Re: Ajutor pagina web

Unread postby Levy » 20 Mar 2017 19:14

Pentru serverele shoutcast v2 am gasit solutie functionala:

Code: Select all

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">

<meta name="robots" content="noindex">
  <title>My Radio Station</title>
</head>
<body>
<title>My Radio Station</title>

  <h1 data-shoutcast-value="servertitle"></h1>
 
  <p>Now Playing: <span data-shoutcast-value="songtitle"></span></p>
  <p>Listeners: <span data-shoutcast-value="currentlisteners"></span>/<span data-shoutcast-value="maxlisteners"></span></p>
 
  <h2>You just missed</h2>
  <ul id="played"></ul>
 
 
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://rawgit.com/Wavestreaming/jquery-shoutcast/master/jquery.shoutcast.easy.min.js?host=tachyon.shoutca.st&port=8098"></script>

</body>
</html>


Dar nu functioneaza pe serverele Shoutcast v1.
Inca nu am gasit solutia pentru acestea.

Un test functional cu un server v2 se poate vedea aici.
Dacă ai tăiat și ultimul copac, ai otrăvit și ultimul râu și ai prins și ultimul pește, ai să fi uimit să constați că banii nu sunt comestibili !

Image

Return to “Diverse”

Who is online

Users browsing this forum: No registered users and 19 guests