# $Id: SouthParkStudios 11706 2010-07-25 15:47:22Z sparky $
# Video::SouthParkStudios - Video 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.

name: SouthParkStudios
short: V:SouthParkStudios
web: "http://www.southparkstudios.com/"
uri: qr{comedycentral\.com/global/feeds/entertainment/media/mediaGenEntertainment\.jhtml\?uri=mgid:cms:item:comedycentral.com:\d+&show=southpark}
# limit slots bacause rtmp support is very bad
slots: 3
status: OK 2010-07-23

pre:
	my $rtmpopts = " swfUrl=http://media.mtvnservices.com/player/release/?v=4.5.3 swfVfy=1";

start:
	GET( $-{_uri} );

	my $width = 0;
	my $bitrate = 0;
	my ( $size, $file_uri );
	while ( s#<rendition .*? width="(\d+)" height="(\d+)" .*? bitrate="(\d+)">\s*<src>(rtmpe://.*?)</src>\s+</rendition>## ) {
		if ( $1 > $width or ( $1 == $width and $3 > $bitrate ) ) {
			$width = $1;
			$bitrate = $3;
			$size = "$1x$2 @ $3kbps";
			$file_uri = $4;
		}
	}
	ERROR( "file not found (this should never happen)" ) unless $file_uri;

	my $fname = de_ml( $file_uri );
	$fname =~ s#.*/##;

	INFO( name => $fname, quality => $size );

	undef $-{_referer}; # because URI cannot handle rtmp:
	DOWNLOAD( $file_uri . $rtmpopts );

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