X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FLiveLeakGrabber.pm;h=1e6bd7426adcb3e309505c765d509d66a91dc607;hb=09d45a4c4460dce9322f4528dad5123322ab6b38;hp=4e49d44c197e605ff5f6e195e292bffb4fa3e600;hpb=863f20e50395e650cfa524adfeddc8132951c01a;p=videosite.git diff --git a/videosite/LiveLeakGrabber.pm b/videosite/LiveLeakGrabber.pm index 4e49d44..1e6bd74 100644 --- a/videosite/LiveLeakGrabber.pm +++ b/videosite/LiveLeakGrabber.pm @@ -3,12 +3,11 @@ # # Grabber for liveleak.com -package LiveLeakGrabber; +package videosite::LiveLeakGrabber; -use GrabberBase; -@ISA = qw(GrabberBase); +use videosite::GrabberBase; +@ISA = qw(videosite::GrabberBase); -use LWP::Simple qw(!get); use HTML::TokeParser; use Data::Dumper; @@ -16,15 +15,15 @@ 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; + 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 { @@ -34,6 +33,8 @@ sub _parse { my $content; my $metadata = {}; my $p; + my $tag; + my $ua = $self->ua(); $url =~ m|$pattern|; $url = $1; @@ -46,7 +47,7 @@ sub _parse { $metadata->{'DLURL'} = undef; # Get the site to extract the title - unless(defined($content = LWP::Simple::get($url))) { + unless(defined($content = $self->simple_get($url, $ua))) { $self->error('Could not download page'); return undef; } @@ -54,23 +55,21 @@ sub _parse { $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; + 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; + } + } } - $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');