X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FBlipTVGrabber.pm;h=5a53d2c1308d22077fae244a17fb2c078581cfdf;hb=fd6d5b9e60563c5146e8cf7a0e286fc4aa8718c9;hp=1b2349db357583f4da04db5935ebe20d39746764;hpb=0c3d27aee3c4c637cb336c739c25c96ca260f067;p=videosite.git diff --git a/videosite/BlipTVGrabber.pm b/videosite/BlipTVGrabber.pm index 1b2349d..5a53d2c 100644 --- a/videosite/BlipTVGrabber.pm +++ b/videosite/BlipTVGrabber.pm @@ -3,12 +3,15 @@ # # 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 XML::Simple; use Data::Dumper; @@ -20,7 +23,8 @@ sub new { my $self = $class->SUPER::new(); $self->{'NAME'} = 'bliptv'; - $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/file/(\d+)(?:\?\S+)?)']; + $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/file/(\d+)(?:\?\S+)?)', + '(http://blip\.tv/play/(\w+)$)']; bless($self, $class); $self->_prepare_parameters(); @@ -39,6 +43,7 @@ sub _parse { my @text; my $e; my $xml = undef; + my $ua; $url =~ m|$pattern|; $url = $1; @@ -50,22 +55,53 @@ sub _parse { $metadata->{'TITLE'} = undef; $metadata->{'DLURL'} = undef; - unless(defined($content = LWP::Simple::get(sprintf('http://blip.tv/file/%s', $2)))) { - $self->error('Could not download page'); - return 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; - $p->handler(start => \@accum, "tagname, attr"); - $p->handler(text => \@text, "text"); - $p->report_tags(qw(script)); - $p->utf8_mode(1); - $p->parse($content); + $ua = LWP::UserAgent->new(max_redirect => 0); + $r = $ua->get(sprintf('http://blip.tv/play/%s', $2)); - # Look for the post id in the javascript code - foreach $e (@text) { - if ($e->[0] =~ m|player.setPostsId\((\d+)\)|s) { - $xml = $1; + 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"); + + unless(defined($u)) { + $self->error('Did not find file parameter in URL'); + return undef; + } + $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)) {