Change new() function in plugins to avoid having to call _prepare_parameters() in...
[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 masturbation in shower',
24         _PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*motherless.com/([a-zA-Z0-9]+))'],
25     );
26
27     return bless($self, $class);
28 }
29
30 sub _parse {
31     my $self = shift;
32     my $url = shift;
33     my $pattern = shift;
34     my $ua = $self->ua();
35     my $content;
36     my $metadata = {};
37     my $p;
38     my $r;
39     my $tag;
40     my $dir;
41     my $hash;
42
43     $url =~ m|$pattern|;
44     $url = $1;
45
46     $metadata->{'URL'} = $url;
47     $metadata->{'ID'} = $2;
48     $metadata->{'TYPE'} = 'video';
49     $metadata->{'SOURCE'} = $self->{'NAME'};
50     $metadata->{'TITLE'} = undef;
51     $metadata->{'DLURL'} = undef;
52
53     unless(defined($content = $self->simple_get(sprintf("http://motherless.com/%s", $2), $ua))) {
54         $self->error('Could not download page');
55         return undef;
56     }
57
58     $p = HTML::TokeParser->new(\$content);
59
60     # Look for the title
61     while ($tag = $p->get_tag('title', 'script')) {
62         if ('title' eq $tag->[0]) {
63             my $t = $p->get_text();
64             $metadata->{'TITLE'} = $t;
65             $metadata->{'TITLE'} =~ s/.* : *//;
66         } elsif ('script' eq $tag->[0]) {
67             my $t = $p->get_text();
68
69             if ($t =~ m|__fileurl = '(.*)';|) {
70                 $self->debug("Found fileurl: %s", $1);
71                 $metadata->{'DLURL'} = $1;
72             }
73         }
74     }
75
76     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
77         $self->error('Could not extract download URL and title');
78         return undef;
79     }
80
81     return $metadata;
82 }
83
84 1;