Archive for Perl

Automated download with “Free Account” on Rapidshare

Rapidshare has change the way “free account” download files, there is no need for captcha anymore, just wait for 60 seconds and you may download for 500kbps speed. Well that’s enough for me, i have plenty files to download and im in no hurry. So how can i automate download listed files from rapidshare.com with free account.

When we put a rapidshare url files into browser, server will generate page with option download using free account or premium account, inside the html files (view source code) you’ll find there’s a form with url to our files. Look at closely this this url different from what public url files we have. this is the post url that will requested to server, and when we click there’s also hidden input form “dl.start” with value “Free”, save this url and the hidden input, we need this to create download session .

after the form requested server will create a session for us to download, and give us a list of mirror link. Get the url of this mirror, final url that we need to download our files.

this simple bash script :

#!/bin/bash
 
for f in `cat rapidfiles.list`;
do
POST_VALUE='--data "dl.start=Free"'
RAPID_URL=$f
echo $RAPID_URL
 
POST_URL=`curl -s  $POST_VALUE $RAPID_URL | grep 'form action="' | cut -d '"' -f2`
echo $POST_URL
MIRROR_URL=`curl -s $POST_VALUE $POST_URL | grep 'form name="dlf"' | cut -d '"' -f4`
echo $MIRROR_URL
sleep 60
curl -s --data "dl.start=Free" $REAL_URL
curl -L -O $MIRROR_URL

perl version:

#!/usr/bin/perl
# Rapidshare downloader for free account
# simple perl script for downloading files from rapidshare.com
#
# rodotelmi.rebstech.com
# 
 
open(RAPID, '<rapidfiles.list') or die "cannot open file list";
@rapid_list = <RAPID>;
close (RAPID);
 
 
foreach $rapid_url (@rapid_list) {
 
	chomp($rapid_url);
	$curl = '/usr/bin/curl ';
	$post_cook  = '--data "dl.start=Free"';
	$cmd_inf = $curl.' -s '.$post_cook.' '.$rapid_url;
	$wait = 100;
	$mirror = 7;
 
	print "Rapid Url: \t".$rapid_url."\n";
	@res = `$cmd_inf`;
	foreach $line (@res) {
	    $form_url = $1 if ($line =~ m/form action="(.*)" method/);
	}                           
 
	print "Post url: \t".$form_url."\n";
	$cmd_ck = $curl.' -s '.$post_cook.' '.$form_url;
 
	@res = `$cmd_ck`;
	@mirror_url = "";
	foreach $line (@res) {
	    push(@mirror_url, $1) if ($line =~ m/document.dlf.action=\\'(.*)\\';/);
	    $wait = $1 if ($line =~ m/var c=(.*);/);
	}
 
	print "Mirrors Url: \t".$mirror_url[$mirror]."\n";
	$cmd_dl = $curl.' -L -O '.$mirror_url[$mirror];
 
	print "Counting for download  .. ";
	# 1 minute delay
	for ($i=$wait; $i>0; $i--) {                                                                                                                      
		$| = 1;                                                                                                                                              
		printf ("%2d", $i);                                                                                                                                  
		sleep(1);                                                                                                                                            
		print "\b" x 2;                                                                                                                                      
	}
	print "\n";
 
	# download now
	`$cmd_dl`;
 
}

For both script file list save on rapidlist.list with same directory of the script.
by default Perl script version select the mirror index 7, but of course u can change it.
for more than just simple script you can add more options like, proxy, using different ip for each file (bind)

Automated Download Script

Command line editor with Perl

Recently i have to change DHCP configuration file, for each file i need to change the MaxRateUp and MaxRateDown value, so how i do it with almost 1000s client ?. Perl come to rescue

perl -pi.old -e ’s/MaxRateUp.*/MaxRateUp\t256000;/g;
\s/MaxRateDown.*/MaxRateDown\t1024000;/g’ *.cfg;mv *.old /backup

above command will backup the original file, adding .old extension and move it to backup directory