--- /dev/null
+# (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
+# licensed under GNU GPL v2
+#
+# Grabber for liveleak.com
+
+package LiveLeakGrabber;
+
+use GrabberBase;
+@ISA = qw(GrabberBase);
+
+use LWP::Simple qw(!get);
+use HTML::TokeParser;
+use Data::Dumper;
+
+use strict;
+
+sub new {
+ my $class = shift;
+ my $self = $class->SUPER::new();
+
+ $self->{'NAME'} = 'liveleak';
+ $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*liveleak.com/view\?i=([^\&]+))'];
+
+ bless($self, $class);
+ $self->_prepare_parameters();
+
+ return $self;
+}
+
+sub _parse {
+ my $self = shift;
+ my $url = shift;
+ my $pattern = shift;
+ my $content;
+ my $metadata = {};
+ my $p;
+
+ $url =~ m|$pattern|;
+ $url = $1;
+
+ $metadata->{'URL'} = $url;
+ $metadata->{'ID'} = $2;
+ $metadata->{'TYPE'} = 'video';
+ $metadata->{'SOURCE'} = $self->{'NAME'};
+ $metadata->{'TITLE'} = undef;
+ $metadata->{'DLURL'} = undef;
+
+ # Get the site to extract the title
+ unless(defined($content = LWP::Simple::get($url))) {
+ $self->error('Could not download page');
+ return undef;
+ }
+
+ $p = HTML::TokeParser->new(\$content);
+
+ # Look for the title
+ if ($p->get_tag('title')) {
+ $metadata->{'TITLE'} = $p->get_text();
+ $metadata->{'TITLE'} =~ s/^LiveLeak\.com\s+-\s+(.+)$/$1/im;
+ }
+
+ # Get the file containing the video metadata
+ unless(defined($content = LWP::Simple::get(sprintf('http://www.liveleak.com/mi?token=%s', $2)))) {
+ $self->error('Could not download metadata');
+ return undef;
+ }
+
+ unless ($content =~ m/file_location=([^\&]+)\&/) {
+ $self->error('Could not find download URL');
+ return undef;
+ }
+ $metadata->{'DLURL'} = $1;
+ $metadata->{'DLURL'} =~ s/%(..)/chr(hex($1))/ge;
+
+ unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
+ $self->error('Could not extract download URL and title');
+ return undef;
+ }
+
+ return $metadata;
+}
+
+1;