Index: t/plugins/Filter-FlickrContactPhotos/base.t =================================================================== --- t/plugins/Filter-FlickrContactPhotos/base.t (revision 0) +++ t/plugins/Filter-FlickrContactPhotos/base.t (revision 0) @@ -0,0 +1,28 @@ +use strict; +use t::TestPlagger; + +test_requires_network; +test_plugin_deps; +plan tests => 6; + +run_eval_expected; + +__END__ + +=== Test Flickr Contact Photos +--- input config +plugins: + - module: Subscription::Config + config: + feed: + - file://$t::TestPlagger::BaseDirURI/t/samples/flickr-friends.xml + - module: Filter::FlickrContactPhotos + config: + api_key: 9d58b60bd3cb21e7d5cd940f3f7c7305 +--- expected +is $context->update->feeds->[0]->entries->[0]->icon->{url}, 'http://farm1.static.flickr.com/25/buddyicons/61554089@N00.jpg'; +is $context->update->feeds->[0]->entries->[0]->icon->{title}, 'Natsu Tohi'; +is $context->update->feeds->[0]->entries->[0]->icon->{link}, 'http://www.flickr.com/people/tohinatsu/'; +is $context->update->feeds->[0]->entries->[1]->icon->{url}, 'http://farm1.static.flickr.com/5/buddyicons/26153219@N00.jpg'; +is $context->update->feeds->[0]->entries->[1]->icon->{title}, 'Kohichi Aoki'; +is $context->update->feeds->[0]->entries->[1]->icon->{link}, 'http://www.flickr.com/people/drikin/'; Index: t/samples/flickr-friends.xml =================================================================== --- t/samples/flickr-friends.xml (revision 0) +++ t/samples/flickr-friends.xml (revision 0) @@ -0,0 +1,403 @@ + + + + From miyagawa's contacts + + + tag:flickr.com,2005:/photos/friends-0-0 + http://farm1.static.flickr.com/1/buddyicons/49503048699@N01.jpg?1102118620#49503048699@N01 + + 2008-09-15T08:56:47Z + Flickr + + + P1060338 + + tag:flickr.com,2005:/photo/2858471483 + 2008-09-15T08:56:47Z + 2008-09-15T08:56:47Z + 2008-07-24T21:36:58-08:00 +

tohinatsugon posted a photo:

+

P1060338

+ +
+ + tohinatsugon + http://www.flickr.com/people/tohinatsu/ + + + +
+ + 鮨英 + + tag:flickr.com,2005:/photo/2858223527 + 2008-09-15T06:20:53Z + 2008-09-15T06:20:53Z + 2008-09-14T13:42:34-08:00 +

Kohichi posted a photo:

+

鮨英

+ +

先日王様のブランチで紹介されていた旗の台にある寿司屋さん
+歩いて行ける圏内なので早速行って見ました。
+
+売りは500円ランチ鮨ですが写真は満腹にぎり1000円。ほん
+と満腹になります。興味あるかたは"旗の台 鮨英"で
+くぐって見てください。気軽に鮨食べたい時にはオススメです。
+
+Sent from iPhone

+ + Kohichi + http://www.flickr.com/people/drikin/ + + + +
+ + Mizuka with our giant okra plant + + tag:flickr.com,2005:/photo/2858804056 + 2008-09-15T04:24:18Z + 2008-09-15T04:24:18Z + 2008-09-14T23:53:08-08:00 +

Joi posted a photo:

+

Mizuka with our giant okra plant

+ +
+ + Joi + http://www.flickr.com/people/joi/ + + + + +
+ + Taft Point + + tag:flickr.com,2005:/photo/2857771011 + 2008-09-15T03:10:13Z + 2008-09-15T03:10:13Z + 2008-09-07T11:12:24-08:00 +

naotakem posted a photo:

+

Taft Point

+ +
+ + naotakem + http://www.flickr.com/people/naotakem/ + + + + +
+ + James! + + tag:flickr.com,2005:/photo/2857686733 + 2008-09-15T02:40:22Z + 2008-09-15T02:40:22Z + 2008-09-14T22:40:22-08:00 +

miz_ginevra posted a photo:

+

James!

+ +

first stop on their North American tour was the Paradise in Boston.

+ + miz_ginevra + http://www.flickr.com/people/ginevra/ + + + + +
+ + IMG_7727 + + tag:flickr.com,2005:/photo/2858189226 + 2008-09-15T00:45:33Z + 2008-09-15T00:45:33Z + 2008-09-13T20:04:17-08:00 +

kennejima posted a photo:

+

IMG_7727

+ +
+ + kennejima + http://www.flickr.com/people/kennejima/ + + + + +
+ + Milo + + tag:flickr.com,2005:/photo/2857809866 + 2008-09-14T22:30:22Z + 2008-09-14T22:30:22Z + 2008-09-09T04:54:33-08:00 +

Andy Lester posted a photo:

+

Milo

+ +
+ + Andy Lester + http://www.flickr.com/people/petdance/ + + + +
+ + Marble + + tag:flickr.com,2005:/photo/2856548409 + 2008-09-14T20:12:29Z + 2008-09-14T20:12:29Z + 2009-01-29T20:59:58-08:00 +

.tiff posted a photo:

+

Marble

+ +

Came with my marble soccer set, from San Salvador

+ + .tiff + http://www.flickr.com/people/dot_tiff/ + + + +
+ + Thames In Flood + + tag:flickr.com,2005:/photo/2857339490 + 2008-09-14T20:00:31Z + 2008-09-14T20:00:31Z + 2008-09-14T15:15:35-08:00 +

cdent posted a photo:

+

Thames In Flood

+ +

Near the locks in Osney

+ + cdent + http://www.flickr.com/people/cdent/ + + + + +
+ + photo.jpg + + tag:flickr.com,2005:/photo/2856959078 + 2008-09-14T18:05:37Z + 2008-09-14T18:05:37Z + 2008-09-14T11:05:37-08:00 +

steveobd posted a photo:

+

photo.jpg

+ +
+ + steveobd + http://www.flickr.com/people/steveobd/ + + + +
+ + aspects2 + + tag:flickr.com,2005:/photo/2856660556 + 2008-09-14T16:28:22Z + 2008-09-14T16:28:22Z + 2008-09-15T01:28:22-08:00 +

Yamaguchies posted a photo:

+

aspects2

+ +

it doesn't have any meaning. I like this angle, color, and font.

+ + Yamaguchies + http://www.flickr.com/people/91221720@N00/ + + + + +
+ + Chain Gang + + tag:flickr.com,2005:/photo/2856439724 + 2008-09-14T15:10:37Z + 2008-09-14T15:10:37Z + 1982-07-01T00:00:00-08:00 +

Dave Cross posted a photo:

+

Chain Gang

+ +

Another blast from the past. I'm second from right.
+
+It's summer 1982 and I'm nineteen. I was walking down Goswell Road one morning when someone stops me and asks if he can take a polaroid of me. Turns out he's from a photographic studio nearby and they're doing a shoot of a heavy metal band that evening. Someone has dropped out of the shoot at the last minute and he's out looking for a replacement. A couple of hours later, having shown the polaroid to his boss, he calls me to ask me to come along to their studio that evening.
+
+I spent a couple of hours having my photo taken with these other people. I got paid £35 for the evening and we also all got more than a little drunk on the crates of beer the studio people brought in. I should point out that there isn't really a band called Chain Gang. None of us had met before that evening.
+
+The advert was for BASF tape. The slogan was "Metal by Chain Gang - Metal tape by BASF". It was part of a series of similar adverts for various types of BASF tapes. The only other one I can remember is a picture of a mod on a really shiny scooter. The slogan on that one was "Chrome by Colin - Chrome tape by BASF".
+
+The adverts appeared in the music press (and on huge posters in tube stations) in about September of that year.

+ + Dave Cross + http://www.flickr.com/people/davorg/ + + + + +
+ + stuffed Pikachu + + tag:flickr.com,2005:/photo/2855290451 + 2008-09-14T12:53:53Z + 2008-09-14T12:53:53Z + 2008-09-14T21:53:53-08:00 +

risathebuzztum posted a photo:

+

stuffed Pikachu

+ +


+ - Camera phone upload powered by ShoZu

+ + risathebuzztum + http://www.flickr.com/people/44855846@N00/ + + + +
+ + RIMG0027 + + tag:flickr.com,2005:/photo/2855237683 + 2008-09-14T12:23:08Z + 2008-09-14T12:23:08Z + 2008-09-14T11:25:05-08:00 +

mu_0623 posted a photo:

+

RIMG0027

+ +

Exif_JPEG_PICTURE

+ + mu_0623 + http://www.flickr.com/people/mu_0623/ + + + + +
+ + Purple civilisation + + tag:flickr.com,2005:/photo/2856052690 + 2008-09-14T12:12:03Z + 2008-09-14T12:12:03Z + 2008-09-14T05:12:03-08:00 +

crucially posted a photo:

+

Purple civilisation

+ +
+ + crucially + http://www.flickr.com/people/crucially/ + + + + +
+ + Fujiya Camera, Nakano, Tokyo, Japan + + tag:flickr.com,2005:/photo/2855906014 + 2008-09-14T10:39:49Z + 2008-09-14T10:39:49Z + 2008-09-14T18:28:48-08:00 +

digitalbear posted a photo:

+

Fujiya Camera, Nakano, Tokyo, Japan

+ +

Photo by Panasonic Lumix LX3

+ + digitalbear + http://www.flickr.com/people/minami/ + + + + +
+ + iPhone app display, apple store sf + + tag:flickr.com,2005:/photo/2854977417 + 2008-09-14T09:36:15Z + 2008-09-14T09:36:15Z + 2008-09-14T02:36:15-08:00 +

emilychang posted a photo:

+

iPhone app display, apple store sf

+ +
+ + emilychang + http://www.flickr.com/people/emilychang/ + + + + +
+ + Samaritain[e] + + tag:flickr.com,2005:/photo/2854867119 + 2008-09-14T08:20:15Z + 2008-09-14T08:20:15Z + 2008-09-12T17:56:57-08:00 +

@rgs posted a photo:

+

Samaritain[e]

+ +
+ + @rgs + http://www.flickr.com/people/rgarciasuarez74/ + + + + +
+ + Big Moon + + tag:flickr.com,2005:/photo/2854857525 + 2008-09-14T08:13:18Z + 2008-09-14T08:13:18Z + 2008-09-13T14:12:37-08:00 +

kazuhito posted a photo:

+

Big Moon

+ +
+ + kazuhito + http://www.flickr.com/people/kazuhito/ + + + +
+ + Pepsi + + tag:flickr.com,2005:/photo/2854753681 + 2008-09-14T06:59:59Z + 2008-09-14T06:59:59Z + 2008-09-14T15:59:24-08:00 +

lopnor posted a photo:

+

Pepsi

+ +
+ + lopnor + http://www.flickr.com/people/lopnor/ + + + +
+ +
\ No newline at end of file Index: lib/Plagger/Plugin/Filter/FlickrContactPhotos.pm =================================================================== --- lib/Plagger/Plugin/Filter/FlickrContactPhotos.pm (revision 0) +++ lib/Plagger/Plugin/Filter/FlickrContactPhotos.pm (revision 0) @@ -0,0 +1,107 @@ +package Plagger::Plugin::Filter::FlickrContactPhotos; +use strict; + +use base qw( Plagger::Plugin ); +use Flickr::API; +use XML::LibXML; + +sub register { + my($self, $context) = @_; + $context->register_hook( + $self, + 'plugin.init' => \&init_flickr, + 'update.entry.fixup' => \&update, + ); +} + +sub init_flickr { + my ($self, $context, $args) = @_; + + $self->{flickr} = Flickr::API->new({ + key => $self->conf->{api_key} + }); +} + +sub update { + my($self, $context, $args) = @_; + my $entry = $args->{entry}; + + if ($entry->link !~ m{^http://www\.flickr\.com/photos/(.+?)/(\d+)/}) { + return; + } + my $user_id = $1; + my $photo_id = $2; + + my $icon = $self->cache->get_callback( + "flickr-buddyicon-$user_id", + sub { + $self->_buddy_icon_of($photo_id); + }, + '3 days' + ); + $entry->icon($icon); +} + +sub _buddy_icon_of { + my($self, $photo_id) = @_; + + my $nsid = $self->_call_flickr( + 'flickr.photos.getInfo', + { photo_id => $photo_id } + )->findvalue('/rsp/photo/owner/@nsid'); + + my $person = $self->_call_flickr( + 'flickr.people.getInfo', + { user_id => $nsid } + ); + + my $title = $person->findvalue('/rsp/person/realname'); + $title ||= $person->findvalue('/rsp/person/username'); + + return { + url => sprintf( + 'http://farm%s.static.flickr.com/%s/buddyicons/%s.jpg', + $person->findvalue('/rsp/person/@iconfarm'), + $person->findvalue('/rsp/person/@iconserver'), + $nsid, + ), + link => $person->findvalue('/rsp/person/profileurl'), + title => $title, + }; +} + +sub _call_flickr { + my($self, $method, $args) = @_; + + my $resp = $self->{flickr}->execute_method($method, $args); + + my $doc = XML::LibXML->new->parse_string($resp->decoded_content); + return $doc; +} + +1; +__END__ + +=head1 NAME + +Plagger::Plugin::Filter::FlickrContactPhotos; + +=head1 SYNOPSIS + + - module: Filter::FlickrContactPhotos + config: + api_key: YOUR-FLICKR-APIKEY + +=head1 DESCRIPTION + +This plugin adds user's buddy icon to Flickr's photos. + +=head1 AUTHOR + +Kazuyoshi Kato + +=head1 SEE ALSO + +L, L, L + +=cut Index: deps/Filter-FlickrContactPhotos.yaml =================================================================== --- deps/Filter-FlickrContactPhotos.yaml (revision 0) +++ deps/Filter-FlickrContactPhotos.yaml (revision 0) @@ -0,0 +1,4 @@ +name: Filter::FlickrContactPhotos +author: Kazuyoshi Kato +depends: + Flickr::API: 0