YouTube: explicitly specify first pass decoding for _decode_url_encoded_fmt_stream_map
[videosite.git] / videosite / YouTubeGrabber.pm
index 56bf65c..97327bd 100644 (file)
@@ -139,7 +139,7 @@ sub _parse_by_video_info {
         $urls = $self->decode_hexurl($content->{'fmt_url_map'});
         $urls = { split /[\|,]/, $urls };
     } elsif (exists($content->{'url_encoded_fmt_stream_map'})) {
-        $urls = $self->_decode_url_encoded_fmt_stream_map($content->{'url_encoded_fmt_stream_map'});
+        $urls = $self->_decode_url_encoded_fmt_stream_map($content->{'url_encoded_fmt_stream_map'}, 1);
     } else {
         $self->debug("No URL data found");
         return undef;
@@ -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 $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 &