#!/usr/bin/perl
use LWP::Simple;

$user="lucag73";
$pass="streetsw391";
$urlbase="http://$user:$pass\@www.mame.dk/download/rom";


$#ARGV > -1 or die "Usage: $0 romname";

$rom=@ARGV[0];

$page = get "$urlbase/$rom/$rom" or die "URL not found\n";

ITER:
for (split /\n/,$page)
{
$ginfoline = $_;
if (/href/)
 {
  /rom\/$rom/ and last ITER;
 }
}
$ginfoline =~ /href=\"([^\"]*)\"/;
($gameinfourl=$1) =~ s/http:\/\//http:\/\/$user:$pass\@/;
print "\n\nURL=$gameinfourl\n";

$gameinfo = get $gameinfourl or die "Something is wrong...";

GAME:
for(split /\n/, $gameinfo)
{
 $downurl=$_;
 /if your download/ and last GAME;
}
$downurl =~ /href=\"([^\"]*)\"/;
$downloadurl=$1;
print "Real url: $downloadurl\n";
getstore $downloadurl, "$rom.zip";
