Youtube: new video formats, 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 LWP::Simple qw(!get);
12 use XML::Simple;
13 use Data::Dumper;
14
15 use strict;
16
17 sub new {
18     my $class = shift;
19     my $self = $class->SUPER::new();
20
21     $self->{'NAME'} = 'spikedhumor';
22     $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*spikedhumor.com/articles/(\d+)(?:/.*)*)'];
23
24     bless($self, $class);
25     $self->_prepare_parameters();
26
27     return $self;
28 }
29
30 sub _parse {
31     my $self = shift;
32     my $url = shift;
33     my $pattern = shift;
34     my $content;
35     my $metadata = {};
36     my $p = XML::Simple->new();
37     my $t;
38
39     $url =~ m|$pattern|;
40     $url = $1;
41
42     $metadata->{'URL'} = $url;
43     $metadata->{'ID'} = $2;
44     $metadata->{'TYPE'} = 'video';
45     $metadata->{'SOURCE'} = $self->{'NAME'};
46     $metadata->{'TITLE'} = undef;
47     $metadata->{'DLURL'} = undef;
48
49     # Get the XML file containing the video metadata
50     unless(defined($content = LWP::Simple::get(sprintf('http://www.spikedhumor.com/playxml/%s/data.xml', $2)))) {
51         $self->error('Could not download XML metadata');
52         return undef;
53     }
54
55     unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
56         $self->error('Could not parse XML metadata');
57         return undef;
58     }
59
60     $metadata->{'DLURL'} = $t->{'playlist'}->{'listitem'}->{'url'};
61     $metadata->{'TITLE'} = $t->{'playlist'}->{'listitem'}->{'name'};
62
63     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
64         $self->error('Could not extract download URL and title');
65         return undef;
66     }
67
68     return $metadata;
69 }
70
71 1;