#
# 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 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 $metadata = {};
my $p = HTML::Parser->new(api_version => 3);
my @accum;
+ my @text;
my $e;
my $xml = undef;
+ my $ua = $self->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 = $self->simple_get(sprintf('http://blip.tv/file/%s', $2), $ua))) {
+ $self->error('Could not download page');
+ return undef;
+ }
- $p->handler(start => \@accum, "tagname, attr");
- $p->report_tags(qw(div));
- $p->utf8_mode(1);
- $p->parse($content);
+ $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 div tags
- foreach $e (@accum) {
- if (exists($e->[1]->{'pokkariparameters'})) {
- if ($e->[1]->{'pokkariparameters'} =~ m|posts_id:"(\d+)"|) {
+ # 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->max_redirect(0);
+ $r = $ua->get(sprintf('http://blip.tv/play/%s', $2));
+
+ 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)) {
}
# 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/rss/flash/%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'}->{'media:group'}->{'media:content'}->{'url'};
+ $metadata->{'DLURL'} = $xml->{'rss'}->{'channel'}->{'item'}->{'enclosure'}->{'url'};
$metadata->{'TITLE'} = $xml->{'rss'}->{'channel'}->{'item'}->{'media:title'};
unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {