# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for blip.tv package videosite::BlipTVGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use HTML::TokeParser; use XML::Simple; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'bliptv', _SELFTESTURL => 'http://blip.tv/rebelliouspixelscom/buffy-vs-edward-twilight-remixed-2274024', _SELFTESTTITLE => 'Buffy vs Edward (Twilight Remixed)', PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/\S+/\S+)'], @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p; my $tag; my $xml = undef; my $ua = $self->ua(); $url =~ m|$pattern|; $url = $1; $metadata->{'URL'} = $url; $metadata->{'TYPE'} = 'video'; $metadata->{'SOURCE'} = $self->{"NAME"}; $metadata->{'ID'} = undef; $metadata->{'TITLE'} = undef; $metadata->{'DLURL'} = undef; unless(defined($content = $self->simple_get($url, $ua))) { $self->error('Could not download page'); return undef; } $p = HTML::TokeParser->new(\$content); while ($tag = $p->get_tag('link')) { if (($tag->[0] eq 'link') and exists($tag->[1]->{'rel'}) and ($tag->[1]->{'rel'} eq 'alternate') and exists($tag->[1]->{'type'}) and ($tag->[1]->{'type'} eq 'application/rss+xml')) { $xml = $tag->[1]->{'href'}; $self->debug("Found RSS link: %s", $xml); } } unless(defined($xml)) { $self->error("Could not find RSS link"); return undef; } # Download the XML file containing the stream information $ua->max_redirect(7); unless(defined($content = $self->simple_get(sprintf('http://blip.tv%s', $xml), $ua))) { $self->error('Could not download XML metadata'); return undef; } $xml = XML::Simple::XMLin($content, KeepRoot => 1); $metadata->{'DLURL'} = $xml->{'rss'}->{'channel'}->{'item'}->{'enclosure'}->{'url'}; $metadata->{'TITLE'} = $xml->{'rss'}->{'channel'}->{'item'}->{'title'}; $metadata->{'ID'} = $xml->{'rss'}->{'channel'}->{'item'}->{'blip:posts_id'}; unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { $self->error('Could not determine download URL'); return undef; } return $metadata; } 1;