From 30f552e063c63e7b8452f239910e490cd37580cb Mon Sep 17 00:00:00 2001 From: Ralf Ertzinger Date: Sun, 30 Nov 2008 21:03:37 +0100 Subject: [PATCH] - Add grabber for snotr.com --- videosite/SnotrGrabber.pm | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 videosite/SnotrGrabber.pm diff --git a/videosite/SnotrGrabber.pm b/videosite/SnotrGrabber.pm new file mode 100644 index 0000000..f5acf3d --- /dev/null +++ b/videosite/SnotrGrabber.pm @@ -0,0 +1,84 @@ +# (c) 2008 by Ralf Ertzinger +# licensed under GNU GPL v2 +# +# Grabber for snotr.com + +package SnotrGrabber; + +use GrabberBase; +@ISA = qw(GrabberBase); + +use LWP::Simple qw(!get); +use HTML::Parser; +use Data::Dumper; + +use strict; + +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + + $self->{'NAME'} = 'snotr'; + $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*snotr\.com/video/(\d+))']; + + bless($self, $class); + $self->_prepare_parameters(); + + return $self; +} + +sub _parse { + my $self = shift; + my $url = shift; + my $pattern = shift; + my $content; + my $metadata = {}; + my $p; + my $t; + my @accum; + + $url =~ m|$pattern|; + $url = $1; + + $metadata->{'URL'} = $url; + $metadata->{'ID'} = $2; + $metadata->{'TYPE'} = 'video'; + $metadata->{'SOURCE'} = $self->{'NAME'}; + $metadata->{'TITLE'} = undef; + $metadata->{'DLURL'} = undef; + + # Get the HTML file containing the title + unless(defined($content = LWP::Simple::get(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; + } + } + } + + # The actual video URL is insultingly simple. + $metadata->{'DLURL'} = sprintf('http://videos.snotr.com/%s.flv', $metadata->{'ID'}); + + unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { + $self->error('Could not extract download URL and title'); + return undef; + } + + return $metadata; +} + +1; -- 1.8.3.1