Nota personal
It is a nice scraper to create a MAME game info database compatible with rcb XBMC add-on
$dir_main should exists and be RW (place where database will be created)
./mame_db.pl ROM_NAME
IE: ./mame_db.pl punisher
#!/usr/bin/perl -w
# Directory where the local database will be created:
$dir_main = "/games";
# Check arument:
my $game = {};
$game{filename} = $ARGV[0] or die("rom filename without extension is needed");
# Require CPAN modules:
require HTML::TreeBuilder;
require LWP::UserAgent;
# CHECK WRITE PERMISIONS ON DIRECTORIES TO SAVE
$game{info_dir} = "info";
( -w "$dir_main/$game{info_dir}" or mkdir("$dir_main/$game{info_dir}") ) or die("Directory: $dir_main/$game{info_dir} -> $!");
my $game_img = {};
$game_img{title}{dir} = "titles";
$game_img{snap}{dir} = "snap"; # TIP: Configure xmamerc to get your own snaps.
$game_img{gameover}{dir} = "gameover";
$game_img{score}{dir} = "scores";
$game_img{select}{dir} = "select";
$game_img{cabinet}{dir} = "cabinet";
$game_img{marquee}{dir} = "marquee";
$game_img{cpanel}{dir} = "cpanel";
$game_img{flyer}{dir} = "flyer";
$game_img{pcb}{dir} = "pcb";
foreach ( keys %game_img ) {
( -w "$dir_main/$game_img{$_}{dir}" or mkdir("$dir_main/$game_img{$_}{dir}") ) or die("Directory: $dir_main/$game_img{$_}{dir} -> $!");
}
# LWP browser rulez!:
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent('Mozilla/5.0');
sub get_minimaws {
# Database information:
my $info_db = "http://maws.mameworld.info/minimaws/set/$game{filename}";
$game{url} = $info_db;
my $info_str_ok = '\w\ \d\.\,\:\-\\\/';
my $info_raw = $ua->get($info_db);
$info_tree = HTML::TreeBuilder->new_from_content($info_raw->content);
foreach ( $info_tree->look_down('class', 'section') ) {
if ( $_->is_inside('h1') ) {
$_->objectify_text();
my @buffer = $_->look_down('_tag', '~text');
($game{title}, $game{region}) = split(/[\(\)\x{00A9}]/,$buffer[0]->attr_get_i('text'));
$game{year} = $buffer[1]->attr_get_i('text');
$game{developer} = $buffer[3]->attr_get_i('text');
foreach ($_->right()->look_down('_tag', 'li')) {
if ( $_->as_text =~ /genre\:\ ([$info_str_ok]*)/s) {
$game{genre} = $1;
}
elsif ( $_->as_text =~ /category\:\ ([$info_str_ok]*)/s) {
$game{category} = $1;
}
elsif ( $_->as_text =~ /gallery\:/) {
foreach ($_->look_down('_tag', 'a')) {
foreach my $image (keys %game_img) {
if ( $_->attr_get_i('href') =~ /$image/ ) {
$game_img{$image}{url} = $_->attr_get_i('href');
}
else {
}
}
}
}
elsif ( $_->as_text =~ /number\ of\ players\:\ ([$info_str_ok]*)/s) {
$game{nop} = $1;
}
elsif ( $_->as_text =~ /rating\:\ ([$info_str_ok]{2})/s) {
$game{rating} = $1;
}
else {
}
}
}
elsif ( $_->is_inside('h2') ) {
if ( $_->as_text =~ /emulation/ ) {
}
elsif ( $_->as_text =~ /display/ ) {
}
elsif ( $_->as_text =~ /input/ ) {
foreach ($_->right()->look_down('_tag', 'li')) {
if ( $_->as_text =~ /controls\:\ ([$info_str_ok]*)/) {
$game{controls} = $1;
}
if ( $_->as_text =~ /players\:\ ([$info_str_ok]*)/) {
$game{players} = $1;
}
else {
}
}
}
elsif ( $_->as_text =~ /hardware/ ) {
}
elsif ( $_->as_text =~ /data/ ) {
foreach ($_->right()->look_down('_tag', 'ol')) {
foreach ($_->look_down('_tag', 'li')) {
my ( $rom_name, $rom_size, $rom_CRC, $rom_set, $rom_status ) = split ( '/', $_->as_text );
$game{crc} .= $rom_CRC;
}
}
}
elsif ( $_->as_text =~ /links/ ) {
}
elsif ( $_->as_text =~ /MAMEInfo.dat/ ) {
$_->right()->objectify_text();
foreach ($_->right()->look_down('_tag', '~text')) {
$game{MAMEInfo} .= $_->attr_get_i('text')."\n";
}
}
elsif ( $_->as_text =~ /arcade-history.com/ ) {
$_->right()->objectify_text();
foreach ($_->right()->look_down('_tag', '~text')) {
$game{arcadehistory} .= $_->attr_get_i('text')."\n";
}
}
else {
}
}
else {
}
}
}
get_minimaws();
my $info_file = $dir_main."/".$game{info_dir}."/".$game{filename}.".txt";
open (INFO_FILE, ">$info_file");
# http://code.google.com/p/romcollectionbrowser/wiki/Main#parserConfig.xml
print INFO_FILE "Game: $game{title}
Platform:
Region: $game{region}
Media:
Controller: $game{controls}
Genre: $game{genre}
Release Year: $game{year}
Developer: $game{developer}
Publisher: $game{developer}
Players: $game{players}
URL: $game{url}
Description:
$game{arcadehistory}
********************************************************************\n";
close (INFO_FILE);
foreach ( keys %game_img ) {
if ( $game_img{$_}{url} ) {
print "GETTING: http://maws.mameworld.info".$game_img{$_}{url}."\n";
my $img_src = "http://maws.mameworld.info".$game_img{$_}{url};
my $img_dst = $dir_main."/".$game_img{$_}{dir}."/".$game{filename}.".png";
$ua->mirror($img_src, $img_dst);
}
}