From 315ef78575a1ed1abe085eb10e2cd6c7bc9d53b3 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Thu, 3 Mar 2011 09:34:37 +0100 Subject: [PATCH] Youtube: Add support for the latest page redesign variant (PLAYER_CONFIG) --- videosite/YouTubeGrabber.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/videosite/YouTubeGrabber.pm b/videosite/YouTubeGrabber.pm index 487d95f..ebb4fc2 100644 --- a/videosite/YouTubeGrabber.pm +++ b/videosite/YouTubeGrabber.pm @@ -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) { -- 1.8.3.1