From: Ralf Ertzinger Date: Sat, 19 Jul 2008 13:54:13 +0000 (+0200) Subject: - Handle blip.tv/play style URLs X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=commitdiff_plain;h=883ff3d3455dd5c4a1b9ce1a72f8482a80f6eeee;p=videosite.git - Handle blip.tv/play style URLs --- diff --git a/videosite/BlipTVGrabber.pm b/videosite/BlipTVGrabber.pm index 1b2349d..64be252 100644 --- a/videosite/BlipTVGrabber.pm +++ b/videosite/BlipTVGrabber.pm @@ -9,6 +9,9 @@ use GrabberBase; @ISA = qw(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)) {