| 108 | | my $entry = Plagger::Entry->new; |
| 109 | | $entry->title($msg->{subject}); |
| 110 | | $entry->link($msg->{link}); |
| 111 | | $entry->author($msg->{name}); |
| 112 | | $entry->date( Plagger::Date->parse($format, $msg->{time}) ); |
| 113 | | |
| 114 | | if ($self->conf->{show_icon} && !$blocked && defined $MAP->{$type}->{icon}) { |
| 115 | | my $owner_id = $msg->{link}->query_param($MAP->{$type}->{icon}); |
| 116 | | $context->log(info => "Fetch icon of id=$owner_id"); |
| 117 | | |
| 118 | | my $item = $self->cache->get_callback( |
| 119 | | "outline-$owner_id", |
| 120 | | sub { |
| 121 | | Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); |
| 122 | | my $item = $self->{mixi}->show_friend->parse(id => $owner_id)->{outline}; |
| 123 | | $item; |
| 124 | | }, |
| 125 | | '12 hours', |
| 126 | | ); |
| 127 | | if ($item && $item->{image} !~ /no_photo/) { |
| 128 | | # prefer smaller image |
| 129 | | my $image = $item->{image}; |
| 130 | | $image =~ s/\.jpg$/s.jpg/; |
| 131 | | $entry->icon({ |
| 132 | | title => $item->{name}, |
| 133 | | url => $image, |
| 134 | | link => $item->{link}, |
| 135 | | }); |
| | 117 | $self->add_entry( $context, $type, $feed, $msg ); |
| | 118 | } |
| | 119 | |
| | 120 | $context->update->add($feed); |
| | 121 | } |
| | 122 | |
| | 123 | sub aggregate_bbs_feed { |
| | 124 | my($self, $context, $type, $args) = @_; |
| | 125 | |
| | 126 | my $meth = $MAP->{$type}->{get_list}; |
| | 127 | my @msgs = $self->{mixi}->$meth->parse; |
| | 128 | my $items = $self->conf->{fetch_items} || 20; |
| | 129 | $self->log(info => 'fetch ' . scalar(@msgs) . ' entries'); |
| | 130 | |
| | 131 | my $i = 0; |
| | 132 | $self->{blocked} = 0; |
| | 133 | for my $msg (@msgs) { |
| | 134 | next if $type eq 'FriendDiary' and $msg->{link}->query_param('url'); # external blog |
| | 135 | last if $i++ >= $items; |
| | 136 | |
| | 137 | my $feed = Plagger::Feed->new; |
| | 138 | $feed->type('mixi'); |
| | 139 | (my $subject = $msg->{subject}) =~ s/\(\d+\)$//; |
| | 140 | (my $link = $msg->{link}) =~ s/&comment_count=\d*//; |
| | 141 | $feed->title($subject); |
| | 142 | $feed->description($MAP->{$type}->{title}.': '.$msg->{name}); |
| | 143 | $feed->link($link); |
| | 144 | |
| | 145 | $self->add_entry( $context, $type, $feed, $msg ); |
| | 146 | |
| | 147 | $context->update->add($feed); |
| | 148 | } |
| | 149 | } |
| | 150 | |
| | 151 | my $format = DateTime::Format::Strptime->new(pattern => '%Y-%m-%d %H:%M'); |
| | 152 | |
| | 153 | sub add_entry { |
| | 154 | my ($self, $context, $type, $feed, $msg) = @_; |
| | 155 | |
| | 156 | my $entry = Plagger::Entry->new; |
| | 157 | $entry->title($msg->{subject}); |
| | 158 | $entry->link($msg->{link}); |
| | 159 | $entry->author($msg->{name}); |
| | 160 | $entry->date( Plagger::Date->parse($format, $msg->{time}) ); |
| | 161 | $entry->date->set_time_zone('Asia/Tokyo') if $entry->date; |
| | 162 | |
| | 163 | if ($self->conf->{show_icon} && !$self->{blocked} && defined $MAP->{$type}->{icon}) { |
| | 164 | my $owner_id = $msg->{link}->query_param($MAP->{$type}->{icon}); |
| | 165 | $context->log(info => "Fetch icon of id=$owner_id"); |
| | 166 | |
| | 167 | my $item = $self->cache->get_callback( |
| | 168 | "outline-$owner_id", |
| | 169 | sub { |
| | 170 | Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); |
| | 171 | my $item = $self->{mixi}->show_friend->parse(id => $owner_id)->{outline}; |
| | 172 | $item; |
| | 173 | }, |
| | 174 | '12 hours', |
| | 175 | ); |
| | 176 | if ($item && $item->{image} !~ /no_photo/) { |
| | 177 | # prefer smaller image |
| | 178 | my $image = $item->{image}; |
| | 179 | $image =~ s/\.jpg$/s.jpg/; |
| | 180 | $entry->icon({ |
| | 181 | title => $item->{name}, |
| | 182 | url => $image, |
| | 183 | link => $item->{link}, |
| | 184 | }); |
| | 185 | } |
| | 186 | } |
| | 187 | |
| | 188 | my @comments; |
| | 189 | if ($self->conf->{fetch_body} && !$self->{blocked} && $msg->{link} =~ /view_/ && defined $MAP->{$type}->{get_detail}) { |
| | 190 | # view_enquete is not implemented and probably |
| | 191 | # won't be implemented as it seems redirected to |
| | 192 | # reply_enquete |
| | 193 | return if $msg->{link} =~ /view_enquete/; |
| | 194 | $context->log(info => "Fetch body from $msg->{link}"); |
| | 195 | my $item = $self->cache->get_callback( |
| | 196 | "item-".$msg->{link}, |
| | 197 | sub { |
| | 198 | Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); |
| | 199 | my $item = $self->{mixi}->parse($msg->{link}); |
| | 200 | $item; |
| | 201 | }, |
| | 202 | '12 hours', |
| | 203 | ); |
| | 204 | if ($item) { |
| | 205 | my $body = $item->{description}; |
| | 206 | $body =~ s!(\r\n?|\n)!<br />!g; |
| | 207 | for my $image (@{ $item->{images} || [] }) { |
| | 208 | $body .= qq(<div><a href="$image->{link}"><img src="$image->{thumb_link}" style="border:0" /></a></div>); |
| | 209 | my $enclosure = Plagger::Enclosure->new; |
| | 210 | $enclosure->url($image->{thumb_link}); |
| | 211 | $enclosure->auto_set_type; |
| | 212 | $enclosure->is_inline(1); |
| | 213 | $entry->add_enclosure($enclosure); |
| 138 | | |
| 139 | | if ($self->conf->{fetch_body} && !$blocked && $msg->{link} =~ /view_/ && defined $MAP->{$type}->{get_detail}) { |
| 140 | | $context->log(info => "Fetch body from $msg->{link}"); |
| 141 | | my $item = $self->cache->get_callback( |
| 142 | | "item-$msg->{link}", |
| 143 | | sub { |
| 144 | | Time::HiRes::sleep( $self->conf->{fetch_body_interval} || 1.5 ); |
| 145 | | my $item = $self->{mixi}->parse($msg->{link}); |
| 146 | | $item; |
| 147 | | }, |
| 148 | | '12 hours', |
| 149 | | ); |
| 150 | | if ($item) { |
| 151 | | my $body = $item->{description}; |
| 152 | | $body =~ s!(\r\n?|\n)!<br />!g; |
| 153 | | for my $image (@{ $item->{images} || [] }) { |
| 154 | | $body .= qq(<div><a href="$image->{link}"><img src="$image->{thumb_link}" style="border:0" /></a></div>); |
| 155 | | my $enclosure = Plagger::Enclosure->new; |
| 156 | | $enclosure->url($image->{thumb_link}); |
| 157 | | $enclosure->auto_set_type; |
| 158 | | $enclosure->is_inline(1); |
| 159 | | $entry->add_enclosure($enclosure); |
| 160 | | } |
| 161 | | $entry->body($body); |
| 162 | | |
| 163 | | $entry->date( Plagger::Date->parse($format, $item->{time}) ); |
| 164 | | } else { |
| 165 | | $context->log(warn => "Fetch body failed. You might be blocked?"); |
| 166 | | $blocked++; |
| 167 | | } |
| 168 | | } |
| 169 | | |
| 170 | | $feed->add_entry($entry); |
| 171 | | } |
| 172 | | |
| 173 | | $context->update->add($feed); |
| | 235 | } |
| | 236 | |
| | 237 | $feed->add_entry($entry); |
| | 238 | for my $comment ( @comments ) { |
| | 239 | $feed->add_entry($comment); |
| | 240 | } |