From 376da74c2839797a731f34894ea7ca35f8b2612b Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Wed, 15 Feb 2012 00:11:24 +0100 Subject: [PATCH] Youtube: Add new page format (yt.playerConfig) --- videosite/YouTubeGrabber.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/videosite/YouTubeGrabber.pm b/videosite/YouTubeGrabber.pm index ca8f49b..f164af2 100644 --- a/videosite/YouTubeGrabber.pm +++ b/videosite/YouTubeGrabber.pm @@ -338,8 +338,35 @@ sub _parse_by_scrape { $self->error('fmt_url_map not found in PLAYER_CONFIG'); return undef; } + } elsif ($e =~ m|yt\.playerConfig\s*=\s*(.+);\n|) { + my $args = $1; + $self->debug("Found yt.playerConfig: %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'}->{'ps'}) and ($r->{'args'}->{'ps'} eq 'live')) { + $self->error("Video URL seems to point to a live stream, cannot save this"); + return undef; + } + + if (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: 2012 (yt.playerConfig), url_encoded_fmt_stream_map"); + } else { + $self->error('url_map not found in yt.playerConfig'); + return undef; + } } + if (%urls) { $self->__pick_url(\%urls, $preflist, $metadata); last SWF_ARGS; -- 1.8.3.1