Youtube: Add video format 44 and 45 (also WebM)
[videosite.git] / videosite / CollegeHumorGrabber.pm
index 9fdb87e..bbf54a6 100644 (file)
@@ -1,8 +1,14 @@
-package CollegeHumorGrabber;
+# Grabber for collegehumor.com
+#
+# (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
+# licensed under GNU GPL v2
 
-use GrabberBase;
-@ISA = qw(GrabberBase);
+package videosite::CollegeHumorGrabber;
 
+use videosite::GrabberBase;
+@ISA = qw(videosite::GrabberBase);
+
+use videosite::HTMLHelper;
 use LWP::Simple qw(!get);
 use XML::Simple;
 use Data::Dumper;
@@ -29,6 +35,7 @@ sub _parse {
     my $content;
     my $metadata = {};
     my $p = XML::Simple->new();
+    my @accum;
     my $t;
 
     $url =~ m|$pattern|;
@@ -36,7 +43,8 @@ sub _parse {
 
     $metadata->{'URL'} = $url;
     $metadata->{'ID'} = $2;
-    $metadata->{'TYPE'} = 'collegehumor';
+    $metadata->{'TYPE'} = 'video';
+    $metadata->{'SOURCE'} = $self->{'NAME'};
     $metadata->{'TITLE'} = undef;
     $metadata->{'DLURL'} = undef;
 
@@ -52,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');