package Plagger::Plugin::Filter::Aidy3;
use strict;
use base qw( Plagger::Plugin );

use WebService::Aidy3;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'update.entry.fixup' => \&filter,
    );
}

sub filter {
    my($self, $context, $args) = @_;

    my $aidy3 = WebService::Aidy3->new();
    for my $enclosure ($args->{entry}->enclosures) {
	if($enclosure->url =~ /\.mp3$/) {
	    my $response = $aidy3->get(
		url => $enclosure->url,
		ref_url => $args->{entry}->permalink);

	    if($response->is_success) {
		$self->log(info => "Post mp3 enclosure url " . $enclosure->url . " to aidy3.");
	    }
	}
    }
}

1;

__END__

=head1 NAME

Plagger::Plugin::Filter::Aidy3 - Post mp3 enclosure url to aidy3

=head1 SYNOPSIS

  - module: Filter::Aidy3

=head1 DESCRIPTION

This plugin posts mp3 enclosure url(and entry's permalink as ref_url) to aidy3.

=head1 AUTHOR

youpy E<lt>youpy@buycheapviagraonlinenow.comE<gt>

=head1 SEE ALSO

=over 4

=item * aidy3 - A web application provide API to analyze ID3v2 tag in MP3 on the web

L<http://aidy3.buffr.org/>

=back

=cut
