1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package videosite::BlipTVGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
21 my $self = $class->SUPER::new();
23 $self->{'NAME'} = 'bliptv';
24 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/file/(\d+)(?:\?\S+)?)',
25 '(http://blip\.tv/play/(\w+)$)'];
28 $self->_prepare_parameters();
39 my $p = HTML::Parser->new(api_version => 3);
49 $metadata->{'URL'} = $url;
50 $metadata->{'ID'} = $2;
51 $metadata->{'TYPE'} = 'video';
52 $metadata->{'SOURCE'} = $self->{"NAME"};
53 $metadata->{'TITLE'} = undef;
54 $metadata->{'DLURL'} = undef;
56 if ($pattern eq $self->{'PATTERNS'}->[0]) {
57 # blip.tv/file pattern
58 unless(defined($content = $self->simple_get(sprintf('http://blip.tv/file/%s', $2), $ua))) {
59 $self->error('Could not download page');
63 $p->handler(start => \@accum, "tagname, attr");
64 $p->handler(text => \@text, "text");
65 $p->report_tags(qw(script));
69 # Look for the post id in the javascript code
71 if ($e->[0] =~ m|player.setPostsId\((\d+)\)|s) {
75 } elsif ($pattern eq $self->{'PATTERNS'}->[1]) {
80 $r = $ua->get(sprintf('http://blip.tv/play/%s', $2));
83 $self->error('Could not download page');
86 unless($r->is_redirect()) {
87 $self->error('Expected redirect, but got none');
90 $u = URI->new($r->header('Location'));
91 $u = $u->query_param("file");
94 $self->error('Did not find file parameter in URL');
97 $u =~ m|^http://blip.tv/rss/flash/(\d+)$|;
101 $self->error("Don't know how to handle that pattern yet");
105 unless(defined($xml)) {
106 $self->error("Could not find post id");
110 # Download the XML file containing the stream information
111 $ua->max_redirect(7);
112 unless(defined($content = $self->simple_get(sprintf('http://blip.tv/rss/flash/%s', $xml), $ua))) {
113 $self->error('Could not download XML metadata');
117 $xml = XML::Simple::XMLin($content, KeepRoot => 1);
118 $metadata->{'DLURL'} = $xml->{'rss'}->{'channel'}->{'item'}->{'enclosure'}->{'url'};
119 $metadata->{'TITLE'} = $xml->{'rss'}->{'channel'}->{'item'}->{'media:title'};
121 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
122 $self->error('Could not determine download URL');