1 package YouTubeGrabber;
4 @ISA = qw(GrabberBase);
6 use LWP::Simple qw(!get);
14 my $self = $class->SUPER::new();
16 $self->{'NAME'} = 'youtube';
17 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*youtube.(?:com|de|co.uk)/watch\?(?:.+=.+&)*v=([-a-zA-Z0-9_]+))',
18 '(http://(?:[-a-zA-Z0-9_.]+\.)*youtube.(?:com|de|co.uk)/v/([-a-zA-Z0-9_]+))'];
21 $self->_prepare_parameters();
32 my $p = HTML::Parser->new(api_version => 3);
40 $metadata->{'URL'} = $url;
41 $metadata->{'ID'} = $2;
42 $metadata->{'TYPE'} = 'youtube';
43 $metadata->{'TITLE'} = undef;
44 $metadata->{'DLURL'} = undef;
46 unless(defined($content = LWP::Simple::get(sprintf('http://youtube.com/watch?v=%s', $2)))) {
47 $self->error('Could not download %s', $url);
51 $p->handler(start => \@accum, "tagname, attr");
52 $p->handler(text => \@text, "text");
53 $p->report_tags(qw(meta script));
57 # Look for the title in the meta tags
59 if ('meta' eq $e->[0]) {
60 if ('title' eq $e->[1]->{'name'}) {
61 $metadata->{'TITLE'} = $e->[1]->{'content'};
66 # Look for the download URL
68 if ($e->[0] =~ m|/watch_fullscreen\?(.*)\&fs|) {
69 $metadata->{'DLURL'} = 'http://www.youtube.com/get_video.php?' . $1;
73 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
74 $self->error('Could not determine download URL');