#!/usr/bin/perl

name: DepositFiles
short: DF
uri: qr{depositfiles\.com/}
status: OK 2009-08-24

start:
	GET( $-{_uri} );

	ERROR( "file not found" ) if /Such file does not exist /;
	! m{<div class="info">.*?<b .*?>(.*?)</b>\s*<span .*?>.*?<b>(\d+(\.\d+)?)&nbsp;([KM]B)</b></span>}s;
	my $name = $1;
	my $size = "$2 $4";
	$name =~ s/\.\.\. (\..{1,5})$/\0$1/;
	INFO( iname => $name, asize => $size );
	RESTART( 5 * 60, "servers overloaded" )
		if /We are sorry, but all downloading slots for your country are busy/;
	
	if ( m{<form action="(.*)" method="get" onSubmit="download_started} ) {
		$-{file_uri} = $1;
		return $self->stage_download();
	}

	! /<form action="(.*?)" method="post">/;
	GET( $1, post => { gateway_result => 1 } );

	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">#;
	! /<form action="(.*?)" method="get" onSubmit="download_started/;
	$-{file_uri} = $1;
	
	WAIT( 60, "starting download" );
stage_download:

	DOWNLOAD( $-{file_uri} );
	RESTART( $1, "traffic limit" ) if /Wait (\d+) seconds/;

# vim:ts=4:sw=4
