# $Id: Vimeo 11662 2010-07-13 01:31:48Z sparky $
# Video::Vimeo - Video 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: Vimeo
short: V:Vimeo
web: "http://vimeo.com/"
uri: qr{vimeo\.com/\d+([/#?].*)?$}
slots: max
status: OK 2010-07-13

unify:
	s/#.*//;
	s/\?.*//;
	return "http://vimeo.com/$1" if m{/(\d+)(?:/.*)?$};

start:
	GET( $-{_uri} );

	ERROR( "file not found" ) if /Page not found/;

	! m{clip_id=(\d+)};
	$-{id} = $1;

	GET( "http://vimeo.com/moogaloop/load/clip:$-{id}" );

	! m{<width>(\d+)</width>};
	my $w = $1;
	! m{<height>(\d+)</height>};
	my $h = $1;
	! m{<caption>(.*?)</caption>};
	my $name = $1;
	$name .= ".flv";
	INFO( name => $name, quality => "${w}x${h}" );

	! m{<request_signature>(.*?)</request_signature>};
	my $rs = $1;
	! m{<request_signature_expires>(\d+)</request_signature_expires>};
	my $rse = $1;

	my $file_uri = "http://vimeo.com/moogaloop/play/clip:$-{id}/$rs/$rse/?q=hd";
	DOWNLOAD( $file_uri, fname => $name );

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