lastfm#

class platypush.plugins.lastfm.LastfmPlugin(api_key, api_secret, username, password)[source]#

Bases: Plugin

Plugin to interact with your Last.FM (https://last.fm) account, update your current track and your scrobbles.

Requires:

  • pylast (pip install pylast)

__init__(api_key, api_secret, username, password)[source]#
Parameters:
get_recent_tracks(username: str | None = None, limit: int = 10, time_from: int | None = None, time_to: int | None = None) List[dict][source]#

Get a list of recently played tracks.

Parameters:
  • username – Target username (default: the one registered to this plugin).

  • limit – Maximum number of tracks to be returned (default: 10).

  • time_from – Return tracks starting from this time (as a UNIX timestamp).

  • time_to – Return tracks starting up to this time (as a UNIX timestamp).

Returns:

Example:

[
    {
        "artist": "Led Zeppelin",
        "title": "Stairway to Heaven",
        "album": "IV",
        "timestamp": 1654196137
    }
]

get_similar_tracks(artist: str, title: str, limit: int | None = None) List[dict][source]#

Get the tracks that are similar to a specific track.

Parameters:
  • artist – Track artist.

  • title – Track title.

  • limit – Maximum number of suggested tracks to be returned (default: None).

Returns:

A list of similar tracks, each with a match score between 0 and 1. Example:

[
  {
    "artist": "Led Zeppelin",
    "title": "Black Dog",
    "score": 1.0
  },
  {
    "artist": "Led Zeppelin",
    "title": "Rock and Roll",
    "score": 0.89
  },
  {
    "artist": "Eagles",
    "title": "Hotel California",
    "score": 0.471
  },
  {
    "artist": "Deep Purple",
    "title": "Smoke on the Water",
    "score": 0.393
  }
]

get_track(artist: str, title: str) dict | None[source]#

Get the information about a track.

Parameters:
  • artist – Track artist.

  • title – Track title.

Returns:

The retrieved track, with the title corrected if required, if it exists on Last.FM. Example:

{
    "artist": "Led Zeppelin",
    "title": "Stairway to Heaven",
    "tags": ["rock", "hard rock", "70s"]
}

scrobble(artist, title, album=None)[source]#

Scrobble a track to Last.FM

Parameters:
  • artist (str) – Artist

  • title (str) – Title

  • album (str) – Album (optional)

update_now_playing(artist, title, album=None)[source]#

Update the currently playing track

Parameters:
  • artist (str) – Artist

  • title (str) – Title

  • album (str) – Album (optional)