root/plagger/trunk/lib/Plagger/Plugin/CustomFeed/iTMS.pm

Revision 122, 2.0 kB (checked in by miya, 3 years ago)

support country.
add pod.

  • Property svn:executable set to *
Line 
1 package Plagger::Plugin::CustomFeed::iTMS;
2 use strict;
3 use warnings;
4 use base qw( Plagger::Plugin );
5
6 use Plagger::Enclosure;
7 use LWP::UserAgent::iTMS_Client;
8 use DateTime::Format::W3CDTF;
9 use Net::iTMS;
10
11 sub register {
12     my($self, $context) = @_;
13     $context->register_hook(
14         $self,
15         'subscription.load' => \&load,
16     );
17 }
18
19 sub load {
20     my($self, $context) = @_;
21     my $feed = Plagger::Feed->new;
22     $feed->aggregator(sub { $self->aggregate(@_) });
23     $context->subscription->add($feed);
24 }
25
26 sub aggregate {
27     my($self, $context, $args) = @_;
28
29     my $feed = Plagger::Feed->new;
30     $feed->type('iTMSSeach');
31     $feed->title('iTMS Search');
32
33     my $ua = LWP::UserAgent::iTMS_Client->new( country => $self->conf->{country} || 'USA' );
34     my $itms = Net::iTMS->new;
35
36     my $results = $ua->search( %{$self->conf->{query}} );
37     for my $result (@$results){
38         my $entry = Plagger::Entry->new;
39
40         $entry->title($result->{itemName});
41         $entry->author( $itms->get_artist($result->{artistId}) );
42         if($result->{releaseDate}){
43             my $dt = DateTime::Format::W3CDTF->parse_datetime($result->{releaseDate});
44             $entry->date(Plagger::Date->from_epoch($dt->epoch));
45         }
46
47         my $enclosure = Plagger::Enclosure->new;
48         $enclosure->url($result->{previewURL});
49         $enclosure->auto_set_type;
50         $entry->add_enclosure($enclosure);
51
52         $feed->add_entry($entry);
53     }
54
55     $context->update->add($feed);
56 }
57
58 1;
59 __END__
60
61 =head1 NAME
62
63 Plagger::Plugin::CustomFeed::iTMS - Apple iTunes Music Store CustomFeed
64
65 =head1 SYNOPSIS
66
67   - module: CustomFeed::iTMS
68     config:
69       country: Japan
70       query:
71         artsit: zebrahead
72
73 =head1 DESCRIPTION
74
75 This plugin fetches seach results from Apple iTunes Music Store.
76
77 =head1 CONFIG
78
79 =over 4
80
81 =item country
82
83 Country name of the store you use.
84
85 =item query
86
87 Query parameters for searching.
88
89 =back
90
91 =head1 AUTHOR
92
93 Gosuke Miyashita
94
95 =head1 SEE ALSO
96
97 L<Plagger>, L<LWP::UserAgent::iTMS_Client>, L<Net::iTMS>
98
99 =cut
100
Note: See TracBrowser for help on using the browser.