#!/usr/bin/perl -w # reencode.pl v.0c - first release (C) 2000, Scott Dier # This script is released under the GPL License #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation; either version 2 of the License, or #(at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # v.0c # added daemon-like things. Such as recovery when the source # does weird stuff, like disconnect. # v.0b # Thanks to dokas@cs for help with IO::Select # If you cant figure out the vars, ill document them next release # you need libshout and libshout-perl from cvs.icecast.org # I need to fix up variables and stuff. this is a pre pre pre release :) # You might want to munge the values for read down there, and the value # for the $ua->request. Balancing out the two will be crucial to if your # filehandles block too often to send stuff out. (or put stuff in) # too low, and it eats all your processor. # you might want to tweak the lame cmd line down there. use Shout qw{}; use LWP::UserAgent; use FileHandle; use IPC::Open2; use IO::Select; $pid = 0; $conn = new Shout; my $streamurl = 'http://localhost:8000/icy_0'; $conn->ip('localhost'); $conn->port('8000'); $conn->password('password'); $conn->mount('quarry'); $conn->icy_compat(0); $conn->name('The Quarry: Voice of the Stoners'); $conn->url('http://www.frogmistress.com/'); $conn->genre('talk'); $conn->bitrate('16'); $conn->ispublic(1); sub streamthis { my ($data, $response, $protocol) = @_; if($sel->can_write()) { print Writer $data; } } my $ua = LWP::UserAgent->new; $conn->connect or die "Failed to connect: ", $conn->error; open2 ( \*Reader, \*Writer, "/usr/bin/lame --mp3input -m m -a --preset phone -"); Writer->autoflush(); $sel=IO::Select->new(); $sel->add(\*Writer); $sel->add(\*Reader); $pid = fork (); if ($pid) { my $attempt = 0; while(1) { my $response = $ua->request( HTTP::Request->new('GET', $streamurl), \&streamthis, 4096); $attempt++; if (!$response->is_success) { if($attempt > 20) { print "stream doesn't exist, sleeping 60 seconds\n"; sleep(60); } else { print "stream might not be avaliable yet, sleeping 5 seconds\n"; sleep(5); } } else { print "stream booted us, sleeping 5 seconds\n"; sleep(5); $attempt = 0; } } } else { while(1) { while($sel->can_read()) { read Reader, $buf, 1024; $conn->sendData( $buf ); } } $conn->disconnect(); }