# $Id: 4Shared 11554 2010-06-12 19:59:45Z sparky $
# Get::4Shared - 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.

# TODO: support images, and probably other content

name: 4Shared
short: 4S
web: "http://www.4shared.com/"
tos: "http://www.4shared.com/terms.jsp"
uri: qr{4shared\.com/(account/)?file/}
cookie: 4s
slots: max
status: OK 2010-06-05

unify:
	return "http://www.4shared.com/file/$1/$2"
		if m{/file/(\d+)/([0-9a-f]+)};

start:
	GET( $-{_uri} );

	ERROR( "file not found" )
		if m{^\s*<img alt="" src="/images/spacer\.gif" class="warn" hspace="3" align="left" />\s*$}m;

	! m{window\.location = ".*/(.*?)\?tsid=.*";};
	my $name = uri_unescape( $1 );

	! m{<td class="finforight">(\d+(?:,\d+)? KB)</td>}s;
	my $size = $1;
	$size =~ tr/,/./;
	INFO( name => $name, asize => $size );

	! m{<a href="(.*?)" class="dbtn" tabindex="1">};
	CLICK( $1 );

	! m{id='divDLStart'>\s*<a href='(.*?)'>};
	$-{file_uri} = $1;

	! /var c = (\d+);/;
	WAIT( $1, "starting download" );

	CLICK_DOWNLOAD( $-{file_uri} );

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