+ } elsif ('script' eq $e->[0]) {
+ my $c = $p->get_text();
+
+ $self->debug("Found script: %s", $c);
+
+ if ($c =~ m|flashvars = (.+);$|m) {
+ my $flashvars = $1;
+ my $jsp = videosite::JSArrayParser->new();
+ my $l;
+ my $s;
+ my $sequence;
+
+ $self->debug("Found flashvars: %s", $flashvars);
+
+ $self->debug("Using %s to parse", ref($jsp));
+ $flashvars = $jsp->parse($flashvars);
+ $self->debug("Parsed flashvars: %s", Dumper($flashvars));
+
+ $sequence = $flashvars->{'sequence'};
+ $sequence =~ s/%(..)/chr(hex($1))/ge;
+
+ $self->debug("Decoded sequence: %s", $sequence);
+ $sequence = $jsp->parse($sequence);
+
+ unless(defined($sequence)) {
+ $self->error("Found sequence, but could not parse");
+ return undef;
+ } else {
+ $self->debug("Parsed sequence: %s", Dumper($sequence));
+
+ $l = $self->_fetch_layer($sequence->{'sequence'}, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
+ unless(defined($l)) {
+ $self->error("Could not find video layer");
+ return undef;
+ }
+
+ # Found video section
+ if (exists($l->{'hd1080URL'})) {
+ $metadata->{'DLURL'} = $l->{'hd1080URL'};
+ } elsif (exists($l->{'hd720URL'})) {
+ $metadata->{'DLURL'} = $l->{'hd720URL'};
+ } elsif (exists($l->{'hqURL'})) {
+ $metadata->{'DLURL'} = $l->{'hqURL'};
+ } elsif (exists($l->{'sdURL'})) {
+ $metadata->{'DLURL'} = $l->{'sdURL'};
+ } elsif (exists($l->{'ldURL'})) {
+ $metadata->{'DLURL'} = $l->{'ldURL'};
+ } else {
+ $self->error("Video section found, but no URLs");
+ return undef;
+ }
+ }
+ }