# $Id: FileServe 12232 2011-04-22 00:52:21Z sparky $
# Premium::FileServe - File getter plugin for rsget.pl
#
# 2011 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

name: FileServe
short: *FSRV
web: "http://fileserve.com/"
tos: "http://fileserve.com/terms.php"
uri: qr{fileserve\.com/file/[A-Za-z0-9]+(/.*)?}
cookie: fsrv.p
slots: max
status: OK 2011-03-03

pre:
	my ($user, $pass);
	if ( my $s = setting("premium_fileserve") ) {
		($user, $pass) = ($s =~ /^(.+?):(.+)/) or die "Premium user:pass incorrect\n";
	} else {
		die "Premium user:pass not given\n";
	}

unify:
	s/#.*//;
	return "http://fileserve.com/file/$1"
		if m{fileserve\.com/file/([A-Za-z0-9]+)};

start:
	GET( $-{_uri} );

	ERROR( "file not found: $1" ) if m#<span class="fail_info">\s*(.*?)\s*</span>#s
		or m{<img src="/images/stop_error\.gif".*?<h1>.*?</h1></li><li>(.*?)</li>}s;

	! m#<h1>(.+?)<br/></h1>#;
	my $fname = $1;
	! m#<span.*?><strong>($STDSIZE)</strong> \| Uploaded on #o;
	INFO( name => $fname, asize => $1 );

	! ( $-{captcha_key} ) = m{var reCAPTCHA_publickey='(.*?)';};
	! ( $-{captcha_encode} ) = m{"recaptcha_shortencode_field".*? value="(.*?)" />};

	DOWNLOAD( "/login.php", post => { loginUserName => $user,
			loginUserPassword => $pass, autoLogin => 'on',
			loginFormSubmit => 'Login' } );

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