fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / LiveLeakGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for liveleak.com
5
6 package videosite::LiveLeakGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use HTML::TokeParser;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new(
19         NAME => 'liveleak',
20         _SELFTESTURL => 'http://www.liveleak.com/view?i=688_1259911803',
21         _SELFTESTTITLE => 'Girl Wins Street Fight By Choking Her Opponent Out Cold',
22         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*liveleak.com/view\?i=([^\&]+))'],
23         @_,
24     );
25
26     return bless($self, $class);
27 }
28
29 sub _parse {
30     my $self = shift;
31     my $url = shift;
32     my $pattern = shift;
33     my $content;
34     my $metadata = {};
35     my $p;
36     my $tag;
37     my $ua = $self->ua();
38
39     $url =~ m|$pattern|;
40     $url = $1;
41
42     $metadata->{'URL'} = $url;
43     $metadata->{'ID'} = $2;
44     $metadata->{'TYPE'} = 'video';
45     $metadata->{'SOURCE'} = $self->{'NAME'};
46     $metadata->{'TITLE'} = undef;
47     $metadata->{'DLURL'} = undef;
48
49     # Get the site to extract the title
50     unless(defined($content = $self->simple_get($url, $ua))) {
51         $self->error('Could not download page');
52         return undef;
53     }
54
55     $p = HTML::TokeParser->new(\$content);
56
57     # Look for the title
58     while ($tag = $p->get_tag('script', 'meta')) {
59         if ('meta' eq $tag->[0]) {
60             if (exists($tag->[1]->{property}) and ('og:title' eq $tag->[1]->{property})) {
61                 $metadata->{'TITLE'} = $tag->[1]->{content};
62                 $metadata->{'TITLE'} =~ s/^LiveLeak\.com - //;
63             }
64         } elsif ('script' eq $tag->[0]) {
65             my $e = $p->get_text();
66
67             if ($e =~ /file: "([^"]+)"/) {
68                 $self->debug("Found file: %s", $1);
69                 $metadata->{'DLURL'} = $1;
70             }
71         }
72     }
73
74     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
75         $self->error('Could not extract download URL and title');
76         return undef;
77     }
78
79     return $metadata;
80 }
81
82 1;