# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for liveleak.com package videosite::LiveLeakGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use HTML::TokeParser; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'liveleak', _SELFTESTURL => 'http://www.liveleak.com/view?i=688_1259911803', _SELFTESTTITLE => 'Girl Wins Street Fight By Choking Her Opponent Out Cold', PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*liveleak.com/view\?i=([^\&]+))'], @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p; my $tag; my $ua = $self->ua(); $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 = $self->simple_get($url, $ua))) { $self->error('Could not download page'); return undef; } $p = HTML::TokeParser->new(\$content); # Look for the title while ($tag = $p->get_tag('script', 'meta')) { if ('meta' eq $tag->[0]) { if (exists($tag->[1]->{property}) and ('og:title' eq $tag->[1]->{property})) { $metadata->{'TITLE'} = $tag->[1]->{content}; $metadata->{'TITLE'} =~ s/^LiveLeak\.com - //; } } elsif ('script' eq $tag->[0]) { my $e = $p->get_text(); if ($e =~ /file: "([^"]+)"/) { $self->debug("Found file: %s", $1); $metadata->{'DLURL'} = $1; } } } unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { $self->error('Could not extract download URL and title'); return undef; } return $metadata; } 1;