Apache2-EmbedFLV

 view release on metacpan or  search on metacpan

lib/Apache2/EmbedFLV.pm  view on Meta::CPAN

You can see it in action here: L<http://axiombox.com/apache2-embedflv/flv>.

=head1 FLOWPLAYER

Find the Flowplayer distribution on L<http://flowplayer.org>. It is a nice
little GPL video player.

=head1 DOWNLOAD

Download it at CPAN: L<http://search.cpan.org/~damog>.

=head1 PROJECT

You can always see the latest information on this project on:
L<http://axiombox.com/apache2-embedflv>.

Code is hosted at L<http://github.com/damog/apache2-embedflv>.

=head1 AUTHOR

David Moreno <david@axiombox.com>, L<http://damog.net/>.
Some other similar projects are announced on the Infinite Pig
Theorem blog: L<http://log.damog.net>.

=head1 THANKS

=over

=item * Bill Cromie, who allowed me to use my employer's resources to
have some fun with this little project.

=item * Flowplayer L<http://flowplayer.com/>.

=item * Raquel Hernándex, L<http://maggit.net>, who made the default template.

=back

=head1 COPYRIGHT

Copyright (C) 2009 by David Moreno.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

Flowplayer, also shipped with this distribution, is GPL:
L<http://flowplayer.org/download/LICENSE_GPL.txt>.

=cut

package Apache2::EmbedFLV;

our $VERSION = '0.2';

use Apache2::Request;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
use Apache2::Util ();
use Apache2::Const -compile => qw/OK :common DIR_MAGIC_TYPE/;
use Apache2::EmbedFLV::Template;
use Data::Dumper;
use Cwd;
use Digest::MD5 qw/md5_hex/;

sub handler {
	my($r) = shift;

	if(! -e $r->filename) {
		return Apache2::Const::NOT_FOUND;
	} elsif(! -r $r->filename) {
		return Apache2::Const::FORBIDDEN;
	} else {
		my $req = Apache2::Request->new($r);

		if(
				# let's face it, this is why Perl sucks
				$req->param and
				scalar keys %{$req->param} == 1 and
				not $req->param( ${ [ keys %{$param} ] }[0] ) and
				length ${ [ keys %{$req->param} ] }[0] == 32
		) {
			my($md5) = keys %{$req->param}; # not too intuitive
			if($md5 eq md5_hex($r->filename)) {
				$r->content_type("video/x-flv");
				open my $fh, "<", $r->filename or die "Apache2::EmbedFLV wrong $!!";
				while(<$fh>) {
					$r->print($_);
				}
				close $fh;
				return Apache2::Const::OK;
			} else {
				return Apache2::Const::FORBIDDEN;
			}
		} else {
			my $md5 = md5_hex($r->filename);
			$r->content_type("text/html");

			my $template = $r->dir_config('template');
			my $flowplayer = $r->dir_config("flowplayer");

			my $t = Apache2::EmbedFLV::Template->new($template);
			$r->print(
				$t->process(
					uri => $r->uri,
					md5 => $md5,
					flowplayer => $flowplayer,
					template => $template
				)
			);

			return Apache2::Const::OK;
		}
	}
}

1;

__END__
Hello! Your md5 cookie is [% md5 %]



( run in 2.287 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )