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);
11 use LWP::Simple qw(!get);
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();
48 $metadata->{'URL'} = $url;
49 $metadata->{'ID'} = $2;
50 $metadata->{'TYPE'} = 'video';
51 $metadata->{'SOURCE'} = $self->{'NAME'};
52 $metadata->{'TITLE'} = undef;
53 $metadata->{'DLURL'} = undef;
55 # Get the XML file containing the video metadata
56 unless(defined($content = LWP::Simple::get(sprintf('http://www.vimeo.com/moogaloop/load/clip:%s/local?context=default&context_id=undefined', $2)))) {
57 $self->error('Could not download XML metadata');
61 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
62 $self->error('Could not parse XML metadata');
66 if (exists($t->{'xml'}->{'video'}->{'isHD'}) and (0 != $t->{'xml'}->{'video'}->{'isHD'})) {
67 $self->debug('Selecting HD video');
70 $self->debug('Selecting SD video');
73 $timestamp = $t->{'xml'}->{'request_signature_expires'};
74 $hash = $t->{'xml'}->{'request_signature'};
75 $dlurl = sprintf('http://vimeo.com/moogaloop/play/clip:%s/%s/%d%s', $metadata->{'ID'}, $hash, $timestamp, $hd);
77 unless(defined($dlurl)) {
78 $self->error('No dlurl found in XML');
82 # # Vimeo appends a hash to the download URL, in order to thwart people like me.
83 # # Unfortunately the algorithm isn't that complicated :)
84 # if ($dlurl =~ m|http://bitcast.vimeo.com(.+)|) {
87 # $hash = md5_hex(sprintf('redFiretruck%s?e=%d', $dlpath, $timestamp));
89 # $self->error('Unknown dlurl scheme: %s', $dlurl);
93 # $metadata->{'DLURL'} = sprintf('%s?e=%d&h=%s', $dlurl, $timestamp, $hash);
94 $metadata->{'DLURL'} = $dlurl;
95 $metadata->{'TITLE'} = $t->{'xml'}->{'video'}->{'caption'};
97 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
98 $self->error('Could not extract download URL and title');