YouTube: Correctly parse url_encoded_fmt_stream_map from the web scape, too
authorRalf Ertzinger <ralf@skytale.net>
Mon, 8 Aug 2011 20:16:23 +0000 (22:16 +0200)
committerRalf Ertzinger <ralf@skytale.net>
Mon, 8 Aug 2011 20:16:23 +0000 (22:16 +0200)
videosite/YouTubeGrabber.pm

index 56bf65c..fd3e0c0 100644 (file)
@@ -290,7 +290,7 @@ sub _parse_by_scrape {
                 $urls = $self->decode_hexurl($urls);
                 %urls = split(/[\|,]/, $urls);
                 $self->debug("Pagetype: 2010 (swfHTML), fmt_url_map");
-            } elsif ($e =~ m|\x27PLAYER_CONFIG\x27:\s+(.+)\}\);|) {
+            } elsif ($e =~ m|\x27PLAYER_CONFIG\x27:\s+(.+)(?:\}\);)?|) {
                 my $args = $1;
                 $self->debug("Found PLAYER_CONFIG: %s", $args);
 
@@ -318,6 +318,10 @@ sub _parse_by_scrape {
                         $urls{$_} = $self->decode_hexurl($urls{$_});
                     }
                     $self->debug("Pagetype: 2011 (PLAYER_CONFIG), fmt_url_map");
+                } elsif (exists($r->{'args'}) and exists($r->{'args'}->{'url_encoded_fmt_stream_map'}) and ($r->{'args'}->{'url_encoded_fmt_stream_map'} ne '')) {
+                    %urls = %{$self->_decode_url_encoded_fmt_stream_map($r->{'args'}->{'url_encoded_fmt_stream_map'}, 0)};
+
+                    $self->debug("Pagetype: 2011 (PLAYER_CONFIG), url_encoded_fmt_stream_map");
                 } else {
                     $self->error('fmt_url_map not found in PLAYER_CONFIG');
                     return undef;
@@ -459,9 +463,11 @@ sub __login {
 # matching video IDs to download URLs
 sub _decode_url_encoded_fmt_stream_map {
     my $self = shift;
-    my $data = $self->decode_hexurl(shift);
+    my $data = shift;
+    my $dataencoded = shift;
     my @data;
 
+    $data = $self->decode_hexurl($data) if (defined($dataencoded) && $dataencoded);
     # This will
     # - Split the decoded string into segments (along ,)
     # - Interpret each segment as a concatenated key-value list (key and value separated by =, pairs separated by &