1 # (c) 2008 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for video.yahoo.com
6 package videosite::YahooGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'yahoo';
23 $self->{'PATTERNS'} = ['(http://video\.yahoo\.com/watch/\d+/(\d+))'];
26 $self->_prepare_parameters();
37 my $p = XML::Simple->new();
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'video';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'TITLE'} = undef;
49 $metadata->{'DLURL'} = undef;
51 # Get the XML file containing the video metadata
52 unless(defined($content = LWP::Simple::get(sprintf('http://cosmos.bcst.yahoo.com/up/yep/process/getPlaylistFOP.php?node_id=%s', $2)))) {
53 $self->error('Could not download XML metadata');
57 # There is no XML header in the data, which makes XML::Simple unhappy
58 $content = '<?xml version="1.0" encoding="UTF-8"?>' . $content;
60 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
61 $self->error('Could not parse XML metadata');
65 $metadata->{'DLURL'} = $t->{'DATA'}->{'SEQUENCE-ITEM'}->{'STREAM'}->{'APP'} . $t->{'DATA'}->{'SEQUENCE-ITEM'}->{'STREAM'}->{'FULLPATH'};
66 $metadata->{'DLURL'} =~ s/\&/\&/g;
68 # The XML does not contain the title of the video, for
69 # reasons possibly known to some jerk at yahoo.
70 # So we'll have to parse the actual HTML, too.
71 unless(defined($content = LWP::Simple::get($url))) {
72 $self->error('Could not download HTML');
75 $p = HTML::Parser->new(api_version => 3);
77 $p->handler(start => \@accum, "tagname, attr");
78 $p->report_tags(qw(meta));
82 # Look for the title in the meta tags
84 if ('meta' eq $t->[0]) {
85 if (exists($t->[1]->{'name'}) and ('title' eq $t->[1]->{'name'})) {
86 $metadata->{'TITLE'} = $t->[1]->{'content'};
92 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
93 $self->error('Could not extract download URL and title');