X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FBlipTVGrabber.pm;h=86084dd992c74bf9a5c3be091854c6f8670a44aa;hb=13d23a6f19e2f8192d894171aaecc7987044a72a;hp=64be25292245ac9ae9fc7b15e0ecdcc5779ffdbf;hpb=883ff3d3455dd5c4a1b9ce1a72f8482a80f6eeee;p=videosite.git diff --git a/videosite/BlipTVGrabber.pm b/videosite/BlipTVGrabber.pm index 64be252..86084dd 100644 --- a/videosite/BlipTVGrabber.pm +++ b/videosite/BlipTVGrabber.pm @@ -3,16 +3,12 @@ # # Grabber for blip.tv -package BlipTVGrabber; +package videosite::BlipTVGrabber; -use GrabberBase; -@ISA = qw(GrabberBase); +use videosite::GrabberBase; +@ISA = qw(videosite::GrabberBase); -use LWP::Simple qw(!get); -use LWP::UserAgent; -use URI; -use URI::QueryParam; -use HTML::Parser; +use HTML::TokeParser; use XML::Simple; use Data::Dumper; @@ -20,16 +16,15 @@ use strict; sub new { my $class = shift; - my $self = $class->SUPER::new(); - - $self->{'NAME'} = 'bliptv'; - $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/file/(\d+)(?:\?\S+)?)', - '(http://blip\.tv/play/(\w+)$)']; - - bless($self, $class); - $self->_prepare_parameters(); - - return $self; + 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 { @@ -38,86 +33,55 @@ sub _parse { my $pattern = shift; my $content; my $metadata = {}; - my $p = HTML::Parser->new(api_version => 3); - my @accum; - my @text; - my $e; + my $p; + my $tag; my $xml = undef; - my $ua; + my $ua = $self->ua(); $url =~ m|$pattern|; $url = $1; $metadata->{'URL'} = $url; - $metadata->{'ID'} = $2; $metadata->{'TYPE'} = 'video'; $metadata->{'SOURCE'} = $self->{"NAME"}; + $metadata->{'ID'} = undef; $metadata->{'TITLE'} = undef; $metadata->{'DLURL'} = undef; - if ($pattern eq $self->{'PATTERNS'}->[0]) { - # blip.tv/file pattern - unless(defined($content = LWP::Simple::get(sprintf('http://blip.tv/file/%s', $2)))) { - $self->error('Could not download page'); - return undef; - } - - $p->handler(start => \@accum, "tagname, attr"); - $p->handler(text => \@text, "text"); - $p->report_tags(qw(script)); - $p->utf8_mode(1); - $p->parse($content); - - # Look for the post id in the javascript code - foreach $e (@text) { - if ($e->[0] =~ m|player.setPostsId\((\d+)\)|s) { - $xml = $1; - } - } - } elsif ($pattern eq $self->{'PATTERNS'}->[1]) { - my $r; - my $u; - - $ua = LWP::UserAgent->new(max_redirect => 0); - $r = $ua->get(sprintf('http://blip.tv/play/%s', $2)); + unless(defined($content = $self->simple_get($url, $ua))) { + $self->error('Could not download page'); + return undef; + } - unless(defined($r)) { - $self->error('Could not download page'); - return undef; - } - unless($r->is_redirect()) { - $self->error('Expected redirect, but got none'); - return undef; - } - $u = URI->new($r->header('Location')); - $u = $u->query_param("file"); + $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')) { - unless(defined($u)) { - $self->error('Did not find file parameter in URL'); - return undef; + $xml = $tag->[1]->{'href'}; + $self->debug("Found RSS link: %s", $xml); } - $u =~ m|^http://blip.tv/rss/flash/(\d+)$|; - $xml = $1; - - } else { - $self->error("Don't know how to handle that pattern yet"); - return undef; } - unless(defined($xml)) { - $self->error("Could not find post id"); + unless(defined($xml)) { + $self->error("Could not find RSS link"); return undef; } # Download the XML file containing the stream information - unless(defined($content = LWP::Simple::get(sprintf('http://blip.tv/rss/flash/%s', $xml)))) { + $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'}->{'media:title'}; + $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');