NAME

Net::LastFMAPI - LastFM API 2.0

SYNOPSIS

use Net::LastFMAPI;
my $perl_data = lastfm("artist.getSimilar", artist => "Robbie Basho");

# sets up a session/gets authorisation when needed for write actions:
my $res = lastfm(
    "track.scrobble",
    artist => "Robbie Basho",
    track => "Wounded Knee Soliloquy",
    timestamp => time(),
);
$success = $res->{scrobbles}->{'@attr'}->{accepted} == 1;

my $xml = lastfm(...); # with config value: xml => 1
my $xml = lastfm(..., format => "xml");
$success = $xml =~ m{<scrobbles accepted="1"};

# paginated data can be iterated through per row
my $iter = lastfm_iter("artist.getTopTracks", artist => "John Fahey");
while (my $row = $iter->()) {
    my $whole_response = $Net::LastFMAPI::last_response;
    say $row->{playcount} .": ". $row->name;
}

# wantarray? tries to extract the rows of data for you
my @rows = lastfm(...);

# see also:
# bin/cmd.pl album.getInfo artist=Laddio Bolocko album=As If In Real Time
# bin/scrobble.pl Artist - Track
# bin/portablog-scrobbler.pl

DESCRIPTION

Makes requests to http://ws.audioscrobbler.com/2.0/ and returns the result.

Takes care of POSTing to write methods, doing authorisation when needed.

Dies if something went obviously wrong.

Can return xml if you like, defaults to returning perl data/requesting json. Not all methods support JSON. Beware of "@attr" and empty elements turned into whitespace strings instead of empty arrays, single elements turned into a hash instead of an array of one hash.

The below configurables can be set by k => v hash to lastfm_config if you prefer.

THE SESSION KEY

$Net::LastFMAPI::session_key = "secret"

It will be sought when an authorised request is needed.

If it is not saved then on-screen instructions should be followed to authorise with whoever is logged in to last.fm.

It is saved in the symlink $ENV{HOME}/.net-lastfmapi-sessionkey. This is probably fine.

Consider altering the subroutines talk_authentication, load_save_sessionkey, or simply setting the $Net::LastFMAPI::session_key before needing it.

RETURN XML

$Net::LastFMAPI::xml = 1

This will return an xml string to you. You can also set format => "xml" for a particular request. Apparently, not all methods support JSON. For casual hacking, though, getting perl data is much more convenient.

CACHING

$Net::LastFMAPI::cache = 1

$Net::LastFMAPI::cache_dir = "$ENV{HOME}/.net-lastfmapi-cache/"

Does caching. Default cache directory is shown. Good for development.

PAGINATION

my $iter = lastfm_iter(...);
while (my $row = $iter->()) {
    ...
}

Will attempt to extract rows from a response, passing you one at a time, keeping going into the next page, and the next...

SEE ALSO

Net::LastFM doesn't handle sessions for you, won't POST to write methods

I had no luck with the 1.2 API modules: WebService::LastFM, Music::Audioscrobbler::Submit, Net::LastFM::Submission

BUGS/CODE

https://github.com/st3vil/Net-LastFMAPI

AUTHOR

Steev Eeeriumn <drsteve@cpan.org>

COPYRIGHT

  Copyright (c) 2011, Steev Eeeriumn. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Perl Artistic License
    (see http://www.perl.com/perl/misc/Artistic.html)