Old 19th October 2017, 22:27   #1
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
Shoutcast v2 Song History

Hello Everybody,

Since i step over to shoutcast v2 my song history script does not work anymore.
Is there a good working one ? I searched a few days on google but i can only find old ones that dont work.

Thanks
BeatFlexx is offline   Reply With Quote
Old 24th October 2017, 12:57   #2
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
This is the Script I'm using.

code:

<?php
error_reporting(0);

$scip = "xxx.xx.xxx.xx"; // Server IP
$scport = "POORT"; // Port
$scpass = "**********"; // Password
$scversion = "2"; // Shoutcast Version
$scID = "1"; // Server ID
$imgKey = "MYAPI"; // LastFM api to Get Images

$scfp = fsockopen("$scip", $scport, &$errno, &$errstr, 30);
if(!$scfp) {
$scsuccs=1;
echo'Offline';
}
if($scsuccs!=1){

fputs ($scfp, "GET /admin.cgi?sid=$scID&pass=$scpass&mode=viewxml&page=4 HTTP/1.1\r\nHost: $scip:$scport\r\n .
User-Agent: User (Mozilla Compatible)\r\n .
Authorization: Basic ".base64_encode ("admin:$scpass")."\r\n\r\n");
while(!feof($scfp)) {
$page .= fgets($scfp, 1000);
}

$loop = array("STREAMSTATUS", "BITRATE");
$y=0;
while($loop[$y]!=''){
$pageed = ereg_replace(".*<$loop[$y]>", "", $page);
$scphp = strtolower($loop[$y]);
$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);
if($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE)
$$scphp = urldecode($$scphp);

$y++;
}

$pageed = ereg_replace(".*<SONGHISTORY>", "", $page);
$pageed = ereg_replace("</SONGHISTORY>.*", "", $pageed);
$songatime = explode("<SONG>", $pageed);
$a = 0;
$r=1;
while($songatime[$r]!=""){
$t=$r-1;
$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);
$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);
$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);
$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);
$song[$t] = urldecode($song[$t]);
list ($artiest, $titel) = explode(" - ", $song[$t]);
$rij_kleur = ($a++ % 2) ? "#f5f5f5" : "#e8e8e8";

$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artiest&api_key=$imgKey");
$trackimg = $xml->artist->image[2];

if ($trackimg == "") {
$trackimg = "../noIMG.png";
}

if ($artiest == "LIVE" AND $titel == "-=ON AIR=-") {
$trackimg = "../live.jpg";
}

echo'<div style="background-color: '.$rij_kleur.';>
<p style="width: 65px;"><img style="margin-top:5px; margin-left:5px; border-radius: 100%; border: 1px solid #ff1190; width: 60px; height: 60px;" src="'.$trackimg.'" /></p>
<div style="display:block; margin: -66px 0px 0px 80px; float:left;">
<i class="fa fa-microphone"></i> <strong>'.$artiest.'</strong><br />
'.$titel.'</a>
</div></div>';

$r++; }
fclose($scfp);
}
?>



It always worked before.
I'm even getting a HTTP ERROR 500
BeatFlexx is offline   Reply With Quote
Old 24th October 2017, 14:58   #3
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,423
Send a message via ICQ to djSpinnerCee Send a message via AIM to djSpinnerCee
i'll check it out 4 ya.... stand by....
djSpinnerCee is offline   Reply With Quote
Old 24th October 2017, 16:10   #4
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,423
Send a message via ICQ to djSpinnerCee Send a message via AIM to djSpinnerCee
sc_played_v2.php - v2 dnas history

ok- simple fix. basically the admin.cgi url needed tweaking.
PHP Code:
<?php

error_reporting
(0);

$scip           "127.0.0.1";   // Server IP/hostname

$scport         "8000";   // Port

$scpass         "changeme";   // Password

$scversion      "2";   // Shoutcast Version

$scID           "1";   // Server ID [sid=]

$imgKey         "MYAPI";   // LastFM api to Get Images


$scfp fsockopen($scip$scport, &$errno, &$errstr30);

if(!
$scfp) {

  
$scsuccs=1;
  echo
'Offline';

}

if(
$scsuccs!=1){

//fputs ($scfp, "GET /admin.cgi?sid=$scID&pass=$scpass&mode=viewxml&page=4 HTTP/1.1\r\nHost: $scip:$scport\r\nUser-Agent: User (Mozilla Compatible)\r\nAuthorization: Basic ".base64_encode ("admin:$scpass")."\r\n\r\n");

//get correct v2 page...
fputs ($scfp"GET /admin.cgi?sid=".$scID."&pass=".$scpass."&mode=viewxml HTTP/1.1\r\nHost: ".$scip.":".$scport."\r\nUser-Agent: User (Mozilla Compatible)\r\n\r\n");

while(!
feof($scfp)) {

  
$page .= fgets($scfp,4096);

}

fclose($scfp);

// to dump the admin.cgi for debugging... 
//echo "<!-- ".$page." -->\n\n";

 
$loop = array("STREAMSTATUS""BITRATE");

 
$y=0;

 while(
$loop[$y]!=''){

  
$pageed ereg_replace(".*<$loop[$y]>"""$page);

  
$scphp strtolower($loop[$y]);

  $
$scphp ereg_replace("</$loop[$y]>.*"""$pageed);

  if(
$loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE)

   $
$scphp urldecode($$scphp);

  
$y++;

 }

 
$pageed ereg_replace(".*<SONGHISTORY>"""$page);

 
$pageed ereg_replace("</SONGHISTORY>.*"""$pageed);

 
$songatime explode("<SONG>"$pageed);

 
$a 0;

 
$r=1;

 while(
$songatime[$r]!=""){

  
$t=$r-1;

  
$playedat[$t] = ereg_replace(".*<PLAYEDAT>"""$songatime[$r]);

  
$playedat[$t] = ereg_replace("</PLAYEDAT>.*"""$playedat[$t]);

  
$song[$t] = ereg_replace(".*<TITLE>"""$songatime[$r]);

  
$song[$t] = ereg_replace("</TITLE>.*"""$song[$t]);

  
$song[$t] = urldecode($song[$t]);

  list (
$artiest$titel) = explode(" - "$song[$t]); 

  
$rij_kleur = ($a++ % 2) ? "#f5f5f5" "#e8e8e8"

if (
$imgKey<>"MYAPI") {

  
$xml simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=".$artiest."&api_key=".$imgKey);

  
$trackimg $xml->artist->image[2];

}

if (
$trackimg == "") {

    
$trackimg "../noIMG.png";

}



if ((
$artiest == "LIVE") && ($titel == "-=ON AIR=-")) {

    
$trackimg "../live.jpg";

}



echo
'<div style="background-color: '.$rij_kleur.';>

<p style="width: 65px;"><img style="margin-top:5px; margin-left:5px; border-radius: 100%; border: 1px solid #ff1190; width: 60px; height: 60px;" src="'
.$trackimg.'" /></p>

<div style="display:block; margin: -66px 0px 0px 80px; float:left;">

<i class="fa fa-microphone"></i> <strong>'
.$artiest.'</strong><br />'.$titel.'</a>

</div></div>'
;



$r++; }

}

?>
djSpinnerCee is offline   Reply With Quote
Old 24th October 2017, 16:46   #5
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
I think that my hoster does not support fsockopen because i still have a
HTTP ERROR 500

I made a new script a that one is working for me.

code:

<?php
$sIP = "127.0.0.1";
$sPort = "8000";
$sID = "1";
$sPass = "CHANGEME";
$imgKey = "MYAPI";

$a = 0;
$b = 0;

function truncate($string, $length, $dots = "...") {
return (strlen($string) > $length) ? substr($string, 0, $length - strlen($dots)) . $dots : $string;
}

$url = file_get_contents("http://$sIP:$sPort/admin.cgi?pass=$sPass&mode=viewxml&page=4&sid=$sID");

$xml = simplexml_load_string($url);
foreach( $xml -> SONGHISTORY -> SONG as $Key => $Value ) {

list ($artist, $title) = explode(" - ", $Value -> TITLE);

$row_color = ($a++ % 2) ? "#fafafa" : "#f5f5f5";
$nowplaying = ($b++ % 20) ? "" : "<font style='color:#b2b2b2;font-size:10px;'><strong>NOW PLAYING</strong></font>";

$LastFM = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artist&api_key=$imgKey");
$trackimg = $LastFM->artist->image[2];

if ($trackimg == "") {
$trackimg = "noIMG.png";
}

if ($trackimg == "https://lastfm-img2.akamaized.net/i/u/174s/62ed6ff00329486d8f56656ef783d1aa.png") {
$trackimg = "noIMG.png";
}

if ($artist == "LIVE" AND $title == "-=ON AIR=-") {
$trackimg = "live.png";
}

$ts = $Value -> PLAYEDAT;
$date = new DateTime("@$ts");

echo'
<div style="background-color: '.$row_color.';>
<p style="width: 65px;"><img style="margin-top:5px; margin-left:5px; border-radius: 100%; border: 1px solid #ff1190; width: 60px; height: 60px;" src="'.$trackimg.'" /></p>
<div style="display:block; margin: -66px 0px 0px 80px; float:left;">
<font style="font-size:15px;"><i class="fa fa-microphone"></i> <strong>'.truncate($artist, 100).'</strong></font><br />
<font style="color:#ff1190;font-size:13px;"><i class="fa fa-headphones"></i> '.truncate($title, 100).'</font><br />' . $nowplaying . '
</div>
<div style="display:block; margin: -55px 10px 0px 0px; float:right;">
<font style="color:#b2b2b2;font-size:10px;"><i class="fa fa-clock-o"></i> ' . $date->format('g:i:s A') . '</font>
</div>
</div>';
}
?>

BeatFlexx is offline   Reply With Quote
Old 24th October 2017, 16:48   #6
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
Sorry for not using the PHP tag. I used code instead.
@djSpinnerCee Thanks for the help.
BeatFlexx is offline   Reply With Quote
Old 24th October 2017, 23:14   #7
neralex
Senior Member
 
Join Date: Mar 2011
Posts: 495
@djSpinnerCee: ereg_replace - This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. http://php.net/manual/en/function.ereg-replace.php
neralex is offline   Reply With Quote
Old 25th October 2017, 00:23   #8
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,423
Send a message via ICQ to djSpinnerCee Send a message via AIM to djSpinnerCee
@neralex - yeah, the real change that needs to be made is to not use admin.cgi, since all we need here is played history, and we can get that without a password -- i 'll tweak that and post something...
djSpinnerCee is offline   Reply With Quote
Old 25th October 2017, 01:13   #9
djSpinnerCee
Forum King
 
djSpinnerCee's Avatar
 
Join Date: Aug 2004
Location: Hollis, Queens/The Bronx, NYC
Posts: 3,423
Send a message via ICQ to djSpinnerCee Send a message via AIM to djSpinnerCee
PHP Code:
/* ... making it smart(er) -- leave the password at the default and we'll use /played instead of /admin.cgi */
if ($sPass <> "CHANGEME")
   
$url file_get_contents("http://".$sIP.":".$sPort"/admin.cgi?pass=".$sPass."&mode=viewxml&page=4&sid=".$sID);
else
   
$url file_get_contents("http://".$sIP.":".$sPort."/played?type=xml&sid=".$sID); 
djSpinnerCee is offline   Reply With Quote
Old 26th October 2017, 02:54   #10
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
Hello Everybody,

I want to share my simple Shoutcast v2 Statistics.
You can see the script in action here: VIEW

In the zip file you will find a index.php, config.php and style.css.
Let me know if you need any help.

Enjoy the script.

Greetings from this side of the world
Attached Files
File Type: zip Shoutcast v2 Statistics.zip (3.0 KB, 44 views)
BeatFlexx is offline   Reply With Quote
Old 31st October 2017, 23:46   #11
BeatFlexx
Junior Member
 
Join Date: Oct 2017
Posts: 10
Hello Everybody,

The DEMO version in the above post is no longer the version that i have uploaded.
It still works, but i have upgraded the script to a bit advanced one.

The FREE version that is in the zip file, is a playlist only to integrate in your own website.
BeatFlexx is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > SHOUTcast > SHOUTcast Site Design

Tags
history v2, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump