#!/usr/bin/perl

name: FileFactory
short: FF
uri: qr{filefactory\.com/}
status: OK 2009-10-03

start:
	GET( $-{_uri} );

	ERROR( "file not found" ) if /File Not Found|This file has been deleted/;
	! m{<title>(.*?) - download now for free};
	my $name = $1;
	! m{<div id="info" class="metadata">\s*<span>($STDSIZE) file uploaded}s;
	my $size = $1;
	INFO( name => $name, asize => $size );
	
	MULTI() if /You are currently downloading/;
	if ( /starthtimer[\s\S]*timerend=d\.getTime\(\)\+(\d+);/m ) {
		RESTART( $1 / 1000, "free limit reached" ) if $1 > 0;
	}

	! m#<a href="(/dlf.*?)"><img.*?alt="Download Now" /></a>#;
	GET( $1 );

	! m#<a href="(http.*?)"><img.*?alt="Download Now" /></a>#;
	$-{file_uri} = $1;

	! m#<span id="countdown".*?>(\d+)</span>#;
	my $wait = $1;
	RESTART( $wait, "free limit reached" ) if $wait > 30;

	WAIT( $wait, "starting soon" );

	DOWNLOAD( $-{file_uri} );

	# file turned out to be html, means we have to wait
	MULTI() if /You are currently downloading too many files at once/;
	RESTART( $1 * 60 - 30, "free limit reached" )
		if /Please wait (\d+) minutes to download more files/;
	RESTART( $1, "free limit reached" )
		if /Please wait (\d+) seconds to download more files/;

# vim:ts=4:sw=4
