| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package LastFM::Export; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
107917
|
$LastFM::Export::AUTHORITY = 'cpan:DOY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$LastFM::Export::VERSION = '0.03'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
1
|
|
|
1
|
|
1663
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: data exporter for last.fm |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Data::Stream::Bulk::Callback; |
|
12
|
|
|
|
|
|
|
use Net::LastFM; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has user => ( |
|
17
|
|
|
|
|
|
|
is => 'ro', |
|
18
|
|
|
|
|
|
|
isa => 'Str', |
|
19
|
|
|
|
|
|
|
required => 1, |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has api_key => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
isa => 'Str', |
|
25
|
|
|
|
|
|
|
default => '30b55f2e2e78056b16dbb15cb0899c2d', |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has lastfm => ( |
|
29
|
|
|
|
|
|
|
is => 'ro', |
|
30
|
|
|
|
|
|
|
isa => 'Net::LastFM', |
|
31
|
|
|
|
|
|
|
lazy => 1, |
|
32
|
|
|
|
|
|
|
default => sub { |
|
33
|
|
|
|
|
|
|
my $self = shift; |
|
34
|
|
|
|
|
|
|
Net::LastFM->new( |
|
35
|
|
|
|
|
|
|
api_key => $self->api_key, |
|
36
|
|
|
|
|
|
|
api_secret => '', |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub track_count { |
|
43
|
|
|
|
|
|
|
my $self = shift; |
|
44
|
|
|
|
|
|
|
my (%params) = @_; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$params{method} = 'user.getRecentTracks'; |
|
47
|
|
|
|
|
|
|
$params{user} = $self->user; |
|
48
|
|
|
|
|
|
|
$params{limit} = 1; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return $self->lastfm->request(%params)->{recenttracks}{'@attr'}{total}; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub tracks { |
|
55
|
|
|
|
|
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
my (%params) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$params{method} = 'user.getRecentTracks'; |
|
59
|
|
|
|
|
|
|
$params{user} = $self->user; |
|
60
|
|
|
|
|
|
|
$params{limit} ||= 200; |
|
61
|
|
|
|
|
|
|
$params{page} ||= 1; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return Data::Stream::Bulk::Callback->new( |
|
64
|
|
|
|
|
|
|
callback => sub { |
|
65
|
|
|
|
|
|
|
my $data = $self->lastfm->request(%params); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return if $params{page} > $data->{recenttracks}{'@attr'}{totalPages}; |
|
68
|
|
|
|
|
|
|
$params{page}++; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $data->{recenttracks}{track}; |
|
71
|
|
|
|
|
|
|
}, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
76
|
|
|
|
|
|
|
no Moose; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=pod |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 NAME |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
LastFM::Export - data exporter for last.fm |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 VERSION |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
version 0.03 |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
use LastFM::Export; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $exporter = LastFM::Export->new(user => 'doyster'); |
|
98
|
|
|
|
|
|
|
my $stream = $exporter->tracks; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
while (my $block = $stream->next) { |
|
101
|
|
|
|
|
|
|
for my $track (@$block) { |
|
102
|
|
|
|
|
|
|
# ... |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
sleep 1; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This module uses the L<http://last.fm/> API to allow you to export your |
|
110
|
|
|
|
|
|
|
scrobbling data from your account. Currently, the only thing this lets you |
|
111
|
|
|
|
|
|
|
export is your actual scrobble data, but more features may be added in the |
|
112
|
|
|
|
|
|
|
future (especially if the feature requests come with patches!). |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 user |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
last.fm user to export data for. Required. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 METHODS |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 track_count(%params) |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns the number of tracks the user has scrobbled. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
C<%params> can contain C<from> and C<to> keys, as documented |
|
127
|
|
|
|
|
|
|
L<here|http://www.last.fm/api/show/user.getRecentTracks>. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 tracks(%params) |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns a L<Data::Stream::Bulk> object, which will stream the entire list of |
|
132
|
|
|
|
|
|
|
tracks that the user has scrobbled. Note that calling C<all> on this object is |
|
133
|
|
|
|
|
|
|
B<not> recommended, since you will likely hit the last.fm API's rate limit. |
|
134
|
|
|
|
|
|
|
Each call to C<next> on this stream will require a separate API call. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
C<%params> can contain C<page>, C<limit>, C<from>, and C<to> keys, as |
|
137
|
|
|
|
|
|
|
documented L<here|http://www.last.fm/api/show/user.getRecentTracks>. C<page> |
|
138
|
|
|
|
|
|
|
will default to C<1> and C<limit> will default to C<200> if not specified. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 BUGS |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
No known bugs. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please report any bugs to GitHub Issues at |
|
147
|
|
|
|
|
|
|
L<https://github.com/doy/lastfm-export/issues>. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L<Net::LastFM> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L<http://last.fm/> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can find this documentation for this module with the perldoc command. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
perldoc LastFM::Export |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
You can also look for information at: |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=over 4 |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * MetaCPAN |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L<https://metacpan.org/release/LastFM-Export> |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * Github |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<https://github.com/doy/lastfm-export> |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=LastFM-Export> |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/LastFM-Export> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Jesse Luehrs <doy@tozt.net> |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Jesse Luehrs. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This is free software, licensed under: |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
The MIT (X11) License |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |