WWW::Mixi::Scraper 0.09とCustomFeed::MixiScraper

false@PC日記さんからパッチをいただいていたので、のっそり対応しました。

WWW::Mixiとの互換性を考えるとどうかなとも思ったのですが、とりあえず

1) ViewBBS/ViewEventのコメント部分、WWW::Mixiでは発言者のプロフィールがlinkになるのですが、このままだとPlaggerを通したときに鬱陶しいので、fragmentにコメント番号を付与した架空のリンクをでっちあげてあります。従来のプロフリンクはname_linkの方に移動。

2) ViewBBSのコメント番号がsubjectに入っていなかったので、追加(いただいたパッチではここで元タイトルをくっつける処理がされていますが、これはCF::MixiScraperの方で対応)。

これをWWW::Mixi::Scraper 0.09としてアップ。

続いてCustomFeed::MixiScraperの方。修正した内容は下記の通り。falseさんのパッチにはタイムゾーンの指定をしている箇所がありますが、これはたぶんお使いのyamlのglobal以下にtimezone: Asia/Tokyoが抜けているだけではないかと。毎回コメントを取ってこられるのはいやだと思う方もいると思いますので、fetch_commentがtrueの場合のみコメント処理するように変えてあります。あと、コメントに書いておきましたが、view_enqueteはRSSを通しても意味なさそうなので明示的にスキップしています。

Index: MixiScraper.pm
===================================================================
--- MixiScraper.pm	(revision 1965)
+++ MixiScraper.pm	(working copy)
@@ -40,6 +40,11 @@
         get_list   => 'show_calendar',
         get_detail => 'view_event',
     },
+    BBS => {
+        title      => 'コミュニティ最新書き込み',
+        get_list   => 'new_bbs',
+        get_detail => 'view_bbs',
+    },
 };
 
 sub plugin_id {
@@ -136,10 +141,15 @@
             }
         }
 
+        my @comments;
         if ($self->conf->{fetch_body} && !$blocked && $msg->{link} =~ /view_/ && defined $MAP->{$type}->{get_detail}) {
+            # view_enquete is not implemented and probably
+            # won't be implemented as it seems redirected to
+            # reply_enquete
+            next if $msg->{link} =~ /view_enquete/;
             $context->log(info => "Fetch body from $msg->{link}");
             my $item = $self->cache->get_callback(
-                "item-$msg->{link}",
+                "item-".$msg->{link},
                 sub {
                     Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 );
                     my $item = $self->{mixi}->parse($msg->{link});
@@ -161,6 +171,17 @@
                 $entry->body($body);
 
                 $entry->date( Plagger::Date->parse($format, $item->{time}) );
+                if ($self->conf->{fetch_comment}) {
+                  for my $comment (@{ $item->{comments} || [] }) {
+                      my $c = Plagger::Entry->new;
+                         $c->title($entry->title . ': '. $comment->{subject});
+                         $c->body($comment->{description});
+                         $c->link($comment->{link});
+                         $c->author($comment->{name});
+                         $c->date( Plagger::Date->parse($format, $comment->{time}) );
+                      push @comments, $c;
+                  }
+                }
             } else {
                 $context->log(warn => "Fetch body failed. You might be blocked?");
                 $blocked++;
@@ -168,6 +189,9 @@
         }
 
         $feed->add_entry($entry);
+        for my $comment ( @comments ) {
+            $feed->add_entry($comment);
+        }
     }
 
     $context->update->add($feed);
@@ -188,6 +212,7 @@
         email: email@example.com
         password: password
         fetch_body: 1
+        fetch_comment: 0
         show_icon: 1
         feed_type:
           - RecentComment
@@ -222,6 +247,11 @@
 With this option set, this plugin fetches entry body HTML, not just a
 link to the entry. Defaults to 0.
 
+=item fetch_comment
+
+With this option set, this plugin fetches entry's comments as well
+(meaningless when C<fetch_body> is not set). Defaults to 0.
+
 =item fetch_body_interval
 
 With C<fetch_body> option set, your Plagger script is recommended to