NAME

Audio::Scrobbler2 - Interface to the Last.fm scrobbling API

SYNOPSIS

use Audio::Scrobbler2;

my $scrobbler = Audio::Scrobbler2->new($api_key, $api_secret);
my $api_token = $scrobbler->auth_getToken;

# Ask the user to authorize the token:
# https://www.last.fm/api/auth/?api_key=$api_key&token=$api_token
my $api_session = $scrobbler->auth_getSession;

$scrobbler->track_updateNowPlaying('Artist Name', 'Track Name');
$scrobbler->track_scrobble('Artist Name', 'Track Name', $started_at);

DESCRIPTION

Audio::Scrobbler2 implements the desktop authentication flow and the two Last.fm track submission methods needed by a basic scrobbler. Requests use HTTPS, UTF-8 form encoding, and verified TLS certificates.

All validation, transport, HTTP, JSON, and Last.fm API failures throw an exception. The module does not retry requests because retrying a submission could create a duplicate scrobble.

METHODS

new

my $scrobbler = Audio::Scrobbler2->new($api_key, $api_secret);

Creates a client. Both credentials are required.

auth_getToken

my $token = $scrobbler->auth_getToken;

Requests and stores an unauthorized desktop application token.

auth_getSession

my $session_key = $scrobbler->auth_getSession;

Exchanges the authorized token for a session key and stores it.

set_session_key

$scrobbler->set_session_key($session_key);

Stores an existing non-empty session key.

track_updateNowPlaying

my $response = $scrobbler->track_updateNowPlaying($artist, $track);

Updates the currently playing track and returns the decoded Last.fm response.

track_scrobble

my $response = $scrobbler->track_scrobble(
    $artist,
    $track,
    $started_at,
);

Scrobbles a track and returns the decoded Last.fm response. $started_at must be a positive integer Unix timestamp for when playback started.

MIGRATING FROM 0.05

Version 1.00 requires a playback start timestamp in track_scrobble. All failures now throw exceptions instead of returning 0 or inconsistent error structures.

AUTHOR

Pier Dolique (Perdolique), baget@cpan.org

CPAN ID: BAGET

COPYRIGHT AND LICENSE

Copyright 2012-2026 Pier Dolique.

This software is free software; you can redistribute it and/or modify it under the same terms as Perl itself.