package LastFM::Export; use Moose; # ABSTRACT: data exporter for last.fm use Data::Stream::Bulk::Callback; use Net::LastFM; =head1 SYNOPSIS use LastFM::Export; my $exporter = LastFM::Export->new(user => 'doyster'); my $stream = $exporter->tracks; while (my $block = $stream->next) { for my $track (@$block) { # ... } sleep 1; } =head1 DESCRIPTION This module uses the L API to allow you to export your scrobbling data from your account. Currently, the only thing this lets you export is your actual scrobble data, but more features may be added in the future (especially if the feature requests come with patches!). =cut =attr user last.fm user to export data for. Required. =cut has user => ( is => 'ro', isa => 'Str', required => 1, ); has api_key => ( is => 'ro', isa => 'Str', default => '30b55f2e2e78056b16dbb15cb0899c2d', ); has lastfm => ( is => 'ro', isa => 'Net::LastFM', lazy => 1, default => sub { my $self = shift; Net::LastFM->new( api_key => $self->api_key, api_secret => '', ); }, ); =method track_count(%params) Returns the number of tracks the user has scrobbled. C<%params> can contain C and C keys, as documented L. =cut sub track_count { my $self = shift; my (%params) = @_; $params{method} = 'user.getRecentTracks'; $params{user} = $self->user; $params{limit} = 1; return $self->lastfm->request(%params)->{recenttracks}{'@attr'}{total}; } =method tracks(%params) Returns a L object, which will stream the entire list of tracks that the user has scrobbled. Note that calling C on this object is B recommended, since you will likely hit the last.fm API's rate limit. Each call to C on this stream will require a separate API call. C<%params> can contain C, C, C, and C keys, as documented L. C will default to C<1> and C will default to C<200> if not specified. Returns =cut sub tracks { my $self = shift; my (%params) = @_; $params{method} = 'user.getRecentTracks'; $params{user} = $self->user; $params{limit} ||= 200; $params{page} ||= 1; return Data::Stream::Bulk::Callback->new( callback => sub { my $data = $self->lastfm->request(%params); return if $params{page} > $data->{recenttracks}{'@attr'}{totalPages}; $params{page}++; return $data->{recenttracks}{track}; }, ); } __PACKAGE__->meta->make_immutable; no Moose; =head1 BUGS No known bugs. Please report any bugs through RT: email C, or browse to L. =head1 SEE ALSO L L =head1 SUPPORT You can find this documentation for this module with the perldoc command. perldoc LastFM::Export You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =cut 1;