# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for spikedhumor.com package videosite::SpikedHumorGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use XML::Simple; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'spikedhumor', PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*spikedhumor.com/articles/(\d+)(?:/.*)*)'], @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p = XML::Simple->new(); my $t; $url =~ m|$pattern|; $url = $1; $metadata->{'URL'} = $url; $metadata->{'ID'} = $2; $metadata->{'TYPE'} = 'video'; $metadata->{'SOURCE'} = $self->{'NAME'}; $metadata->{'TITLE'} = undef; $metadata->{'DLURL'} = undef; # Get the XML file containing the video metadata unless(defined($content = $self->simple_get(sprintf('http://www.spikedhumor.com/playxml/%s/data.xml', $2)))) { $self->error('Could not download XML metadata'); return undef; } unless(defined($t = $p->XMLin($content, KeepRoot => 1))) { $self->error('Could not parse XML metadata'); return undef; } $metadata->{'DLURL'} = $t->{'playlist'}->{'listitem'}->{'url'}; $metadata->{'TITLE'} = $t->{'playlist'}->{'listitem'}->{'name'}; unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { $self->error('Could not extract download URL and title'); return undef; } return $metadata; } 1;