# $Id: UploadingCom 10871 2009-10-27 11:36:04Z sparky $
# Get::UploadingCom - 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: UploadingCom
short: UC
uri: qr{uploading\.com/(../)?files/(get/)?[A-Za-z0-9]{8}}
cookie: uc
status: OK 2009-10-22

unify:
	return "http://uploading.com/files/$1/"
		if m{uploading\.com/(?:../)?files/(?:get/)?([A-Za-z0-9]{8})/?};

start:
	GET( $-{_uri} );

	RESTART( irand( 60, 300 ), "temporarily unavailable" )
		if m{<h1>Service Not Available</h1>};
	ERROR( "file not found" ) if /Requested file not found/;

	! m{<h2 style=".*?">File download</h2><br/>\s*<h2>(.*?)</h2><br/>\s*File size: <b>($STDSIZE)</b>};
	my $name = $1; my $size = $2;
	if ( $name =~ /\.\..{1,5}$/ ) {
		! m{<title>Download (.*?) for free on uploading\.com</title>};
		$name = $1;
	}
	INFO( name => $name, asize => $size );

	my $form = $self->form( id => "downloadform" );
	$-{file_id} = $form->get( "file_id" );

	CLICK( $form->post() );

	if ( m{var file_link = '(.+?)'} ) {
		$-{file_uri} = $1;
		GOTO stage_download;
	}
	! /CONF\s*=\s*{\s*host:\s*'(.*?)'/;
	$-{host} = $1;

	! m{start_timer\((\d+)\);};
	WAIT( -$1, "expecting download link" );

	GET( $-{host} . "files/get/?JsHttpRequest=" . jstime() . "-xml",
		post => "file_id=$-{file_id}&action=get_link&pass=",
		headers => [ "Content-Type: application/octet-stream" ],
		keep_referer => 1,
	);
stage_download:

	unless ( $-{file_uri} ) {
		! m{"link"\s*:\s*"(.*?)"};
		$-{file_uri} = $1;
		$-{file_uri} =~ s/\\(.)/$1/g;
	}

	CLICK_DOWNLOAD( $-{file_uri} );

	MULTI() if /Your IP address is currently downloading a file/;

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