1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for vimeo.com
6 package videosite::VimeoGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
13 use Digest::MD5 qw(md5_hex);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'vimeo';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*vimeo.com/(\d+))'];
26 $self->_prepare_parameters();
37 my $p = XML::Simple->new();
44 my $ua = LWP::UserAgent->new(agent => 'Mozilla');
49 $metadata->{'URL'} = $url;
50 $metadata->{'ID'} = $2;
51 $metadata->{'TYPE'} = 'video';
52 $metadata->{'SOURCE'} = $self->{'NAME'};
53 $metadata->{'TITLE'} = undef;
54 $metadata->{'DLURL'} = undef;
56 # Get the XML file containing the video metadata
57 $content = $ua->get(sprintf('http://www.vimeo.com/moogaloop/load/clip:%s', $2));
58 unless ($content->is_success()) {
59 $self->error('Could not download XML metadata');
63 $content = $content->decoded_content();
65 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
66 $self->error('Could not parse XML metadata');
70 if (exists($t->{'xml'}->{'video'}->{'isHD'}) and (0 != $t->{'xml'}->{'video'}->{'isHD'})) {
71 $self->debug('Selecting HD video');
74 $self->debug('Selecting SD video');
77 $timestamp = $t->{'xml'}->{'request_signature_expires'};
78 $hash = $t->{'xml'}->{'request_signature'};
79 $dlurl = sprintf('http://vimeo.com/moogaloop/play/clip:%s/%s/%d%s', $metadata->{'ID'}, $hash, $timestamp, $hd);
81 unless(defined($dlurl)) {
82 $self->error('No dlurl found in XML');
86 # # Vimeo appends a hash to the download URL, in order to thwart people like me.
87 # # Unfortunately the algorithm isn't that complicated :)
88 # if ($dlurl =~ m|http://bitcast.vimeo.com(.+)|) {
91 # $hash = md5_hex(sprintf('redFiretruck%s?e=%d', $dlpath, $timestamp));
93 # $self->error('Unknown dlurl scheme: %s', $dlurl);
97 # $metadata->{'DLURL'} = sprintf('%s?e=%d&h=%s', $dlurl, $timestamp, $hash);
98 $metadata->{'DLURL'} = $dlurl;
99 $metadata->{'TITLE'} = $t->{'xml'}->{'video'}->{'caption'};
101 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
102 $self->error('Could not extract download URL and title');