VimeoGrabber: rework to new site layout
[videosite.git] / videosite / SnotrGrabber.pm
index f5acf3d..3009995 100644 (file)
@@ -3,13 +3,12 @@
 #
 # Grabber for snotr.com
 
-package SnotrGrabber;
+package videosite::SnotrGrabber;
 
-use GrabberBase;
-@ISA = qw(GrabberBase);
+use videosite::GrabberBase;
+@ISA = qw(videosite::GrabberBase);
 
-use LWP::Simple qw(!get);
-use HTML::Parser;
+use videosite::HTMLHelper;
 use Data::Dumper;
 
 use strict;
@@ -19,6 +18,8 @@ sub new {
     my $self = $class->SUPER::new();
 
     $self->{'NAME'} = 'snotr';
+    $self->{_SELFTESTURL} = 'http://www.snotr.com/video/1836';
+    $self->{_SELFTESTTITLE} = 'Brilliant thief';
     $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*snotr\.com/video/(\d+))'];
 
     bless($self, $class);
@@ -33,9 +34,8 @@ sub _parse {
     my $pattern = shift;
     my $content;
     my $metadata = {};
-    my $p;
-    my $t;
-    my @accum;
+    my $p = videosite::HTMLHelper->new();
+    my $n;
 
     $url =~ m|$pattern|;
     $url = $1;
@@ -48,26 +48,14 @@ sub _parse {
     $metadata->{'DLURL'} = undef;
 
     # Get the HTML file containing the title
-    unless(defined($content = LWP::Simple::get(sprintf('http://www.snotr.com/video/%s', $2)))) {
+    unless(defined($p->load(sprintf('http://www.snotr.com/video/%s', $2)))) {
         $self->error('Could not download HTML');
         return undef;
     }
 
-    $p = HTML::Parser->new(api_version => 3);
-
-    $p->handler(start => \@accum, "tagname, attr");
-    $p->report_tags(qw(meta));
-    $p->utf8_mode(1);
-    $p->parse($content);
-
-    # Look for the title in the meta tags
-    foreach $t (@accum) {
-        if ('meta' eq $t->[0]) {
-            if (exists($t->[1]->{'name'}) and ('title' eq $t->[1]->{'name'})) {
-                $metadata->{'TITLE'} = $t->[1]->{'content'};
-                last;
-            }
-        }
+    $n = $p->findnodes('meta[@property="og:title"]');
+    if (defined($n)) {
+        $metadata->{'TITLE'} = $n->{'content'};
     }
 
     # The actual video URL is insultingly simple.