# $Id: RapidShare 12397 2011-10-31 15:15:24Z cactus $
# Get::RapidShare - File getter plugin for rsget.pl
#
# 2009-2010 (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
web: "http://rapidshare.com/"
tos: "http://rapidshare.com/#!rapidshare-ag/rapidshare-ag_agb"
uri: qr{(?:rs[a-z0-9]+\.)?rapidshare\.com/files/\d+/.+}
uri: qr{(?:rs[a-z0-9]+\.)?rapidshare\.com/?#!download\|\d+\|\d+\|.+?\|\d+}
uri: qr{(?:rs[a-z0-9]+\.)?rapidshare\.de/files/\d+/.+}
uri: qr{(?:rs[a-z0-9]+\.)?rapidshare\.de/?#!download\|\d+\|\d+\|.+?\|\d+}
status: OK 2010-10-04

unify:
	return $_;

start:
	$-{__uri} = $-{_uri} unless $-{__uri};

	GET( $-{__uri} );

	ERROR( "file not found: $1" )
		if /^ERROR: (File .*)/;

	if ( m{<script type="text/javascript">location="(.*?)"} ) {
		$-{__uri} = "http://rapidshare.com$1";

		RESTART( 1, "found correct uri: $-{__uri}" );
	}

	if ( ( $-{id}, $-{name}, my $size ) = $-{_referer} =~ m{#!download\|[0-9a-z]+\|(\d+)\|(.+?)\|(\d+)} ) {
		INFO( name => $-{name}, asize => "$size KB" );
	} else {
		ERROR( "unknown error, uri is: $-{_referer}" );
	}
	
	CLICK( "http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&try=1&fileid=$-{id}&filename=$-{name}" );

	MULTI( $1 )
		if /^(ERROR: You need RapidPro.*)/;
	RESTART( -60, "must wait: $1" )
		if /^ERROR: (Please stop floo.*|All free download slots are full.*)/;
	RESTART( -$2, "free limit reached: $1" )
		if /^(ERROR: You need to wait (\d+) seconds.*)/;

	! my ( $host, $dlauth, $wait ) = m{DL:(.*?),([0-9A-F]+?),(\d+)};

	$-{file_uri} = "http://$host/cgi-bin/rsapi.cgi?sub=download&dlauth=$dlauth&bin=1&fileid=$-{id}&filename=$-{name}";

	WAIT( -$wait, "starting download" );

	DOWNLOAD( $-{file_uri} );

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