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