Old 26th April 2001, 05:30   #1
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
I posted this as a reply to another question. For fear of it getting lost in the shuffle, I am posting it again... alone.

For those of us broadcasting with Macintoshes (yes, it can be done) or staying away from Microsoft Servers, here is a script based on Tom Pepper's grabxml. The authoring information is below.

I am using Apache and PHP 4. Make sure you have PHP4 (although it may work with PHP3). If not, it won't work.

Last but not least, add .php to the name of the file. Yes, some of us are newbies- like me.

Enjoy!

Todd



HERE'S THE PHP SCRIPT FOR SONG HISTORY ETC.

THIS SCRIPT IS PROVIDED AS IS:
---------------------------------------------------------------------
<?php
// grabxml and more v1.0 (php)
// Todd Day and Joshua Gerrish
// This is an adaptation of Tom Pepper’s grabxml
// Joshua added the code that will display the
// SONGHISTORY ARRAY. I added some messy HTML
// CODE at the bottom to display the data taken
// from the Shoutcast server.
// Simply add your PASSWORD, host domain or ip,
// and port number to get it going.
//
// Don’t change any of the code up until the
// HTML portion or it’ll blow up.
// This script requires PHP on your webserver.
//
// There ain’t no support, there ain’t no guarantees,
// and, NO, we are not responsible.
//
// Have a nice day.
//
// Todd – toddday@mac.com --- http://promedia.mine.nu
//
///////////////////////////////////////////////////////
//
// SET THESE VARIABLES
//
$password="changeme";
$host="your.kickinserver.com";
$port=8000;
//
//
// DON’T CHANGE ANYTHING BELOW THIS LINE UNTIL
// YOU GET TO THE HTML FORMATTING PORTION
//
//
function startElement($parser, $name, $attrs)
{
global $varname, $in_songhistory, $in_title;
$varname=$name;

if ($name == 'SONGHISTORY') {
$in_songhistory = 1;
} else if ($name == 'TITLE') {
$in_title = 1;
} else if ($name == 'PLAYEDAT') {
$in_title = 0;
}
}

function endElement($parser, $name)
{
global $in_songhistory, $song_ind;

if ($name == 'SONGHISTORY') {
$in_songhistory = 0;
} else if ($name == 'SONG') {
$song_ind++;
}
}

function characterData($parser, $data) {
global $datalog,$varname, $in_songhistory, $song_ind, $titles, $times;
global $in_title;

$data=trim($data);
if ($data) {
if ($in_songhistory) {
if ($in_title) {
$titles[$song_ind] = $data;
} else {
$times[$song_ind] = $data;
}
} else {
$datalog[$varname] = $data;
}
}
}

// here we go
$in_songhistory = 0;
$song_ind = 0;

// set up html
echo "<HTML>\n<HEAD><TITLE>XML parsing for $host:$port</TITLE></HEAD>\n<BODY><PRE>\n";


// connect to sc_serv
$sp=fsockopen($host,$port,&$errno,&$errstr,10);
if(!$sp) die("Could not contact $host:$port - $errstr\n");
set_socket_blocking($sp,false);
// send request
fputs($sp,"GET /admin.cgi?pass=$password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

// fetch response, timeout if it takes > 15s
for($i=0; $i<30; $i++) {
if(feof($sp)) break; // exit if connection broken
$sp_data.=fread($sp,31337);
usleep(500000);
}
// strip HTTP headers so all we have is XML data
$sp_data=ereg_replace("^.*<\?xml ","<?xml ",$sp_data);
/* xml code goes here, here's a plain empty parser */

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $sp_data, 1)) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
reset($datalog);
//reset($titles);
//reset($times);
/* UNCOMMENT THIS TO SEE ALL ASSIGNED ARRAY VARIABLES
while(list($key,$val) = each($datalog)) {
echo "$key => $val\n";
}
*/
// print up some variables and their values (change to suit your needs)
//
//
// BELOW IS THE HTML FORMATTING AND VARIABLES
//
// MAKE A COPY OF THIS FILE!!!
//
// IF YOU WANT TO KNOW WHAT VARIABLES TO ADD
// LOOK AT THE XML STATS ON YOUR SERVER
// STUFF THAT IS COMMENTED OUT IS WHAT
// I DIDN’T WANT DISPLAYED
//
//
echo "<font face=Arial Size=2 color=#000000>";
echo “SERVER STATS:\n”;
echo "<br><br>";
//echo “SERVER STATS” .$datalog["SERVERTITLE"].”\n";
echo "<br><br>";
echo "Now Playing:</font><font face=Arial Size=2 color=red><b> ".$datalog["SONGTITLE"]."</b></font>\n";
echo "<font face=Arial Size=2 color=#000000>";
echo "<br>";
echo "Currently Tuned In: ".$datalog["CURRENTLISTENERS"]."\n";
echo "<br>";
echo "Stream Requests: ".$datalog["STREAMHITS"]."\n";
//echo "<br>";
//echo "Site URL: ".$datalog["SERVERURL"]."\n";
echo "<br>";
echo "Webhits: ".$datalog["WEBHITS"]."\n";
echo "<br>";
// echo "song: ".$datalog["SONGTITLE"]."\n";
echo "<br><br>";
echo "<b>Song History: (N/A= ID3 Information Missing)</b>";
echo "<br><br>";
for ($i = 0; $i < $song_ind; $i++) {
//echo "Last Song: ".$titles[$i]."\n";

echo "=><b> ".$titles[$i]."</b>\n";
echo "Played At: ".$times[$i]."\n";
echo "<br>\n";
}
echo "</font>";
// close up HTML
echo "</PRE></BODY></HTML>";
?>
liquidpixel is offline   Reply With Quote
Old 26th April 2001, 05:38   #2
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
BTW, you can see what it looks like in action here:

http://promedia.mine.nu/parse.php
liquidpixel is offline   Reply With Quote
Old 26th April 2001, 22:05   #3
Bplanet
Junior Member
 
Join Date: Apr 2001
Posts: 6
Send a message via AIM to Bplanet
Yo, I istalled it and I get the error:

XML error: not well-formed at line 1

Any suggestions?

Thanks
Bplanet is offline   Reply With Quote
Old 26th April 2001, 22:46   #4
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
you're talking to a newbie on that one... don't mess with the script... just add your account ifo at the top.
liquidpixel is offline   Reply With Quote
Old 26th April 2001, 22:52   #5
Bplanet
Junior Member
 
Join Date: Apr 2001
Posts: 6
Send a message via AIM to Bplanet
all i did was add my info, I didn' change anything.
Bplanet is offline   Reply With Quote
Old 26th April 2001, 22:55   #6
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
you probably have hidden control characters in there or something.

Make sure you save it as straight text.
liquidpixel is offline   Reply With Quote
Old 27th April 2001, 22:39   #7
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
did you get it work? I have integrated it into my website:

http://promedia.mine.nu

use IE for the iFrames.
liquidpixel is offline   Reply With Quote
Old 27th April 2001, 22:47   #8
Bplanet
Junior Member
 
Join Date: Apr 2001
Posts: 6
Send a message via AIM to Bplanet
It still doesnt work. I just get the error:
XML error: not well-formed at line 1

That error sounds like something on the XML end of the equation. I have tried everything to try and get this bitch to work. I dunno, if anyone out their has this script installed and would like to do me a favor and punch in my server and pass to see if it will work give me a holar. If it works with someone elses, then its got to be a server or XML problem.

-JEFF
jeff@boardingplanet.com
Bplanet is offline   Reply With Quote
Old 28th April 2001, 15:32   #9
angst
Major Dude
 
angst's Avatar
 
Join Date: Dec 2000
Location: Toronto, Canada!
Posts: 545
Send a message via ICQ to angst
hello,
I'm prity sure that, thats an old script, you didn't make it, and it requiers an older virsion of shoutcast and sc_dsp to work correctly,
just stick to the ASP scripts that every one is use,
search for the forums and I'm sure your find it.

SiX - what's reality compared to me...
www.remixwars.com - free mp3's for download!
free shoutcast scripts: http://dev.irn.ca
angst is offline   Reply With Quote
Old 28th April 2001, 17:59   #10
liquidpixel
Member
 
Join Date: Mar 2001
Location: Orlando, FL | Cuernavaca, MX
Posts: 54
As the script comments state, it is build on top of tom peppers grabxml script. Further, Josh Gerrish and I worked on this together with Josh adding the proper values to call the SONGHISTORY array. The script can be viewed on http://promedia.mine.nu

Lastly, there are a very good number of us that *do not* use Microsoft products. And a good number of ISPs that do not use M$ products. This is a PHP script and will not work on an ASP box (unless PHP is installed). UNIX is still the workhorse of the net and a lot of use it. If you have a problem with the script then go elsewhere. It works well for a lot of us. And, yes, I will be updating the script over time.

This script was meant to be a help to those who use PHP. I haven't seen one solid response to people's questions about PHP scripts (sans Tom Pepper's script) All I have seen are posts about using SAM and/or oddsock or whatever it is. This script is not for ASP users. If they had ASP, they wouldn't be asking for this script.

Now get off yer horse and walk home.
liquidpixel is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Discussions

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