Plagger/Plugin/Namespace/MediaRSS.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 48 CC 3 SCAR 19.5
CC
3
Cov
0%
handle
12.0
register
2.0
BEGIN
2.0
CRAP 7.0
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__