From 6ca5e9acaa584df9a29c91d42de1e0fceb036b02 Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Sat, 6 Dec 2008 15:37:42 +0100 Subject: [PATCH] - Convert SnotrGrabber and CollegeHumorGrabber to HTMLHelper --- videosite/CollegeHumorGrabber.pm | 23 +++++++---------------- videosite/SnotrGrabber.pm | 28 +++++++--------------------- 2 files changed, 14 insertions(+), 37 deletions(-) diff --git a/videosite/CollegeHumorGrabber.pm b/videosite/CollegeHumorGrabber.pm index b25043c..4388a31 100644 --- a/videosite/CollegeHumorGrabber.pm +++ b/videosite/CollegeHumorGrabber.pm @@ -8,9 +8,9 @@ package CollegeHumorGrabber; use GrabberBase; @ISA = qw(GrabberBase); +use HTMLHelper; use LWP::Simple qw(!get); use XML::Simple; -use HTML::Parser; use Data::Dumper; use strict; @@ -64,24 +64,15 @@ sub _parse { # 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. - unless(defined($content = LWP::Simple::get(sprintf('http://www.collegehumor.com/video:%s', $2)))) { + $p = HTMLHelper->new(); + unless(defined($content = $p->load(sprintf('http://www.collegehumor.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'}; - } - } + + $t = $p->findnodes('meta[@name="title"]'); + if (defined($t)) { + $metadata->{'TITLE'} = $t->{'content'}; } unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { diff --git a/videosite/SnotrGrabber.pm b/videosite/SnotrGrabber.pm index f5acf3d..3e40ff6 100644 --- a/videosite/SnotrGrabber.pm +++ b/videosite/SnotrGrabber.pm @@ -8,8 +8,7 @@ package SnotrGrabber; use GrabberBase; @ISA = qw(GrabberBase); -use LWP::Simple qw(!get); -use HTML::Parser; +use HTMLHelper; use Data::Dumper; use strict; @@ -33,9 +32,8 @@ sub _parse { my $pattern = shift; my $content; my $metadata = {}; - my $p; - my $t; - my @accum; + my $p = HTMLHelper->new(); + my $n; $url =~ m|$pattern|; $url = $1; @@ -48,26 +46,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[@name="title"]'); + if (defined($n)) { + $metadata->{'TITLE'} = $n->{'content'}; } # The actual video URL is insultingly simple. -- 1.8.3.1