# $Id: DepositFiles 12176 2011-03-02 20:34:18Z sparky $
# Get::DepositFiles - File getter plugin for rsget.pl
#
# 2009-2011 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

name: DepositFiles
short: DF
web: "http://depositfiles.com/"
uri: qr{depositfiles\.com/(../)?files/[0-9a-z]+}
status: OK 2011-03-02

unify:
	return "http://depositfiles.com/files/$1" if m#/files/([0-9a-z]+)#;

start:
	GET( $-{_uri} );

	ERROR( "file not found" ) if /Such file does not exist /;

	! m{<div class="info">.*?<b title="(.*?)">.*?</b>\s*<span .*?>.*?<b>(\d+(?:\.\d+)?)&nbsp;([KMG]B)</b></span>}s;
	my $name = $1;
	my $size = "$2$3";
	INFO( iname => $name, asize => $size );
	RESTART( 5 * 60, "servers overloaded" )
		if /We are sorry, but all downloading slots for your country are busy/;
	
	$-{dl_form} = $self->form( match => { onsubmit => qr/^download_started/ } );
	GOTO stage_download if $-{dl_form};

	! my $form = $self->form( match => { onsubmit => qr/^show_begin_popup/ } );
	CLICK( $form->post() );

	RESTART( $1, "free limit reached" )
		if m#<span class="html_download_api-limit_interval">(\d+)</span>#;
	
	MULTI() if m#<span class="html_download_api-limit_parallel">#;
	
	! m#setTimeout\('load_form\(\)', (\d+)\);#;
	my $wait = $1 / 1000;

	! m/\$\('#download_container'\)\.load\('(.*?)'\);/;
	$-{dl_link} = $1;

	WAIT( $wait, "starting download" );

	CLICK( $-{dl_link} );

	$-{dl_form} = $self->form( match => { onsubmit => qr/^download_started/ } );
	GOTO stage_download if $-{dl_form};

stage_download:
	CLICK_DOWNLOAD( $-{dl_form}->post() );

	RESTART( $1, "traffic limit" ) if /Wait (\d+) seconds/;

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