-
Notifications
You must be signed in to change notification settings - Fork 29
Convincing Icecast to show additional metadata fields
To get additional fields in your Icecast status display, you'll have to edit or create an XSL file. These are usually installed in either /usr/share/icecast2/web (or similar location - see your Icecast configuration file).
The below is a new status-json2.xsl
file that exports key stream information as a JSON object. It either uses artist
and/or song
fields, or auto-splits the title
field automatically. If you need to add more fields for your setup, feel free to modify to meet your needs. It should work in all versions of Icecast above 2.0, but is untested below 2.4.0.
The first copy is a bit of a run-on sentence to make sure there's no unexpected newlines or white space (which break certain JSON interpreters). The second copy is the same code broken out for readability. If you copy from the second version, make sure to remove any newlines and extra spaces before using in production.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="UTF-8" media-type="application/json"/><xsl:template match="/icestats">{<xsl:for-each select="source"><xsl:if test="position()>1">,</xsl:if>"<xsl:value-of select="translate(@mount,'/','')" />":{"play":{"M3U":"<xsl:value-of select="@mount" />.m3u","XSPF":"<xsl:value-of select="@mount" />.xspf"},"name":"<xsl:value-of select="server_name" />","description":"<xsl:value-of select="server_description" />","type":"<xsl:value-of select="server_type" />","bitrate":"<xsl:value-of select="bitrate" />","listeners":{"current":"<xsl:value-of select="listeners" />","peak":"<xsl:value-of select="listener_peak" />","max":"<xsl:value-of select="max_listeners" />"},"nowplaying":{"artist":"<xsl:choose><xsl:when test="artist"><xsl:value-of select="artist" /></xsl:when><xsl:otherwise><xsl:value-of select='substring-before(title," - ")' /></xsl:otherwise></xsl:choose>","title":"<xsl:choose><xsl:when test="artist"><xsl:value-of select="title" /></xsl:when><xsl:otherwise><xsl:value-of select='substring-after(title," - ")' /></xsl:otherwise></xsl:choose>"}}</xsl:for-each>}</xsl:template></xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="UTF-8" media-type="application/json"/>
<xsl:template match="/icestats">
{
<xsl:for-each select="source">
<xsl:if test="position()>1">,</xsl:if>
"<xsl:value-of select="translate(@mount,'/','')" />":{
"play":{
"M3U":"<xsl:value-of select="@mount" />.m3u",
"XSPF":"<xsl:value-of select="@mount" />.xspf"
},
"name":"<xsl:value-of select="server_name" />",
"description":"<xsl:value-of select="server_description" />",
"type":"<xsl:value-of select="server_type" />",
"bitrate":"<xsl:value-of select="bitrate" />",
"listeners":{
"current":"<xsl:value-of select="listeners" />",
"peak":"<xsl:value-of select="listener_peak" />",
"max":"<xsl:value-of select="max_listeners" />"
},
"nowplaying":{
"artist":"<xsl:choose>
<xsl:when test="artist"><xsl:value-of select="artist" /></xsl:when>
<xsl:otherwise><xsl:value-of select='substring-before(title," - ")' /></xsl:otherwise>
</xsl:choose>",
"title":"<xsl:choose>
<xsl:when test="artist"><xsl:value-of select="title" /></xsl:when>
<xsl:otherwise><xsl:value-of select='substring-after(title," - ")' /></xsl:otherwise>
</xsl:choose>"
}
}
</xsl:for-each>
}
</xsl:template>
</xsl:stylesheet>