PDA

View Full Version : Perl Script


BovineCreature
07-06-2002, 02:11 AM
I wrote a Perl script that grabs a page from shoutcast, prints out info on the server, then randomly plays one of the servers in xmms (or winamp, it can be changed easily). It may be buggy, and it doesn't have my comments because I'm sorta new to Perl, but anyway, here it is:

#!/usr/bin/perl -w
srand;
use IO::Socket::INET;
my @serv;
my @url;
my $i;
my @playlist;

die "Usage ./www.pl [genre/band/whatever]" unless $ARGV[0];

$remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "www.shoutcast.com",
PeerPort => "http(80)",
);
unless ($remote) { die "Cannot Open: $!"; }
$remote->autoflush(1);
print $remote "GET /directory/index.phtml?sgenre=$ARGV[0] HTTP/1.0\n\n";
foreach $blah (<$remote>) { push (@playlist,$blah) unless $i++ < 224 || $blah =~ /\[Genre\]/ || $blah =~ /\[ ICQ \]/}
close ($remote);
foreach $element (@playlist) {
if ($element =~ /<a href.*?>/g || $element =~ /<a id.*?/g) { push(@newlist,$element) }
}
foreach (@newlist) {
s/ //mg;
if (/sbin/) {
$test = "http://www.shoutcast.com" . substr($_,53,57) . "\n";
$test =~ s/[><"]//mg;
push (@pls,$test);
}
else {
s/<.*?>//mg;
s/\[ AIM \]//mg;
s/&.*?//mg;
unless (/\[ Next/ || /\[terms/) {
$temp = $_;
push(@name,$temp) if (/\[/);
}
}
}
foreach $blah (@pls) {
$serv = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "www.shoutcast.com",
PeerPort => "http(80)",
);
die unless $serv;
$serv->autoflush(1);
print $serv "GET $blah HTTP/1.0\n\n";
foreach $yay (<$serv>) {
if ($yay =~ /File1/) {
$yay =~ s/File1=//mg;
push(@servers,$yay);
}
}
}
for ($i=0;$i<$#servers;$i++) {
print "------------------------\n";
print "Server URL: $servers[$i]";
print "Server Name: $name[$i]";
}
close($remote);
system("xmms $servers[rand(@servers)]") if @servers;

recluse
07-08-2002, 12:36 PM
Cool. Now what would be niffty is if you could tell it to grab info from several servers based on a few criteria, i.e. Kbs, genre etc. And then display a list and have you choose the one you want to listen to, or just play it automajically. Nice job. :tu:

BovineCreature
07-10-2002, 12:42 AM
You can. In case you didn't notice it:

die "Usage ./www.pl [genre/band/whatever]" unless $ARGV[0];

recluse
07-11-2002, 01:01 PM
<homer> doh! </homer>