Update: RS redesigned their site and this script no longer works. (July 3, 2008)
Hi frndz,
Today I wrote a Perl script to download a set of files from www.rapidshare.com at "Happy Hours" for free users. This works in Linux/Unix only and only if you have a pppoe connection. It uses WWW::Mechanize module which is not available with standard Perl library. You will need to install it separately. This script works with current design of rapidshare site. If they make changes in site, this may fail. The usage is:
perl RSDownloader.pl [-d download_directory] links.txt
This program will wait till "Happy Hours" (will check every 10 mins) and will start downloading rapidshare links in links.txt. The program will ignore blank lines and lines starting with a '#' in the input file. If -d flag is omitted, files will be downloaded to current working directory. You can also group your downloads simply by putting a name in one line and all following links till next name will be saved to a directory with that name. eg:
In.Harihar.Nagar
htt...rapidshare.com/files/115665/In.Harihar.Nagar...part5.rar
htt...rapidshare.com/files/115685/In.Harihar.Nagar...part6.rar
htt...rapidshare.com/files/115448/In.Harihar.Nagar...part7.rar
Aaram.Thamburan
htt...rapidshare.com/files/101625/Aaram.Thamburan...part01.rar
htt...rapidshare.com/files/101841/Aaram.Thamburan...part02.rar
htt...rapidshare.com/files/101856/Aaram.Thamburan...part03.rar
htt...rapidshare.com/files/101869/Aaram.Thamburan...part04.rar
htt...rapidshare.com/files/102124/Aaram.Thamburan...part05.rar
Punjabi.House
htt...rapidshare.com/files/94088/Punjabi.House...part01.rar
htt...rapidshare.com/files/94095/Punjabi.House...part02.rar
Here is the code...
#!/usr/bin/perl -w
use WWW::Mechanize;
use Getopt::Std;
my $mech = WWW::Mechanize->new();
my $pwd = `pwd`;
chomp($pwd);
if (getopts('d:')) {
for (my $i = 0; $i <= $#ARGV; $i++) {
$ARGV[$i] = $pwd."/".$ARGV[$i] unless ($ARGV[$i] =~ m{^/});
}
chdir "$opt_d" or die "Couldn't cd to $opt_d: $!";
$pwd = `pwd`;
chomp($pwd);
}
else {
die "Error in option? $!";
}
while (<>) {
chomp;
# if input line is not a url, treat it as a directory name to create and cd.
unless (/http/) {
chdir "$pwd";
mkdir "$_", 0755 or warn "Failed to create directory $_: $!";
chdir "$_";
next;
}
print "Trying to download $_\n";
$mech->get("$_");
if ($mech->response()->content() =~ m{h1>Error./h1>}) {
print "Some server error. Skipping file: $_\n";
next;
}
$mech->submit_form("form_number", 2); # click the "Free" button
print "Selected Free download.\n";
$data = $mech->response()->content();
if ($data =~ /Happy Hour/) {
print "It\'s Happy Hour!\n";
if ($data =~ /form name="dl" action="(.*?)"/) { # get file url
print "Got free link.\n";
`wget $1`;
print "Reconnecting pppoe after 1 minutes.\n";
`poff -a;sleep 1m;pon dsl-provider;sleep 4`;
}
}
elsif ($data =~ /reached the limit/) { # didnt get new ip. try again.
print "Reached free user's limit.\n";
print "Reconnecting pppoe after 2 minutes.\n";
`poff -a;sleep 2m;pon dsl-provider;sleep 4`;
redo;
}
else {
print "Not happy hour :-(\nRetrying after 10 minutes\n";
for ($i = 1; $i <= 10; $i++) {
`sleep 1m`;
print " $i";
}
print "\n";
redo;
}
}