# $Id: RapidShare 10871 2009-10-27 11:36:04Z sparky $
# Get::RapidShare - File getter plugin for rsget.pl
#
# 2009 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

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

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 (\d+) minutes,/;
	
	! my $form = $self->form( id => "ff" );
	CLICK( $form->post() );

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

	# TODO: this should decrease file priority to delay its download,
	# postpone it, download after the next file.
	return $self->problem( "No slots for free users" )
		if /There are no more download slots available for free users right now/;

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

	RESTART( $1 * 60, "servers overloaded" )
		if /Unfortunately you will have to wait (\d+) minutes,/
			or /Please try again in (\d+) minutes/;

	! $-{form} = $self->form( name => "dlf" );
	$-{form}->set( mirror => "on" );
	$-{form}->set( x => irand 5, 103 );
	$-{form}->set( y => irand 5, 103 );

	! /var c=(\d+);/;
	WAIT( $1, "starting download" );

	CLICK_DOWNLOAD( $-{form}->post() );

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

# vim: filetype=perl:ts=4:sw=4
