#!/usr/bin/perl

name: RapidShare
short: RS
uri: qr{rapidshare\.com/}
status: OK 2009-08-28

start:
	GET( $-{_uri} );

	ERROR( "file not found" )
		if /The file could not be found\.  Please check the download link/;
	ERROR( "file removed" ) if /file has been removed from the server/;
	ERROR( "file removed" ) if /download of this file is currently not possible|This limit is reached/;

	m#<p class="downloadlink">.*/(.+?) <font style=".*?">\| (\d+ KB)</font></p>#;
	INFO( name => $1, asize => $2, kilo => 1000 );

	RESTART( $1 * 60, "servers overloaded" )
		if /Unfortunately you will have to wait ([0-9]+) minutes,/;
	
	! /form id="ff" action="(.*?)"/;
	GET( $1, post => 'dl.start=Free' );

	MULTI() if /Please wait until the download is completed/;

	RESTART( $1 * 60 + 10, "free limit reached" )
		if /Instant download access! Or try again in about ([0-9]+) minutes\./;

	RESTART( $1 * 60, "servers overloaded" )
		if /Unfortunately you will have to wait ([0-9]+) minutes,/;

	! /form name="dlf" action="(.*?)"/;
	$-{file_uri} = $1;

	! /var c=([0-9]+);/;
	WAIT( $1, "starting download" );

	DOWNLOAD( $-{file_uri}, post => { mirror => "on" } );

# vim:ts=4:sw=4
