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->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*redtube.com/(\d+))'];
27 $self->_prepare_parameters();
33 return ($_[0] - ($_[0] % $_[1])) / $_[1];
36 sub digitatindex($$) {
37 return div($_[0], 10**$_[1]) % 10;
45 my @key = split(//, "R15342O7K9HBCDXFGAIJ8LMZ6PQ0STUVWEYN");
48 # Calculate a weighed digit sum of the id
49 $q += ($_*($i--)) for reverse(split(//, $id));
51 # Now calculate the digit sum of the digit sum
52 $q2 += $_ for split(//, $q);
54 # The rest are lookups into @key and the second digit sum,
55 # based on the second digit sum and the original id
56 $hash .= $key[digitatindex($id,3)+$q2+3];
57 $hash .= digitatindex($q2, 0);
58 $hash .= $key[digitatindex($id,6)+$q2+2];
59 $hash .= $key[digitatindex($id,4)+$q2+1];
60 $hash .= $key[digitatindex($id,1)+$q2+6];
61 $hash .= $key[digitatindex($id,5)+$q2+5];
62 $hash .= digitatindex($q2, 1);
63 $hash .= $key[digitatindex($id,2)+$q2+7];
64 $hash .= $key[digitatindex($id,0)+$q2+4];
66 return (sprintf("%07d", $id/1000), $hash);
84 $metadata->{'URL'} = $url;
85 $metadata->{'ID'} = $2;
86 $metadata->{'TYPE'} = 'video';
87 $metadata->{'SOURCE'} = $self->{'NAME'};
88 $metadata->{'TITLE'} = undef;
89 $metadata->{'DLURL'} = undef;
91 # Set the cookies necessary to get the video data
92 $ua->cookie_jar->set_cookie(undef, 'pp', '1', '/', '.redtube.com');
94 unless(defined($content = $self->simple_get(sprintf("http://www.redtube.com/%s", $2), $ua))) {
95 $self->error('Could not download page');
99 $p = HTML::TokeParser->new(\$content);
102 if ($p->get_tag('title')) {
103 my $t = $p->get_text();
104 if ($t =~ /\xa0RedTube - /) {
105 $metadata->{'TITLE'} = $t;
106 $metadata->{'TITLE'} =~ s/\xa0RedTube - //;
110 # Redtube uses a selfmade hash system to create the filename
111 ($dir, $hash) = mkfilename($metadata->{'ID'});
113 $metadata->{'DLURL'} = sprintf('http://dl.redtube.com/_videos_t4vn23s9jc5498tgj49icfj4678/%s/%s.flv', $dir, $hash);
115 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
116 $self->error('Could not extract download URL and title');