fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / MotherlessGrabber.pm
1 # (c) 2008 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for motherless.com
5 #
6 # written by Maximilian Rehkopf  <otakon at gmx dot net>
7
8 package videosite::MotherlessGrabber;
9
10 use videosite::GrabberBase;
11 @ISA = qw(videosite::GrabberBase);
12
13 use HTML::TokeParser;
14 use Data::Dumper;
15
16 use strict;
17
18 sub new {
19     my $class = shift;
20     my $self = $class->SUPER::new(
21         NAME => 'motherless',
22         _SELFTESTURL => 'http://motherless.com/4976432',
23         _SELFTESTTITLE => 'Teen Masturbating In Shower',
24         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*motherless.com/([a-zA-Z0-9]+))'],
25         @_,
26     );
27
28     return bless($self, $class);
29 }
30
31 sub _parse {
32     my $self = shift;
33     my $url = shift;
34     my $pattern = shift;
35     my $ua = $self->ua();
36     my $content;
37     my $metadata = {};
38     my $p;
39     my $r;
40     my $tag;
41     my $dir;
42     my $hash;
43
44     $url =~ m|$pattern|;
45     $url = $1;
46
47     $metadata->{'URL'} = $url;
48     $metadata->{'ID'} = $2;
49     $metadata->{'TYPE'} = 'video';
50     $metadata->{'SOURCE'} = $self->{'NAME'};
51     $metadata->{'TITLE'} = undef;
52     $metadata->{'DLURL'} = undef;
53
54     unless(defined($content = $self->simple_get(sprintf("http://motherless.com/%s", $2), $ua))) {
55         $self->error('Could not download page');
56         return undef;
57     }
58
59     $p = HTML::TokeParser->new(\$content);
60
61     # Look for the title
62     while ($tag = $p->get_tag('meta', 'script')) {
63         if (('meta' eq $tag->[0]) and ($tag->[1]->{'name'}) and ($tag->[1]->{'name'} eq 'description')) {
64             $metadata->{'TITLE'} = $tag->[1]->{'content'};
65         } elsif ('script' eq $tag->[0]) {
66             my $t = $p->get_text();
67
68             if ($t =~ m|__fileurl = '(.*)';|) {
69                 $self->debug("Found fileurl: %s", $1);
70                 $metadata->{'DLURL'} = $1;
71             }
72         }
73     }
74
75     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
76         $self->error('Could not extract download URL and title');
77         return undef;
78     }
79
80     return $metadata;
81 }
82
83 1;