@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;
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();
my @text;
my $e;
my $xml = undef;
+ my $ua;
$url =~ m|$pattern|;
$url = $1;
$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)) {