| 1 | package Plagger::Plugin::Summary::GetSen; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use Encode; | ||
| 6 | use XMLRPC::Lite; | ||
| 7 | |||
| 8 | sub register { | ||
| 9 | my($self, $context) = @_; | ||
| 10 | $context->autoload_plugin({ module => 'Filter::GuessLanguage' }); | ||
| 11 | $context->register_hook( | ||
| 12 | $self, | ||
| 13 | 'summarizer.summarize' => \&summarize, | ||
| 14 | ); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub summarize { | ||
| 18 | my($self, $context, $args) = @_; | ||
| 19 | |||
| 20 | my $lang = $args->{entry}->language || $args->{feed}->language; | ||
| 21 | return unless $lang && $lang eq 'ja'; | ||
| 22 | |||
| 23 | $context->log(info => "Call GetSen XMLRPC API for " . ( $args->{entry}->permalink || '(no-url)' )); | ||
| 24 | my $res; | ||
| 25 | eval { | ||
| 26 | $res = XMLRPC::Lite->proxy("http://www.ryo.com/getsen/rpc.php") | ||
| 27 | ->call("ryocomJapanese.getsen", encode_utf8($args->{text}->plaintext)) | ||
| 28 | ->result; | ||
| 29 | }; | ||
| 30 | |||
| 31 | if (my $err = $res->{flerror} ? $res->{message} : $@) { | ||
| 32 | $context->log(error => "Got error: $err"); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | decode_utf8($res->{summarySentence}); | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | __END__ |