From: Ralf Ertzinger Date: Tue, 28 May 2013 19:48:56 +0000 (+0200) Subject: Liveleak: Fix downloader and add self test X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=commitdiff_plain;h=d158da20419ae2c682f2c0d67b7739313e26466b Liveleak: Fix downloader and add self test --- diff --git a/videosite/LiveLeakGrabber.pm b/videosite/LiveLeakGrabber.pm index 4521f37..1e6bd74 100644 --- a/videosite/LiveLeakGrabber.pm +++ b/videosite/LiveLeakGrabber.pm @@ -17,6 +17,8 @@ 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=([^\&]+))'], @_, ); @@ -31,6 +33,7 @@ sub _parse { my $content; my $metadata = {}; my $p; + my $tag; my $ua = $self->ua(); $url =~ m|$pattern|; @@ -52,24 +55,22 @@ 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; + 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; + } + } } - # Get the file containing the video metadata - unless(defined($content = $self->simple_get(sprintf('http://www.liveleak.com/mi?token=%s', $2), $ua))) { - $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;