1 # (c) 2008 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for redtube.com
6 # Algorithm for the file name hash reverse engineered by
7 # Maximilian Rehkopf <otakon at gmx dot net>
9 package videosite::RedTubeGrabber;
11 use videosite::GrabberBase;
12 @ISA = qw(videosite::GrabberBase);
21 my $self = $class->SUPER::new();
23 $self->{'NAME'} = 'redtube';
24 $self->{_SELFTESTURL} = 'http://www.redtube.com/8269';
25 $self->{_SELFTESTTITLE} = 'Porn bloopers with pretty girl';
26 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*redtube.com/(\d+))'];
29 $self->_prepare_parameters();
35 return ($_[0] - ($_[0] % $_[1])) / $_[1];
38 sub digitatindex($$) {
39 return div($_[0], 10**$_[1]) % 10;
47 my @key = split(//, "R15342O7K9HBCDXFGAIJ8LMZ6PQ0STUVWEYN");
50 # Calculate a weighed digit sum of the id
51 $q += ($_*($i--)) for reverse(split(//, $id));
53 # Now calculate the digit sum of the digit sum
54 $q2 += $_ for split(//, $q);
56 # The rest are lookups into @key and the second digit sum,
57 # based on the second digit sum and the original id
58 $hash .= $key[digitatindex($id,3)+$q2+3];
59 $hash .= digitatindex($q2, 0);
60 $hash .= $key[digitatindex($id,6)+$q2+2];
61 $hash .= $key[digitatindex($id,4)+$q2+1];
62 $hash .= $key[digitatindex($id,1)+$q2+6];
63 $hash .= $key[digitatindex($id,5)+$q2+5];
64 $hash .= digitatindex($q2, 1);
65 $hash .= $key[digitatindex($id,2)+$q2+7];
66 $hash .= $key[digitatindex($id,0)+$q2+4];
68 return (sprintf("%07d", $id/1000), $hash);
87 $metadata->{'URL'} = $url;
88 $metadata->{'ID'} = $2;
89 $metadata->{'TYPE'} = 'video';
90 $metadata->{'SOURCE'} = $self->{'NAME'};
91 $metadata->{'TITLE'} = undef;
92 $metadata->{'DLURL'} = undef;
94 # Set the cookies necessary to get the video data
95 $ua->cookie_jar->set_cookie(undef, 'pp', '1', '/', '.redtube.com');
97 unless(defined($content = $self->simple_get(sprintf("http://www.redtube.com/%s", $2), $ua))) {
98 $self->error('Could not download page');
102 $p = HTML::TokeParser->new(\$content);
105 while ($tag = $p->get_tag('title', 'script')) {
106 if ('title' eq $tag->[0]) {
107 my $t = $p->get_text();
108 $metadata->{'TITLE'} = $t;
109 $metadata->{'TITLE'} =~ s/ \| Redtube.*//;
110 } elsif ('script' eq $tag->[0]) {
111 my $t = $p->get_text();
113 if ($t =~ m|so\.addParam\("flashvars","([^\x22]+)"|) {
116 $self->debug("Found flashvars: %s", $1);
117 %h = map { $self->decode_hexurl($_) } split(/[&=]/, $1);
119 $self->debug("Decoded flashvars: %s", Dumper(\%h));
121 if (exists($h{mp4_url})) {
122 $metadata->{'DLURL'} = $h{mp4_url};
128 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
129 $self->error('Could not extract download URL and title');