1 package CollegeHumorGrabber;
4 @ISA = qw(GrabberBase);
6 use LWP::Simple qw(!get);
14 my $self = $class->SUPER::new();
16 $self->{'NAME'} = 'collegehumor';
17 $self->{'PATTERNS'} = ['(http://www.collegehumor.com/video:(\d+))'];
20 $self->_prepare_parameters();
31 my $p = XML::Simple->new();
37 $metadata->{'URL'} = $url;
38 $metadata->{'ID'} = $2;
39 $metadata->{'TYPE'} = 'video';
40 $metadata->{'SOURCE'} = 'collegehumor';
41 $metadata->{'TITLE'} = undef;
42 $metadata->{'DLURL'} = undef;
44 # Get the XML file containing the video metadata
45 unless(defined($content = LWP::Simple::get(sprintf('http://www.collegehumor.com/moogaloop/video:%s', $2)))) {
46 $self->error('Could not download XML metadata');
50 unless(defined($t = $p->XMLin($content))) {
51 $self->error('Could not parse XML metadata');
55 $metadata->{'DLURL'} = $t->{'video'}->{'file'};
56 $metadata->{'TITLE'} = $t->{'video'}->{'caption'};
58 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
59 $self->error('Could not extract download URL and title');