calliope.lastfm

Access data from Last.fm.

This module uses lastfmclient to access the Last.fm API, and requires a Last.fm API key (see below). Note that the history submodule does not require an API key.

Authentication

API keys are available on request and existing keys can be viewed here.

Credentials should be provided to the LastfmContext by with args lastfm.client-id and lastfm.client-secret.

Additionally lastfm.redirect-uri should be passed. Any URL should work. The first time LastfmContext.authenticate() is called, it will open a browser window to authorize with Last.fm, and will return the access token by asking to paste the redirected URI:

$ cpe lastfm --user ssam top-artists

    User authentication requires interaction with your
    web browser. Once you enter your credentials and
    give authorization, you will be redirected to
    a url.  Paste that url you were directed to to
    complete the authorization.

Opened http://www.last.fm/api/auth/?api_key=275fdd45ac3cd224b3501be6444ff679&cb=http://afuera.me.uk/ in your browser

Enter the URL you were redirected to:

The authorization code will be saved in the cache so future API access will work without a prompt, until the cached code expires.

The credentials can be provided in calliope.conf as follows:

[lastfm] client_id = <API Key> client_secret = <Shared Secret> redirect_uri = http://

Caching

The calliope.cache module is used to cache requests.

Submodules

Package Contents

Classes

LastfmContext

Context for accessing Last.fm API.

Functions

prompt_for_user_token(username[, client_id, ...])

Prompt user to obtain authorization token.

annotate_tags(context, playlist)

similar_artists(context, count, artist_name)

Given an artist, return similar artists.

similar_tracks(context, count, artist_name, track_name)

Given a track artist and title, return similar tracks.

top_artists(context, count, time_range, include)

Return top artists for the given user.

class calliope.lastfm.LastfmContext(user=None, client_id=None, client_secret=None, redirect_uri=None)

Context for accessing Last.fm API.

The authenticate() function must be called to obtain a lastfmclient.LastfmClient object.

Parameters:
  • user – Username to use in requests

  • client_id – API client

  • client_secret – API key

  • redirect_uri – Authentication return URI

authenticate()
calliope.lastfm.prompt_for_user_token(username, client_id=None, client_secret=None, redirect_uri=None)

Prompt user to obtain authorization token.

calliope.lastfm.annotate_tags(context, playlist)
calliope.lastfm.similar_artists(context, count, artist_name)

Given an artist, return similar artists.

calliope.lastfm.similar_tracks(context, count, artist_name, track_name)

Given a track artist and title, return similar tracks.

calliope.lastfm.top_artists(context, count, time_range, include)

Return top artists for the given user.