1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
23 my $self = $class->SUPER::new();
25 $self->{'NAME'} = 'bliptv';
26 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/file/(\d+)(?:\?\S+)?)',
27 '(http://blip\.tv/play/(\w+)$)'];
30 $self->_prepare_parameters();
41 my $p = HTML::Parser->new(api_version => 3);
51 $metadata->{'URL'} = $url;
52 $metadata->{'ID'} = $2;
53 $metadata->{'TYPE'} = 'video';
54 $metadata->{'SOURCE'} = $self->{"NAME"};
55 $metadata->{'TITLE'} = undef;
56 $metadata->{'DLURL'} = undef;
58 if ($pattern eq $self->{'PATTERNS'}->[0]) {
59 # blip.tv/file pattern
60 unless(defined($content = LWP::Simple::get(sprintf('http://blip.tv/file/%s', $2)))) {
61 $self->error('Could not download page');
65 $p->handler(start => \@accum, "tagname, attr");
66 $p->handler(text => \@text, "text");
67 $p->report_tags(qw(script));
71 # Look for the post id in the javascript code
73 if ($e->[0] =~ m|player.setPostsId\((\d+)\)|s) {
77 } elsif ($pattern eq $self->{'PATTERNS'}->[1]) {
81 $ua = LWP::UserAgent->new(max_redirect => 0);
82 $r = $ua->get(sprintf('http://blip.tv/play/%s', $2));
85 $self->error('Could not download page');
88 unless($r->is_redirect()) {
89 $self->error('Expected redirect, but got none');
92 $u = URI->new($r->header('Location'));
93 $u = $u->query_param("file");
96 $self->error('Did not find file parameter in URL');
99 $u =~ m|^http://blip.tv/rss/flash/(\d+)$|;
103 $self->error("Don't know how to handle that pattern yet");
107 unless(defined($xml)) {
108 $self->error("Could not find post id");
112 # Download the XML file containing the stream information
113 unless(defined($content = LWP::Simple::get(sprintf('http://blip.tv/rss/flash/%s', $xml)))) {
114 $self->error('Could not download XML metadata');
118 $xml = XML::Simple::XMLin($content, KeepRoot => 1);
119 $metadata->{'DLURL'} = $xml->{'rss'}->{'channel'}->{'item'}->{'enclosure'}->{'url'};
120 $metadata->{'TITLE'} = $xml->{'rss'}->{'channel'}->{'item'}->{'media:title'};
122 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
123 $self->error('Could not determine download URL');