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