# $Id: StorageTo 11716 2010-07-27 20:18:28Z sparky $
# Get::StorageTo - File getter plugin for rsget.pl
#
# 2009-2010 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

name: StorageTo
short: ST
web: "http://storage.to/"
uri: qr{storage\.to/get/[a-zA-Z0-9]{8}([\?/].*?)?$}
status: OK 2010-07-13

start:
	GET( $-{_uri} );

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

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

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

	DELAY( 5 * 60, "download failed" ) if /'state'\s*:\s*'failed'/;

	! /'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
	CLICK_DOWNLOAD( $-{file_uri} );

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