[PHP] Shoutcast API Script [sc_api]

Status
Not open for further replies.
Joined
Nov 6, 2010
Messages
1,561
Reaction score
394
Greetz!

I forgot to release this to you guys a while back. This script uses the XML statistics given off by the Shoutcast server and parses them accordingly, to whichever variable you need. I realize the PHP is messy, but that's only because I got lucky enough and found the correct parser, and fixed it accordingly.

Page Definitions
listeners.php - Parses the current listeners XML.
currentdj.php - Parses the stream title XML. In SAM Broadcaster, configure your stream title for your encoder and make it DJ-(Name) for this to properly work.

Download:


Instructions:

1. Extract the contents.
2. Properly configure all of the files by replacing SHOUTCAST-IP:SHOUTCAST-PORT with your IP and port, so it looks like so: 123.456.789.10:8000, only, with YOUR IP and port.

How do I use this?
Listeners:
PHP:
<?php $listeners = file_get_contents('URL-OR-PATH-TO-LISTENERS.PHP'); echo $listeners; ?>
Current DJ:
PHP:
<?php $dj = file_get_contents('URL-OR-PATH-TO-LISTENERS.PHP'); echo $dj; ?>
Current Song:
PHP:
<?php $currentsong = file_get_contents('http://SHOUTCAST-IP:PORT/currentsong?sid=1'); echo $currentsong; ?>

Here's some example code I use, which also automatically updates the script. You can modify it to only display one variable, if you choose, so you can use file_get_contents() to get the contents of this and have them echo on the page, and they'll still automatically update!

PHP:
<div id="loaddiv">
<b>Live DJ:</b>
<br>
<?php 
$onlinedj = file_get_contents('currentdj.php'); echo $onlinedj;
?>
<br>
<b>Now Playing:</b>
<br>
<?php $currentsong = file_get_contents('http://SHOUTCAST-IP:SHOUTCAST-PORT/currentsong?sid=1');
echo $currentsong;
?>
<br>
<b>Listeners:</b>
<br>
<?php 
$listeners = file_get_contents('listeners.php');
echo $listeners;
?>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>

Good luck with the scripts! :)
 
:) glad people are finding use. Btw, if you want a SHOUTCast server, pm me. The ones I carry go for $100/mo on any other site. $5/mo for me, only since its stupid to charge so much for 320kbps. :l

Also pm me if you want help placing this script anywhere.

Oh also going to update this with the AJAX for my php example. Won't work without it.
 
Don't set the file_get_contents to a variable, just echo it directly ( echo file_get_contents(...) )

That's the only way I knew how xD But thanks. Like + Rep.


A lot more code for such a little result. It would help me learn, though :)
 
cURL allows you to do many more things but for this script I can't see it being of any benefit.

More code. Same function. Same outcome.

:P But good tip I guess.

CURL - split contents using explode()

how do i get the currentdj part working mate i use SAM Broadcaster
ive done u have said to do but its not changeing

Thread start date: 12-12-12

Stop bumping.

And yes I know while writing this I have just contradicted myself.
 
Does it really matter? Someone bumped the thread for assistance and a discussion started. Stop trying to be a minimod.

Well, we have the help section for asking help.

Also fyi:
w7TknR - [PHP] Shoutcast API Script [sc_api] - RaGEZONE Forums
 
Status
Not open for further replies.
Back