package lastfm

  1. Overview
  2. Docs

This is the type of the Audioscrobbler API.

Audioscrobbler is the submission protocol as described at

http://www.audioscrobbler.net/development/protocol/

Types

type source =
  1. | User
  2. | Broadcast
  3. | Recommendation
  4. | Lastfm
  5. | Unknown

source of the track

type rating =
  1. | Love
  2. | Ban
  3. | Skip

possible rating for the track

type action =
  1. | NowPlaying
  2. | Submit

type of action

type song = {
  1. artist : string;
  2. track : string;
  3. time : float option;
  4. source : source option;
  5. rating : rating option;
  6. length : float option;
  7. album : string option;
  8. trackauth : string option;
  9. tracknumber : int option;
  10. musicbrainzid : string option;
}

song submission type

type error =
  1. | Http of string
  2. | Banned
  3. | Badauth
  4. | Badtime
  5. | Failed of string
  6. | UnknownError of string
  7. | Success
  8. | Internal of string
  9. | BadData of string

various errors

exception Error of error
val string_of_error : error -> string

Get meaning of Error e

val base_port : int Stdlib.ref

Base port. Default: 80

val base_host : string Stdlib.ref

Base host. Default: "post.audioscrobbler.com"

Common API

Functions common to both basic and advanced APIs

val get_song : ?time:float -> ?source:source -> ?rating:rating -> ?length:float -> ?album:string -> ?tracknumber:int -> ?musicbrainzid:string -> ?trackauth:string -> artist:string -> track:string -> unit -> song

get_song create a song record based on given values.

Optional records can be ommited there.

val check_song : song -> action -> unit

Check wether required song informations are supplied for given action.

Raises Error (BadData reason) if invalid data is given.

See protocol details there:

http://www.audioscrobbler.net/development/protocol/

Basic API

Using this API, all requests are done in one single step

val do_np : ?timeout:float -> ?host:(string * int) -> client -> login -> song -> unit

do_np client login song execute a nowplaying request with authentification

Optional host parameter is a pair "host",port to override the global values.

val do_submit : ?timeout:float -> ?host:(string * int) -> client -> login -> song list -> (error * song) list

do_submit client login songs execute a nowplaying request with authentification.

This functions returns a list songs for which supplied informations were incomplete, with corresponding exception (see check_song source)

Advanced API

This API is for advanced usages.

You may use it this way:

  1. handshake : initiate session
  2. np/submit: execute request

The module will cache session informations and avoid redundant requests, so you might always call handshake.

However, if a np or submit fails, it can be because the session has expired on server side, but the module cache still refered to it. So you might clear this session id, and try another handshake+submit/np.

Check do_no and do_submit for examples.

val handshake : ?timeout:float -> ?host:(string * int) -> client -> login -> string

handshake client login open session, returns session ID

Optional host parameter is a pair "host",port to override the global values.

val np : ?timeout:float -> string -> song -> unit

np sessionID track execute a nowplaying request

val submit : ?timeout:float -> string -> song list -> (error * song) list

submit sessionID tracks execute a submit request

This functions returns a list songs for which supplied informations were incomplete, with corresponding exception (see check_song)