Advertising Icecast
From MtdWiki
This is a script to advertise Icecast streams in iTunes using the DAAP protocol. It take two parameters, first the URL of the icecast server, secondly the directory to write the streams into, for example:
/usr/local/bin/icecast2urls.pl \ http://10.54.146.25:8000/status-xml.xsl \ /home/music/streams
To enable this script to work, you will need to enable the .url file suffix in mt-daapd. See Streaming Audio for details.
#!/usr/bin/perl
#
# icecast2urls.pl
#
# Public Domain script to advertise Icecast streams using mt-daap
# By Nicholas Humfrey
#
use LWP::Simple;
use XML::XPath;
use strict;
my ($url, $dir) = @ARGV;
die "Directory does not exist: $dir" unless (-e $dir);
die "Is not a directory: $dir" unless (-d $dir);
print "URL: $url\n";
print "Dir: $dir\n";
# Fetch it
my $xml = get( $url );
die "Failed to fetch XML" unless (defined $xml);
my $xp = XML::XPath->new( xml => $xml );
my $sources = $xp->find('/icestats/source');
foreach my $source ($sources->get_nodelist) {
my $name = $xp->findvalue('server_name', $source);
my $listenurl = $xp->findvalue('listenurl', $source);
my $bitrate = $xp->findvalue('bitrate', $source);
# Remove commas from the stream name
$name =~ s/,//g;
# Create the filename
my $filename = $name;
$filename =~ tr/A-Z/a-z/;
$filename =~ s/\W/_/g;
my $filepath = "$dir/$filename.url";
print "Writing to file: $filepath\n";
# Write the URL file
open( STREAM, ">$filepath" ) or die "Failed to open file $filepath: $!";
print STREAM "$bitrate,$name,$listenurl\n";
close(STREAM);
}
Here is my status-xml.xsl, which should be placed in your Icecast2 server's 'web' directory:
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > <xsl:output method="xml" indent="yes" /> <xsl:template match="*"> <xsl:copy-of select="/" /> </xsl:template> </xsl:stylesheet>
