Icecast2 “Now Playing”

Project:  Icecast2 “Now Playing”

I made this script for AnimeYume Radio so the users of that site could see whose streaming and what’s playing.  Now the script itself is not of my own design.  In fact that design is from the “{status.xsl}” file that came with Icecast2.

A running demo of this script can be found at {AnimeYume Radio} in the sidebar.

Prep

For the optimal effectiveness of this script or hack job, we will want to make some changes to your server…   Now just so you know I’m using a UNIX setup, not Windows, also you will need ssh/terminal access to your server.

You will be making various updates to your script until you get it to look the way you want and so where changing some stuff. First up we want a copy of the Original Icecast2 Web Directories and we are placing it into a sub directory of your web site.

So on you web directories you will need to create a folder system for the files we are using.

Example:


/httpdocs/private/icecast2
/httpdocs/private/icecast2/admin
/httpdocs/private/icecast2/conf
/httpdocs/private/icecast2/logs
/httpdocs/private/icecast2/web

Now we need to grab some files from the Main Icecast2 files. Within your terminal/ssh connection to your server you want to run the following command without the quotations.

“cp /etc/icecast2 /var/www/vhosts/{domain}/httpdocs/private”

Now that we’ve done that we got almost all the files we need the main files don’t have the pictures thatare in the shared folder for Icecast2. So we need to run the following command.


“cp /usr/share/icecast2/web/*.jpg /var/www/vhosts/{domain}/httpdocs/private/icecast2/web”
“cp /usr/share/icecast2/web/*.png /var/www/vhosts/{domain}/httpdocs/private/icecast2/web”
“cp /usr/share/icecast2/web/*.gif /var/www/vhosts/{domain}/httpdocs/private/icecast2/web”

That should copy over any/all the default images and finally you need to run this final command.


“chown {ftpusername}:{ftpusername} –R /var/www/vhosts/{domain}/httpdocs/private”

This will ensure that you will be able to modify the files via ftp.

Phase 2

In you icecast.xml file, btw you’ll want to place in the /httpdocs/private/icecast2/conf directory, you will need to update the following variables. Also create a file named icecast.pid and place in the same directory.


<paths>
<basedir>/var/www/vhosts/{domain}/httpdocs/private/icecast2</basedir>
<logdir>/var/www/vhosts/{domain}/httpdocs/private/icecast2/logs</logdir>
<webroot>/var/www/vhosts/{domain}/httpdocs/private/icecast2/web</webroot>
<adminroot>/var/www/vhosts/{domain}/httpdocs/private/icecast2/admin</adminroot>
<pidfile>/var/www/vhosts/{domain}/httpdocs/private/icecast2/conf/icecast.pid</pidfile>
<alias source="/" dest="/status.xsl"/>
</paths>
<logging>
<accesslog>access.log</accesslog>
<errorlog>error.log</errorlog>
<loglevel>1</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
<logsize>10000</logsize> <!-- Max size of a logfile -->
</logging>
<security>
<chroot>0</chroot>
<changeowner>
<user>{ftpusername}</user>
<group>icecast</group>
</changeowner>
</security>

Logging

Now I don’t know if you will be doing this overall but I know Icecast has a fit if your logs aren’t working. In the /httpdocs/private/icecast2/logs directory you want to create the following files.


“error.log”
“access.log”

And with that your prep is done all you have to do is update your various icecast2 files to use the conf in the conf directory we setup and everything should run fine and the best part we can now use your FTP top update the web directory to what we need.

The Script

The script itself is just a crack down version of the {status.xsl} file.  All you have to do is copy the file and rename it to something else. For example I renamed the file to status3.xsl because there was already a status2.xsl and I just want to follow the trend.

Now you notice very quickly that the variables such as this:

“<xsl:value-of select="artist" />”

These variables are pulled from the /admin/stats.xml when a stream is running. So you could change or add a variable if you don’t see on in the status.xsl file but it is available in the stats.xml file.

For example here is my {status3.xsl} to look at:


<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:output omit-xml-declaration="no" method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes" encoding="UTF-8" />
<xsl:template match = "/icestats" >
<html>
<head>
<title>AnimeYume Radio</title>
<link rel="stylesheet" href="style2.css" />
<meta http-equiv="refresh" content="60;url=http://animeyumeradio.org:8000/status3.xsl" />
</head>
<body>
<!--mount point stats-->
<xsl:for-each select="source">
<xsl:choose>
<xsl:when test="listeners">
<h4><span>
<xsl:value-of select="server_name" /> - <a href="{@mount}.m3u">Tune-in!</a>
</span></h4>
<ul>
<xsl:if test="server_description">
<li><b>Stream Title</b>:<br /><xsl:value-of select="server_description" /></li>
</xsl:if>
<xsl:if test="listeners">
<li><b>Current Listeners</b>: <xsl:value-of select="listeners" /></li>
</xsl:if>
<li><b>Current Song</b>:
<xsl:if test="artist"><xsl:value-of select="artist" /> - </xsl:if><xsl:value-of select="title" /></li>
</ul>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Final Notes

One other thing, as I found out very quickly, if you remove the wrong code or place a code that should be there you will get a error saying the page could not be process or something to that effect…  It sucks because it will happen often.  At first I had to go back to the original version and start again.

That should be it. If you got questions let me know.

Add reply