# $Id: X7 11732 2010-07-30 15:04:53Z sparky $
# Get::X7 - File getter plugin for rsget.pl
#
# 2010 (c) Przemysław Iskra <sparky@pld-linux.org>
#		This program is free software,
# you may distribute it under GPL v2 or newer.

# TODO: try to act more like web browser

name: X7
short: X7
web: "http://x7.to/"
tos: "http://x7.to/legal"
uri: qr{x7\.to/[a-z0-9]{6}}
status: OK 2010-07-30

unify:
	return "http://x7.to/$1"
		if m#x7\.to/([a-z0-9]{6})#;

start:
	GET( $-{_uri} );

	ERROR( "file not found" )
		if /<title>File not found/;
	ERROR( "not allowed: $1" )
		if /(The requested file is larger.*only premium.*?)</;

	! m#<b>Download</b>\s+\((\d+(?:,\d+)?\s*[KMG]?B)\)#s;
	my $asize = $1;
	$asize =~ tr/,/./;
	! m#<title>.*? Download: (.*?)</title>#;
	INFO( name => $1, asize => $asize );

	! m#var dlID = '([a-z0-9]{6})';#;
	$-{id} = $1;

	CLICK( "/james/ticket/dl/$-{id}", post => "" );

	RESTART( - irand( 60, 300 ), "free limit reached" )
		if /{err:"limit-dl"}/;
	MULTI() if /{err:"limit-parallel"}/;

	! m#{type:'download',wait:(\d+),url:'(.+?)'#;
	$-{file_uri} = $2;

	# wait a bit longer because server needs some time to prepare the file
	WAIT( 20 + $1, "starting download" );

	CLICK_DOWNLOAD( $-{file_uri} );

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