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 videosite::JSArrayParser;
19 my $self = $class->SUPER::new(
21 _SELFTESTURL => 'http://vimeo.com/35055590',
22 _SELFTESTTITLE => 'Hello',
23 PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*vimeo.com/(?:m/)?(\d+))'],
27 return bless($self, $class);
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://vimeo.com/%s', $2)))) {
56 $self->error('Could not download site');
60 $p = HTML::TokeParser->new(\$content);
62 while ($e = $p->get_tag('script')) {
63 if ($e->[0] eq 'script') {
64 my $t = $p->get_text();
66 if ($t =~ m|clip\d+_\d+ = (.*\});Player|s) {
67 my $jsp = videosite::JSArrayParser->new();
70 $self->debug("Found raw config: %s", $1);
74 $self->error("Found information hash, but could not parse");
78 $self->debug("Found parsed config: %s", Dumper($r));
80 unless(exists($r->{'config'}->{'request'})) {
81 $self->error("Required information not found in hash");
85 $metadata->{'TITLE'} = $r->{'config'}->{'video'}->{'title'};
86 $hd = grep { $_ eq 'hd' } @{$r->{'config'}->{'video'}->{'files'}->{'h264'}};
87 $self->debug("HD: %d", $hd);
88 $r = $r->{'config'}->{'request'};
90 $metadata->{'DLURL'} = sprintf("http://%s/play_redirect?clip_id=%d&sig=%s&time=%d&quality=%s&codecs=H264,VP8,VP6",
101 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
102 $self->error('Could not extract download URL and title');