# $Id: FileFactory 10867 2009-10-26 22:47:10Z sparky $
# Get::FileFactory - File getter plugin for rsget.pl
#
# 2009 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

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

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>#;
	CLICK( $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" );

	CLICK_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: filetype=perl:ts=4:sw=4
