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);
19 my $self = $class->SUPER::new(
21 PATTERNS => ['(http://video\.yahoo\.com/watch/\d+/(\d+))'],
25 return bless($self, $class);
34 my $p = XML::Simple->new();
42 $metadata->{'URL'} = $url;
43 $metadata->{'ID'} = $2;
44 $metadata->{'TYPE'} = 'video';
45 $metadata->{'SOURCE'} = $self->{'NAME'};
46 $metadata->{'TITLE'} = undef;
47 $metadata->{'DLURL'} = undef;
49 # Get the XML file containing the video metadata
50 unless(defined($content = $self->simple_get(sprintf('http://cosmos.bcst.yahoo.com/up/yep/process/getPlaylistFOP.php?node_id=%s', $2), $ua))) {
51 $self->error('Could not download XML metadata');
55 # There is no XML header in the data, which makes XML::Simple unhappy
56 $content = '<?xml version="1.0" encoding="UTF-8"?>' . $content;
58 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
59 $self->error('Could not parse XML metadata');
63 $metadata->{'DLURL'} = $t->{'DATA'}->{'SEQUENCE-ITEM'}->{'STREAM'}->{'APP'} . $t->{'DATA'}->{'SEQUENCE-ITEM'}->{'STREAM'}->{'FULLPATH'};
64 $metadata->{'DLURL'} =~ s/\&/\&/g;
66 # The XML does not contain the title of the video, for
67 # reasons possibly known to some jerk at yahoo.
68 # So we'll have to parse the actual HTML, too.
69 unless(defined($content = $self->simple_get($url, $ua))) {
70 $self->error('Could not download HTML');
73 $p = HTML::Parser->new(api_version => 3);
75 $p->handler(start => \@accum, "tagname, attr");
76 $p->report_tags(qw(meta));
80 # Look for the title in the meta tags
82 if ('meta' eq $t->[0]) {
83 if (exists($t->[1]->{'name'}) and ('title' eq $t->[1]->{'name'})) {
84 $metadata->{'TITLE'} = $t->[1]->{'content'};
90 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
91 $self->error('Could not extract download URL and title');