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);
12 use Digest::MD5 qw(md5_hex);
19 my $self = $class->SUPER::new();
21 $self->{'NAME'} = 'vimeo';
22 $self->{_SELFTESTURL} = 'http://vimeo.com/35055590';
23 $self->{_SELFTESTTITLE} = 'Hello';
24 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*vimeo.com/(\d+))'];
27 $self->_prepare_parameters();
38 my $p = XML::Simple->new();
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 unless(defined($content = $self->simple_get(sprintf('http://www.vimeo.com/moogaloop/load/clip:%s', $2)))) {
58 $self->error('Could not download XML metadata');
62 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
63 $self->error('Could not parse XML metadata');
67 if (exists($t->{'xml'}->{'video'}->{'isHD'}) and (0 != $t->{'xml'}->{'video'}->{'isHD'})) {
68 $self->debug('Selecting HD video');
71 $self->debug('Selecting SD video');
74 $timestamp = $t->{'xml'}->{'request_signature_expires'};
75 $hash = $t->{'xml'}->{'request_signature'};
76 $dlurl = sprintf('http://vimeo.com/moogaloop/play/clip:%s/%s/%d%s', $metadata->{'ID'}, $hash, $timestamp, $hd);
78 unless(defined($dlurl)) {
79 $self->error('No dlurl found in XML');
83 # # Vimeo appends a hash to the download URL, in order to thwart people like me.
84 # # Unfortunately the algorithm isn't that complicated :)
85 # if ($dlurl =~ m|http://bitcast.vimeo.com(.+)|) {
88 # $hash = md5_hex(sprintf('redFiretruck%s?e=%d', $dlpath, $timestamp));
90 # $self->error('Unknown dlurl scheme: %s', $dlurl);
94 # $metadata->{'DLURL'} = sprintf('%s?e=%d&h=%s', $dlurl, $timestamp, $hash);
95 $metadata->{'DLURL'} = $dlurl;
96 $metadata->{'TITLE'} = $t->{'xml'}->{'video'}->{'caption'};
98 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
99 $self->error('Could not extract download URL and title');