=head2 icecast_listeners($url, $stream_name) icecast_listeners('http://localhost:8000/status-text.xsl', '/stream'); The URL provided should point to a comma-delimited status file served by icecast in the format: MountPoint,Connections,Stream Name,Current Listeners,Description,Currently Playing,Stream URL As long as the MountPoint and Stream Name don't have any embedded commas in them, the (simplistic) parsing should work fine. Fixing the regexes if this isn't suitable is left as an exercise for the reader. ; ) Returns undef on error and the number of listeners for the stream specified on success, or if no stream is specified, the listeners for all streams. =cut sub icecast_listeners { my ($url, $stream) = @_; # get data use LWP::Simple qw/get/; my $data = LWP::Simple::get($url) or return undef; $data =~ s/
/\n/g; my @data = split /\n/, $data; if ($stream) { # getting just one stream for (@data) { next unless /^\Q$stream\E/; /^\Q$stream\E,\d+,[^,]*,(\d+),/; return $1 ? $1 : 0; } } else { # get total listeners for server my $total = 0; for (@data) { next unless /^\//; /^\/[^,]+,\d+,[^,]*,(\d+),/; $total += $1 if $1; } return $total ? $total : 0; } return undef; }