#!/usr/bin/perl

name: StorageTo
short: ST
uri: qr{storage\.to/}
status: OK 2009-08-28

start:
	GET( $-{_uri} );

	ERROR( "file not found" ) if /File not found\./;
	! m{<span class="orange">.*?:</span> (.*?) <span class="light">\(([\d\.]+ [KM]B)\)</span>};
	INFO( name => $1, asize => $2 );

	! /onclick='javascript:startcountdown\("(.*?)", "(.*?)"\);'/;
	GET( "/getlink/$2/" );

	! s/^.*?{\s+//;
	! s/\s+}.*?$//;

	! /'countdown'\s*:\s*(\d+)/;
	my $wait = $1;
	RESTART( $wait, "free limit reached" )
		unless /'state'\s*:\s*'ok'/;

	! /'link'\s*:\s*'(.*?)'/ and $1;
	$-{file_uri} = $1;

	WAIT( $wait, "starting download" );

	delete $-{_referer}; # started from ajax, there must be no referer
	DOWNLOAD( $-{file_uri} );

# vim:ts=4:sw=4
