From bfa96f21d49c38615707963d596f269ffc48f0f3 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Sun, 12 Feb 2012 17:15:59 +0100 Subject: [PATCH] Zero Punctuation: fix grabber --- videosite/ZeroPunctuationGrabber.pm | 41 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/videosite/ZeroPunctuationGrabber.pm b/videosite/ZeroPunctuationGrabber.pm index 0ee5ffb..a9538fe 100644 --- a/videosite/ZeroPunctuationGrabber.pm +++ b/videosite/ZeroPunctuationGrabber.pm @@ -10,6 +10,7 @@ use videosite::GrabberBase; use HTML::TokeParser; use Data::Dumper; +use videosite::JSArrayParser; use strict; @@ -18,7 +19,9 @@ sub new { my $self = $class->SUPER::new(); $self->{'NAME'} = 'zeropunctuation'; - $self->{'PATTERNS'} = ['(http://www.escapistmagazine.com/articles/view/editorials/zeropunctuation/([-A-Za-z0-9]+))']; + $self->{_SELFTESTURL} = 'http://www.escapistmagazine.com/videos/view/zero-punctuation/5346-Amy'; + $self->{_SELFTESTTITLE} = 'Amy'; + $self->{'PATTERNS'} = ['(http://www.escapistmagazine.com/videos/view/zero-punctuation/([-A-Za-z0-9]+))']; bless($self, $class); $self->_prepare_parameters(); @@ -34,6 +37,9 @@ sub _parse { my $metadata = {}; my $p; my $e; + my $j; + my $jsp; + my $r; $url =~ m|$pattern|; $url = $1; @@ -52,16 +58,33 @@ sub _parse { $p = HTML::TokeParser->new(\$content); - # Look for the title - if ($p->get_tag('title')) { - $metadata->{'TITLE'} = $p->get_text(); - $metadata->{'TITLE'} =~ s/^The Escapist : Zero Punctuation: (.*)$/$1/im; + while ($e = $p->get_tag('div', 'param')) { + if (($e->[0] eq 'param') and exists($e->[1]->{name}) and ($e->[1]->{name} eq 'flashvars')) { + my %r = map { $self->decode_hexurl($_) } split(/[&=]/, $e->[1]->{value}); + + unless(exists($r{config})) { + $self->error("config URL not found in flashvars"); + return undef; + } + + $j = $r{config}; + } elsif (($e->[0] eq 'div') and exists($e->[1]->{itemprop}) and ($e->[1]->{itemprop} eq 'name')) { + $metadata->{'TITLE'} = $p->get_phrase(); + } } - while ($e = $p->get_tag('script')) { - my $c = $p->get_text(); - if ($c =~ m|var vars = \{file:\x27([^\x27]+)\x27|) { - $metadata->{'DLURL'} = 'http://' . $1 . '_high.flv'; + unless(defined($content = $self->simple_get($j))) { + $self->error("Could not download %s", $j); + return undef; + } + + $jsp = videosite::JSArrayParser->new(); + $r = $jsp->parse($content); + + foreach (@{$r->{playlist}}) { + if ($_->{eventCategory} eq 'Video') { + $metadata->{'DLURL'} = $_->{url}; + last; } } -- 1.8.3.1