Plagger::Plugin::Filter::ImageGathering
Plaggerがenclosure対応ってことで。
Image TagのURLをenclosureに追加していくPlugin
- module: Filter::ImageGathering
configはない。
package Plagger::Plugin::Filter::ImageGathering;
use strict;
use base qw( Plagger::Plugin );
sub register {
my($self, $context) = @_;
$context->register_hook(
$self,
'update.entry.fixup' => \&update,
);
}
sub update {
my ( $self, $context, $args ) = @_;
my $body = $args->{entry}->body;
while($body =~ m!<img([^>]+)>!ig){
$self->gathering($&,$context,$args)
}
}
sub gathering {
my ( $self, $tag, $context, $args ) = @_;
my %attrs;
while ( $tag =~ m!(\w+)\s*=\s*(["'])(.*?)\2!g ) {
$attrs{$1} = $3;
}
return unless $attrs{src};
my $enclosure = Plagger::Enclosure->new;
$enclosure->url( URI->new($attrs{src}) );
#$enclosure->length();
#$enclosure->type();
$args->{entry}->add_enclosure($enclosure);
}
1;
http://svn.nomadscafe.jp/public/library/perl/Plagger-Plugin-Filter-ImageGathering/
に置いておいた。