#!/usr/bin/perl -w use strict; use Shout; use MP3::Info; use File::Find; $File::Find::dont_use_nlink = 1; @ARGV = qw(.) unless @ARGV; # do it again once we play thru while (1) { my @mp3list = (); # get the list of mp3s find sub { push(@mp3list,$File::Find::name) if $File::Find::name =~ /mp3$/i }, @ARGV; die "No MP3 files found in '@ARGV'" if (!@mp3list); # randomize it! fisher_yates_shuffle( \@mp3list ); # start the connection my $conn = new Shout; # setup all the params $conn->ip('localhost'); $conn->port(8000); $conn->icy_compat(1); $conn->mount('punk'); $conn->name('Punk'); $conn->genre('punk'); $conn->password('scott'); # connect! $conn->connect or die "Failed to connect: ", $conn->error; foreach my $mp3 (@mp3list) { # get the metadata info my $mp3tag = MP3::Info::get_mp3tag($mp3); my $titlestring = $mp3tag->{"TITLE"}." - ".$mp3tag->{"ARTIST"}; #print "$titlestring\n"; # stream some data my ( $buffer, $bytes ) = ( '', 0 ); open(MP3FILE, "<$mp3"); $conn->updateMetadata($titlestring); while( ($bytes = sysread( MP3FILE, $buffer, 4096 )) > 0 ) { $conn->sendData( $buffer ) && next; print STDERR "Error while sending: ", $conn->error, "\n"; last; } continue { $conn->sleep; } close(MP3FILE); } } sub fisher_yates_shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } }