Suggestions for internet radio software

Any other programming language that is not covered in the Web Scripting category.

Suggestions for internet radio software

Postby eMKy on Wed Dec 13, 2006 9:40 pm

Ok, i need some software for radio station and good howto but just not this two "SHOUTcast", "Icecast" i want to try something new Smile

please make a suggestions thanks !

my distro is slackware 11 with kernel 2.4.33
Image
Image
eMKy
Regular
Regular
 
Posts: 89
Joined: Mon May 08, 2006 7:26 am
Location: Bulgaria

Postby ludakot on Sun Dec 24, 2006 1:14 pm

How about this Wink
Code: Select all
#!/usr/bin/perl -w
use strict;
use IO::Socket;

#get the port to bind to or default to 8000
my $port = $ARGV[0] || 8000;

#ignore child processes to prevent zombies
$SIG{CHLD} = 'IGNORE';

#create the listen socket
my $listen_socket = IO::Socket::INET->new(LocalPort => $port,
                                          Listen => 10,
                                          Proto => 'tcp',
                                          Reuse => 1);
#make sure we are bound to the port
die "Cant't create a listening socket: $@" unless $listen_socket;

warn "Server ready. Waiting for connections ... \n";

#wait for connections at the accept call
while (my $connection = $listen_socket->accept)
{   
    my $child;
    # perform the fork or exit
    die "Can't fork: $!" unless defined ($child = fork());
    if ($child == 0)
    {   #i'm the child!
   
        #close the child's listen socket, we dont need it.
        $listen_socket->close;
       
        #call the main child rountine
        play_songs($connection);
       
        #if the child returns, then just exit;
        exit 0;
    }
    else
    {   #i'm the parent!
   
        #who connected?
        warn "Connecton recieved ... ",$connection->peerhost,"\n";

        #close the connection, the parent has already passed
        #   it off to a child.
        $connection->close();
       
    }
    #go back and listen for the next connection!
}

sub play_songs
{   
    my $socket = shift;
   
    #get all the possible songs
    open PLAYLIST, "playlist.m3u" or die;
    my @songs = <PLAYLIST>;   
    close PLAYLIST;
    chomp @songs;

    #seed the rand number generator
    srand(time / $$);
   
    #loop forever (or until the client closes the socket)
    while()
    {
       
        #print the HTTP header.  The only thing really necessary
        #   is the first line and the trailing "\n\n"
        #   depending on your client (like xmms) you can also
        #   send song title etc.

       
        #get a random song from your playlist
        my $song = $songs[ rand @songs ];
       
        #what song are we playing
        warn( "play song: $song\n");
        #open the song, or continue to try another one
        open (SONG, $song) || next;

        binmode(SONG); #for windows users
      print $socket "ICY 200 OK\r\n";
        print $socket "Content-Type: audio/mpeg \r\n";
        print $socket "Cache-Control: no-cache \r\n";
        print $socket "Pragma: no-cache \r\n";
        print $socket "Connection: close \r\n";
   print $socket "icy-name: $song \r\n";
        print $socket "icy-genre: Music for open minded people \r\n";
        print $socket "icy-url: http://localhost \r\n";
        print $socket "icy-notice1:This stream requires Winamp \r\n";
        print $socket "icy-notice2:Perl Streamer v0.1a \r\n";
        print $socket "icy-metadata: 1 \r\n\r\n";
        my $read_status = 1;
        my $print_status = 1;
        my $chunk;

        # This parts print the binary to the socket
        #   as fast as it can.  The buffering will
        #   take place on the client side (it blocks when full)
        #   because this is *not* non-blocking IO
        #
        #the read will return 0 if it has reached eof
        #
        #the print will return undef if it fails
        #   (ie the client stopped listening)
        #
        while( $read_status  && $print_status )
        {   
            $read_status = read (SONG, $chunk, 1024);
            if( defined $chunk && defined $read_status)
            {   
                $print_status = print $socket $chunk;
            }
            undef $chunk;
        }
        close SONG;
       
        unless( defined $print_status )
        {   
            $socket->close();
            exit(0);
        }
    }
}
ludakot
Contributer
Contributer
 
Posts: 22
Joined: Wed Sep 06, 2006 1:21 am
Location: http://ludakot.com

Postby eMKy on Tue Dec 26, 2006 11:53 pm

hm with perl... interesting.. Shocked
i`ll try it thanks ludakot Smile
Image
Image
eMKy
Regular
Regular
 
Posts: 89
Joined: Mon May 08, 2006 7:26 am
Location: Bulgaria


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron