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+))'],
26 return bless($self, $class);
46 $metadata->{'URL'} = $url;
47 $metadata->{'ID'} = $2;
48 $metadata->{'TYPE'} = 'video';
49 $metadata->{'SOURCE'} = $self->{'NAME'};
50 $metadata->{'TITLE'} = undef;
51 $metadata->{'DLURL'} = undef;
53 # Get the XML file containing the video metadata
54 unless(defined($content = $self->simple_get(sprintf('http://vimeo.com/%s', $2)))) {
55 $self->error('Could not download site');
59 $p = HTML::TokeParser->new(\$content);
61 while ($e = $p->get_tag('script')) {
62 if ($e->[0] eq 'script') {
63 my $t = $p->get_text();
65 if ($t =~ m|clip\d+_\d+ = (.*\});Player|s) {
66 my $jsp = videosite::JSArrayParser->new();
69 $self->debug("Found raw config: %s", $1);
73 $self->error("Found information hash, but could not parse");
77 $self->debug("Found parsed config: %s", Dumper($r));
79 unless(exists($r->{'config'}->{'request'})) {
80 $self->error("Required information not found in hash");
84 $metadata->{'TITLE'} = $r->{'config'}->{'video'}->{'title'};
85 $hd = grep { $_ eq 'hd' } @{$r->{'config'}->{'video'}->{'files'}->{'h264'}};
86 $self->debug("HD: %d", $hd);
87 $r = $r->{'config'}->{'request'};
89 $metadata->{'DLURL'} = sprintf("http://%s/play_redirect?clip_id=%d&sig=%s&time=%d&quality=%s&codecs=H264,VP8,VP6",
100 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
101 $self->error('Could not extract download URL and title');