Youtube: Add video format 44 and 45 (also WebM)
[videosite.git] / videosite / CollegeHumorGrabber.pm
index 546e669..bbf54a6 100644 (file)
@@ -3,11 +3,12 @@
 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
 # licensed under GNU GPL v2
 
-package CollegeHumorGrabber;
+package videosite::CollegeHumorGrabber;
 
-use GrabberBase;
-@ISA = qw(GrabberBase);
+use videosite::GrabberBase;
+@ISA = qw(videosite::GrabberBase);
 
+use videosite::HTMLHelper;
 use LWP::Simple qw(!get);
 use XML::Simple;
 use Data::Dumper;
@@ -34,6 +35,7 @@ sub _parse {
     my $content;
     my $metadata = {};
     my $p = XML::Simple->new();
+    my @accum;
     my $t;
 
     $url =~ m|$pattern|;
@@ -58,7 +60,20 @@ sub _parse {
     }
 
     $metadata->{'DLURL'} = $t->{'video'}->{'file'};
-    $metadata->{'TITLE'} = $t->{'video'}->{'caption'};
+
+    # The XML does not contain the full title of the video, for
+    # reasons possibly known to some jerk at CollegeHumor.
+    # So we'll have to parse the actual HTML, too.
+    $p = videosite::HTMLHelper->new();
+    unless(defined($content = $p->load(sprintf('http://www.collegehumor.com/video:%s', $2)))) {
+        $self->error('Could not download HTML');
+        return undef;
+    }
+
+    $t = $p->findnodes('h1[@id="item_title"]');
+    if (defined($t)) {
+        $metadata->{'TITLE'} = $t->{'_content'}->[0];
+    }
 
     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
         $self->error('Could not extract download URL and title');