fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / SpikedHumorGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for spikedhumor.com
5
6 package videosite::SpikedHumorGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use XML::Simple;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new(
19         NAME => 'spikedhumor',
20         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*spikedhumor.com/articles/(\d+)(?:/.*)*)'],
21         @_,
22     );
23
24     return bless($self, $class);
25 }
26
27 sub _parse {
28     my $self = shift;
29     my $url = shift;
30     my $pattern = shift;
31     my $content;
32     my $metadata = {};
33     my $p = XML::Simple->new();
34     my $t;
35
36     $url =~ m|$pattern|;
37     $url = $1;
38
39     $metadata->{'URL'} = $url;
40     $metadata->{'ID'} = $2;
41     $metadata->{'TYPE'} = 'video';
42     $metadata->{'SOURCE'} = $self->{'NAME'};
43     $metadata->{'TITLE'} = undef;
44     $metadata->{'DLURL'} = undef;
45
46     # Get the XML file containing the video metadata
47     unless(defined($content = $self->simple_get(sprintf('http://www.spikedhumor.com/playxml/%s/data.xml', $2)))) {
48         $self->error('Could not download XML metadata');
49         return undef;
50     }
51
52     unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
53         $self->error('Could not parse XML metadata');
54         return undef;
55     }
56
57     $metadata->{'DLURL'} = $t->{'playlist'}->{'listitem'}->{'url'};
58     $metadata->{'TITLE'} = $t->{'playlist'}->{'listitem'}->{'name'};
59
60     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
61         $self->error('Could not extract download URL and title');
62         return undef;
63     }
64
65     return $metadata;
66 }
67
68 1;