#!/usr/bin/env perl
#
# SlimRat 
# v0.1 (2008-08-14)
# Free stahování z RapidShare
# Přemek Vyhnal <premysl.vyhnal zavinac gmail com> 2008 - public domain
#

use LWP::UserAgent;

my $file = $ARGV[0];

print "\nDownloading $file\n\n";

$ua = LWP::UserAgent->new;
$ua->agent("SlimRat");

$res = $ua->get($file);
if ($res->is_success) { $_ = $res->decoded_content."\n";} 
else { die "Page #1 error: ".$res->status_line."\n"; }
($nextpage) = m/form id="ff" action="([^"]+)"/;

$res = $ua->post($nextpage, {"dl.start"=>"Free"});
if ($res->is_success) { $_ = $res->decoded_content."\n";} 
else { die "Page #2 error: ".$res->status_line."\n"; }
($download, $wait) = m/form name="dlf" action="([^"]+)".*var c=(\d+);/sm;

print "$wait seconds\n";
sleep $wait;

if(!system("wget $download")){
	print "OK\n\n";
} else {
	print "KO\n\n";
}

