| 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__ |