Youtube: Add support for the latest page redesign variant (PLAYER_CONFIG)
authorRalf Ertzinger <ralf@skytale.net>
Thu, 3 Mar 2011 08:34:37 +0000 (09:34 +0100)
committerRalf Ertzinger <ralf@skytale.net>
Thu, 3 Mar 2011 08:34:37 +0000 (09:34 +0100)
videosite/YouTubeGrabber.pm

index 487d95f..ebb4fc2 100644 (file)
@@ -193,6 +193,34 @@ sub _parse {
                 $urls =~ s/%([[:xdigit:]]{2})/chr(hex($1))/ge;
                 %urls = split(/[\|,]/, $urls);
                 $self->debug("Pagetype: 2010 (swfHTML), fmt_url_map");
+            } elsif ($e =~ m|\x27PLAYER_CONFIG\x27:\s+(.+)\}\);|) {
+                my $args = $1;
+                $self->debug("Found PLAYER_CONFIG: %s", $args);
+
+                $jsp = videosite::JSArrayParser->new();
+                $self->debug("Using %s to parse", ref($jsp));
+                $r = $jsp->parse($args);
+
+                unless(defined($r)) {
+                    $self->error("Found information hash, but could not parse");
+                    return undef;
+                }
+
+                if (exists($r->{'args'}) and exists($r->{'args'}->{'fmt_url_map'}) and ($r->{'args'}->{'fmt_url_map'} ne '')) {
+                    my $urls = $r->{'args'}->{'fmt_url_map'};
+
+                    $self->debug("Video has fmt_url_map: %s", $urls);
+
+                    %urls = split(/[\|,]/, $urls);
+                    foreach (keys(%urls)) {
+                        my $u = $urls{$_};
+                        $u =~ s/%([[:xdigit:]]{2})/chr(hex($1))/ge;
+                        $urls{$_} = $u;
+                    }
+                    $self->debug("Pagetype: 2011 (PLAYER_CONFIG), fmt_url_map");
+                } else {
+                    $self->error('fmt_url_map not found in PLAYER_CONFIG');
+                }
             }
 
             if (%urls) {