#!/usr/bin/perl # mamedkget.pl - downloads a rom from www.mame.dk when giving a romname (not filename) # # Originally by Toby Deshane, few additions by Zachary P. Landau # # $& The text that that matched. # $` The text that occurred before the text that matched. # $' The text that occurred after the text that matched. # $n The text that matched within the nth set of parens. (Count the open # parens from left to right to figure out which is the nth set.) # # don't forget to only use this for roms in which you own the original # see www.mame.dk for the full warning my $output_file; if ($ARGV[1]) { $output_file = $ARGV[1]; } my $timeout = 30; my $base_url = "http://www.mame.dk/download/rom/"; #--------------------------------------------------------------- sub http_get_html { `lynx -source \"$_[0]\"`; } #========================================================================= $game_name = $ARGV[0]; if (!$game_name) { die("I need a valid MAME romset name.\n"); } print "Locating $game_name download address...\n"; $parse = &http_get_html($base_url . $game_name . '/'); if ($parse =~ /a href="(.*)">\nyes i do/) { $temp = $1; $part2 = $base_url . $game_name . "/" . $temp; } else { die("Couldn't find redirect location.\n"); } # Let's download that file. print "Finding final download address...\n"; $p = http_get_html( $part2 ); if ($p =~ /a href="(.*)">click here/) { $temp = $1; print "Snagging rom...\n"; if (!$output_file) { system(`\`which wget\` -q -c $temp`); } else { system(`\`which wget\` -q -c $temp -O $output_file`); } } else { die("Couldn't find final download location.\n"); }