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->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*vimeo.com/(\d+))'];
25 $self->_prepare_parameters();
36 my $p = XML::Simple->new();
47 $metadata->{'URL'} = $url;
48 $metadata->{'ID'} = $2;
49 $metadata->{'TYPE'} = 'video';
50 $metadata->{'SOURCE'} = $self->{'NAME'};
51 $metadata->{'TITLE'} = undef;
52 $metadata->{'DLURL'} = undef;
54 # Get the XML file containing the video metadata
55 unless(defined($content = $self->simple_get(sprintf('http://www.vimeo.com/moogaloop/load/clip:%s', $2)))) {
56 $self->error('Could not download XML metadata');
60 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
61 $self->error('Could not parse XML metadata');
65 if (exists($t->{'xml'}->{'video'}->{'isHD'}) and (0 != $t->{'xml'}->{'video'}->{'isHD'})) {
66 $self->debug('Selecting HD video');
69 $self->debug('Selecting SD video');
72 $timestamp = $t->{'xml'}->{'request_signature_expires'};
73 $hash = $t->{'xml'}->{'request_signature'};
74 $dlurl = sprintf('http://vimeo.com/moogaloop/play/clip:%s/%s/%d%s', $metadata->{'ID'}, $hash, $timestamp, $hd);
76 unless(defined($dlurl)) {
77 $self->error('No dlurl found in XML');
81 # # Vimeo appends a hash to the download URL, in order to thwart people like me.
82 # # Unfortunately the algorithm isn't that complicated :)
83 # if ($dlurl =~ m|http://bitcast.vimeo.com(.+)|) {
86 # $hash = md5_hex(sprintf('redFiretruck%s?e=%d', $dlpath, $timestamp));
88 # $self->error('Unknown dlurl scheme: %s', $dlurl);
92 # $metadata->{'DLURL'} = sprintf('%s?e=%d&h=%s', $dlurl, $timestamp, $hash);
93 $metadata->{'DLURL'} = $dlurl;
94 $metadata->{'TITLE'} = $t->{'xml'}->{'video'}->{'caption'};
96 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
97 $self->error('Could not extract download URL and title');