#!/usr/bin/perl

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

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/;
	
	if ( m{<form action="(.*)" method="get" onSubmit="download_started} ) {
		$-{dl_form} = $self->form( match => { onsubmit => qr/^download_started/ } );
		return $self->stage_download();
	}

	my $form = $self->form( match => { body => qr/name="gateway_result"/ } );
	GET( $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">#;
	$-{dl_form} = $self->form( match => { onsubmit => qr/^download_started/ } );
	
	WAIT( 60, "starting download" );
stage_download:

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

# vim:ts=4:sw=4
