root/trunk/plagger/lib/Plagger/Plugin/Namespace/MediaRSS.pm

Revision 1905 (checked in by miyagawa, 2 years ago)

test Media RSS URL with and without the trailing slash. Ugh

Line 
1 package Plagger::Plugin::Namespace::MediaRSS;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 sub register {
6     my($self, $context) = @_;
7     $context->register_hook(
8         $self,
9         'aggregator.entry.fixup' => \&handle,
10     );
11 }
12
13 sub handle {
14     my($self, $context, $args) = @_;
15
16     # Ick, I need to try the URL with and without the trailing slash
17     for my $media_ns ("http://search.yahoo.com/mrss", "http://search.yahoo.com/mrss/") {
18         my $media = $args->{orig_entry}->{entry}->{$media_ns}->{group} || $args->{orig_entry}->{entry};
19         my $content = $media->{$media_ns}->{content} || [];
20         $content = [ $content ] unless ref $content && ref $content eq 'ARRAY';
21
22         for my $media_content (@{$content}) {
23             my $enclosure = Plagger::Enclosure->new;
24             $enclosure->url( URI->new($media_content->{url}) );
25             $enclosure->auto_set_type($media_content->{type});
26             $args->{entry}->add_enclosure($enclosure);
27         }
28
29         if (my $thumbnail = $media->{$media_ns}->{thumbnail}) {
30             $args->{entry}->icon({
31                 url   => $thumbnail->{url},
32                 width => $thumbnail->{width},
33                 height => $thumbnail->{height},
34             });
35         }
36     }
37
38     1;
39 }
40
41 1;
42 __END__
43
44 =head1 NAME
45
46 Plagger::Plugin::Namespace::MediaRSS - Media RSS extension
47
48 =head1 SYNOPSIS
49
50   - module: Namespace::MediaRSS
51
52 =head1 DESCRIPTION
53
54 This plugin parses Media RSS extension in the feeds and stores media
55 information to entry enclosures. This plugin is loaded by default.
56
57 =head1 AUTHOR
58
59 Tatsuhiko Miyagawa
60
61 =head1 SEE ALSO
62
63 L<Plagger>, L<http://search.yahoo.com/mrss>
64
65 =cut
Note: See TracBrowser for help on using the browser.