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

start:
	GET( $-{_uri} );

	ERROR( "file not found" )
		if m/>Dailymotion – 404 Not Found</;
	! m{<h1 class="dmco_title"><span class="title" title="(.*?)"};
	my $name = de_ml( $1 );
	$name =~ s{/}{_}g;

	! m{"video", "(.*?)"};
	my @uris = map { /(.*)@@.*/; $1 } split /\|\|/, uri_unescape( $1 );
	my $best_uri = undef;
	my $best_size = 0;
	foreach my $uri ( @uris ) {
		$uri =~ m{/cdn/.*?-(\d+)x};
		next unless $1 > $best_size;
		$best_size = $1;
		$best_uri = $uri;
	}

	my $ext = "mp4";
	! $best_uri =~ m{/cdn/((.*?)-\d+x\d+)};
	$ext = "flv" if $2 eq "FLV";
	my $fname = $name . "." . $ext;
	INFO( name => $fname, quality => $1 );

	DOWNLOAD( $best_uri, fname => $fname );

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