X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FZeroPunctuationGrabber.pm;h=f40da054f59b3fa5dfd385f135f89d31826fe217;hb=513fff57bcf5c5724ea25fc69831b97f8f0bc0cc;hp=0ee5ffbcc49d374fec49e3460ee9d94f0b04f276;hpb=771fcc7e7309dcb054d652812cead6b6bf47be5f;p=videosite.git diff --git a/videosite/ZeroPunctuationGrabber.pm b/videosite/ZeroPunctuationGrabber.pm index 0ee5ffb..f40da05 100644 --- a/videosite/ZeroPunctuationGrabber.pm +++ b/videosite/ZeroPunctuationGrabber.pm @@ -10,20 +10,21 @@ use videosite::GrabberBase; use HTML::TokeParser; use Data::Dumper; +use videosite::JSArrayParser; use strict; sub new { my $class = shift; - my $self = $class->SUPER::new(); - - $self->{'NAME'} = 'zeropunctuation'; - $self->{'PATTERNS'} = ['(http://www.escapistmagazine.com/articles/view/editorials/zeropunctuation/([-A-Za-z0-9]+))']; - - bless($self, $class); - $self->_prepare_parameters(); - - return $self; + my $self = $class->SUPER::new( + NAME => 'zeropunctuation', + _SELFTESTURL => 'http://www.escapistmagazine.com/videos/view/zero-punctuation/5346-Amy', + _SELFTESTTITLE =>'Amy', + PATTERNS => ['(http://www.escapistmagazine.com/videos/view/zero-punctuation/([-A-Za-z0-9]+))'], + @_, + ); + + return bless($self, $class); } sub _parse { @@ -34,6 +35,9 @@ sub _parse { my $metadata = {}; my $p; my $e; + my $j; + my $jsp; + my $r; $url =~ m|$pattern|; $url = $1; @@ -52,16 +56,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; } }