Youtube: remove old matching code
[videosite.git] / videosite / BlipTVGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for blip.tv
5
6 package videosite::BlipTVGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use HTML::TokeParser;
12 use XML::Simple;
13 use Data::Dumper;
14
15 use strict;
16
17 sub new {
18     my $class = shift;
19     my $self = $class->SUPER::new();
20
21     $self->{'NAME'} = 'bliptv';
22     $self->{_SELFTESTURL} = 'http://blip.tv/rebelliouspixelscom/buffy-vs-edward-twilight-remixed-2274024';
23     $self->{_SELFTESTTITLE} = 'Buffy vs Edward (Twilight Remixed)';
24     $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*blip.tv/\S+/\S+)'];
25
26     bless($self, $class);
27     $self->_prepare_parameters();
28
29     return $self;
30 }
31
32 sub _parse {
33     my $self = shift;
34     my $url = shift;
35     my $pattern = shift;
36     my $content;
37     my $metadata = {};
38     my $p;
39     my $tag;
40     my $xml = undef;
41     my $ua = $self->ua();
42
43     $url =~ m|$pattern|;
44     $url = $1;
45
46     $metadata->{'URL'} = $url;
47     $metadata->{'TYPE'} = 'video';
48     $metadata->{'SOURCE'} = $self->{"NAME"};
49     $metadata->{'ID'} = undef;
50     $metadata->{'TITLE'} = undef;
51     $metadata->{'DLURL'} = undef;
52
53     unless(defined($content = $self->simple_get($url, $ua))) {
54         $self->error('Could not download page');
55         return undef;
56     }
57
58     $p = HTML::TokeParser->new(\$content);
59     while ($tag = $p->get_tag('link')) {
60         if (($tag->[0] eq 'link') and
61             exists($tag->[1]->{'rel'}) and
62             ($tag->[1]->{'rel'} eq 'alternate') and
63             exists($tag->[1]->{'type'}) and
64             ($tag->[1]->{'type'} eq 'application/rss+xml')) {
65
66             $xml = $tag->[1]->{'href'};
67             $self->debug("Found RSS link: %s", $xml);
68         }
69     }
70
71     unless(defined($xml)) {
72         $self->error("Could not find RSS link");
73         return undef;
74     }
75
76     # Download the XML file containing the stream information
77     $ua->max_redirect(7);
78     unless(defined($content = $self->simple_get(sprintf('http://blip.tv%s', $xml), $ua))) {
79         $self->error('Could not download XML metadata');
80         return undef;
81     }
82
83     $xml = XML::Simple::XMLin($content, KeepRoot => 1);
84     $metadata->{'DLURL'} = $xml->{'rss'}->{'channel'}->{'item'}->{'enclosure'}->{'url'};
85     $metadata->{'TITLE'} = $xml->{'rss'}->{'channel'}->{'item'}->{'title'};
86     $metadata->{'ID'} = $xml->{'rss'}->{'channel'}->{'item'}->{'blip:posts_id'};
87
88     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
89         $self->error('Could not determine download URL');
90         return undef;
91     }
92
93     return $metadata;
94 }
95
96 1;