- $dlurl = $t->{'xml'}->{'video'}->{'hd_file'} || $t->{'xml'}->{'video'}->{'file'};
- $timestamp = $t->{'xml'}->{'timestamp'};
-
- unless(defined($dlurl)) {
- return undef;
- }
-
- # Vimeo appends a hash to the download URL, in order to thwart people like me.
- # Unfortunately the algorithm isn't that complicated :)
- if ($dlurl =~ m|http://bitcast.vimeo.com(.+)|) {
- $dlpath = $1;
- $timestamp += 1800;
- $hash = md5_hex(sprintf('redFiretruck%s?e=%d', $dlpath, $timestamp));
- } else {
- return undef;
+ $p = HTML::TokeParser->new(\$content);
+
+ while ($e = $p->get_tag('script')) {
+ if ($e->[0] eq 'script') {
+ my $t = $p->get_text();
+
+ if ($t =~ m|clip\d+_\d+ = (.*\});Player|s) {
+ my $jsp = videosite::JSArrayParser->new();
+ my $r;
+
+ $self->debug("Found raw config: %s", $1);
+ $r = $jsp->parse($1);
+
+ unless(defined($r)) {
+ $self->error("Found information hash, but could not parse");
+ return undef;
+ }
+
+ $self->debug("Found parsed config: %s", Dumper($r));
+
+ unless(exists($r->{'config'}->{'request'})) {
+ $self->error("Required information not found in hash");
+ return undef;
+ }
+
+ $metadata->{'TITLE'} = $r->{'config'}->{'video'}->{'title'};
+ $hd = grep { $_ eq 'hd' } @{$r->{'config'}->{'video'}->{'files'}->{'h264'}};
+ $self->debug("HD: %d", $hd);
+ $r = $r->{'config'}->{'request'};
+
+ $metadata->{'DLURL'} = sprintf("http://%s/play_redirect?clip_id=%d&sig=%s&time=%d&quality=%s&codecs=H264,VP8,VP6",
+ $r->{'player_url'},
+ $metadata->{'ID'},
+ $r->{'signature'},
+ $r->{'timestamp'},
+ $hd?'hd':'sd',
+ );
+ }
+ }