1 # Grabber for collegehumor.com
3 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
6 package CollegeHumorGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'collegehumor';
23 $self->{'PATTERNS'} = ['(http://www.collegehumor.com/video:(\d+))'];
26 $self->_prepare_parameters();
37 my $p = XML::Simple->new();
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'video';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'TITLE'} = undef;
49 $metadata->{'DLURL'} = undef;
51 # Get the XML file containing the video metadata
52 unless(defined($content = LWP::Simple::get(sprintf('http://www.collegehumor.com/moogaloop/video:%s', $2)))) {
53 $self->error('Could not download XML metadata');
57 unless(defined($t = $p->XMLin($content))) {
58 $self->error('Could not parse XML metadata');
62 $metadata->{'DLURL'} = $t->{'video'}->{'file'};
64 # The XML does not contain the full title of the video, for
65 # reasons possibly known to some jerk at CollegeHumor.
66 # So we'll have to parse the actual HTML, too.
67 unless(defined($content = LWP::Simple::get(sprintf('http://www.collegehumor.com/video:%s', $2)))) {
68 $self->error('Could not download HTML');
71 $p = HTML::Parser->new(api_version => 3);
73 $p->handler(start => \@accum, "tagname, attr");
74 $p->report_tags(qw(meta));
78 # Look for the title in the meta tags
80 if ('meta' eq $t->[0]) {
81 if (exists($t->[1]->{'name'}) and ('title' eq $t->[1]->{'name'})) {
82 $metadata->{'TITLE'} = $t->[1]->{'content'};
87 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
88 $self->error('Could not extract download URL and title');