Changeset 507
- Timestamp:
- 04/02/06 16:50:10
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/lib/Plagger/Plugin/CustomFeed/iTunesRecentPlay.pm
r430 r507 8 8 use HTML::Entities; 9 9 use Plagger::UserAgent; 10 use Net::Amazon; 11 use Net::Amazon::Request::Keyword; 10 12 11 13 sub register { … … 77 79 m!</dict>! 78 80 and do { 79 my $entry = Plagger::Entry->new;80 81 81 if( $data->{date} and $data->{artist} ){ 82 82 my $dt = DateTime::Format::W3CDTF->parse_datetime($data->{date}); … … 86 86 } 87 87 if( !defined $self->conf->{duration} or $dt->epoch > time - $self->conf->{duration} * 60 ){ 88 my $entry = Plagger::Entry->new; 89 $entry->date(Plagger::Date->from_epoch($dt->epoch)); 90 91 # author 92 $entry->author($data->{artist}); 93 94 # title 95 my $title = $self->conf->{title_format}; 96 $title = '%track - %artist' unless $title; 97 $title =~ s/%artist/$data->{artist}/; 98 $title =~ s/%album/$data->{album}/; 99 $title =~ s/%track/$data->{track}/; 100 $entry->title($title); 101 102 # search aws 103 if($self->conf->{aws_developer_token}){ 104 my $item = $self->search_aws($context, $data->{artist}, $data->{album}); 105 if($item){ 106 $entry->link($item->url); 107 $entry->icon({ url => $item->ImageUrlSmall }); 108 $entry->body($item->ProductDescription); 109 $entry->summary($item->ProductDescription); 110 } 111 } 112 88 113 for my $key (keys %$data){ 89 114 $entry->meta->{$key} = $data->{$key}; 90 115 } 91 $entry->date(Plagger::Date->from_epoch($dt->epoch)); 116 92 117 $context->log( debug => $data->{artist} . ' ' . $data->{track}); 118 93 119 $feed->add_entry($entry); 94 120 } … … 101 127 } 102 128 129 sub search_aws { 130 my($self, $context, $artist, $album) = @_; 131 $context->log( info => "Searching $artist - $album on Amazon..."); 132 my $attr; 133 $attr->{token} = $self->conf->{aws_developer_token}; 134 $attr->{locale} = $self->conf->{aws_locale}; 135 $attr->{affiliate_id} = $self->conf->{aws_associate_id}; 136 137 my $ua = Net::Amazon->new(%$attr); 138 139 my $keyword = encode("UTF-8", "$artist $album"); 140 my $req = Net::Amazon::Request::Keyword->new( 141 keyword => $keyword, 142 mode => 'music'. $self->conf->{aws_locale}, 143 ); 144 145 my $response = $ua->request($req); 146 my $item = ($response->properties())[0]; 147 return $item; 148 } 149 103 150 1; 104 151 __END__ … … 115 162 library_path: /path/to/iTunes Music Library.xml 116 163 duration: 120 164 title_format: %track - %artist 165 aws_developer_token: XXXXXXXXXXXXXXXXXXXX 166 aws_associate_id: xxxxxxxxxx-22 167 aws_locale: jp 117 168 118 169 =head1 DESCRIPTION … … 135 186 period of plagger with cron to reduce memory usage. 136 187 188 =item title_format 189 190 Set a title format of an entry.You can use %track, %artist and %album. 191 192 =item aws_developer_token 193 194 If you set this parameter, this plugin get information about a track from the Amazon web service. 195 196 =item aws_associate_id 197 198 Your Amazon associate ID. 199 200 =item aws_locale 201 202 Set a web service locale. 203 137 204 =back 138 205
