#
# Grabber for www.escapistmagazine.com/articles/view/editorials/zeropunctuation
-package ZeroPunctuationGrabber;
+package videosite::ZeroPunctuationGrabber;
-use GrabberBase;
-@ISA = qw(GrabberBase);
+use videosite::GrabberBase;
+@ISA = qw(videosite::GrabberBase);
-use LWP::Simple qw(!get);
use HTML::TokeParser;
use Data::Dumper;
+use videosite::JSArrayParser;
use strict;
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();
my $metadata = {};
my $p;
my $e;
+ my $j;
+ my $jsp;
+ my $r;
$url =~ m|$pattern|;
$url = $1;
$metadata->{'TITLE'} = undef;
$metadata->{'DLURL'} = undef;
- unless(defined($content = LWP::Simple::get($url))) {
+ unless(defined($content = $self->simple_get($url))) {
$self->error('Could not download %s', $url);
return undef;
}
$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;
}
}