Documentation
¶
Overview ¶
Package api is a small client for the go-librespot daemon HTTP API.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AddToPlaylist(ctx context.Context, playlistURI string, uris []string) error
- func (c *Client) AddToQueue(ctx context.Context, uri string) error
- func (c *Client) AuthCode(ctx context.Context) (*DeviceAuth, error)
- func (c *Client) Base() string
- func (c *Client) ContextTracks(ctx context.Context, uri string) (*ContextTracks, error)
- func (c *Client) CreatePlaylist(ctx context.Context, name string) (string, error)
- func (c *Client) LibraryAlbums(ctx context.Context) ([]LibraryAlbum, error)
- func (c *Client) LibraryArtists(ctx context.Context) ([]LibraryArtist, error)
- func (c *Client) LibraryPlaylists(ctx context.Context) ([]LibraryPlaylist, error)
- func (c *Client) Liked(ctx context.Context, uris []string) (map[string]bool, error)
- func (c *Client) Next(ctx context.Context) error
- func (c *Client) Play(ctx context.Context, uri, skipTo string) error
- func (c *Client) PlayPause(ctx context.Context) error
- func (c *Client) PlaylistContains(ctx context.Context, playlistURI string, uris []string) (map[string]bool, error)
- func (c *Client) Prev(ctx context.Context) error
- func (c *Client) Ready(ctx context.Context) (bool, error)
- func (c *Client) RemoveFromPlaylist(ctx context.Context, playlistURI, uri string, position int) error
- func (c *Client) RemovePlaylist(ctx context.Context, playlistURI string) error
- func (c *Client) Seek(ctx context.Context, posMs int64, relative bool) error
- func (c *Client) SetLiked(ctx context.Context, uris []string, liked bool) error
- func (c *Client) SetRepeatContext(ctx context.Context, on bool) error
- func (c *Client) SetRepeatTrack(ctx context.Context, on bool) error
- func (c *Client) SetShuffle(ctx context.Context, on bool) error
- func (c *Client) SetVolume(ctx context.Context, vol int, relative bool) error
- func (c *Client) Status(ctx context.Context) (*Status, error)
- func (c *Client) StreamEvents(ctx context.Context, onEvent func(Event), onConn func(connected bool))
- type ContextTrackItem
- type ContextTracks
- type DeviceAuth
- type Event
- type LibraryAlbum
- type LibraryArtist
- type LibraryPlaylist
- type Status
- type Track
Constants ¶
const MaxLikedQuery = 50
MaxLikedQuery is how many URIs one Liked query may carry.
Variables ¶
var ( // /context/tracks (older version or metadata.enabled is false). ErrContextTracksUnavailable = errors.New("context track listing unavailable") // /library/playlists. ErrLibraryUnavailable = errors.New("library listing unavailable") // Liked Songs or playlists. ErrLibraryWriteUnavailable = errors.New("daemon cannot write to the library") // tracks are liked. ErrLikedUnavailable = errors.New("liked state unavailable") // a playlist holds a track. ErrContainsUnavailable = errors.New("playlist membership unavailable") // ErrNotInPlaylist is returned when a playlist does not hold the track to // remove, or the daemon cannot remove from playlists. ErrNotInPlaylist = errors.New("not in the playlist") // ErrPlaylistChanged is returned when a playlist changed since it was // listed, so the entry to remove is no longer where it was. ErrPlaylistChanged = errors.New("the playlist changed") // ErrNotInLibrary is returned when the playlist to remove is not in the // user's library, or the daemon cannot remove playlists. ErrNotInLibrary = errors.New("not in the library") // ErrNoSession is returned when the daemon has no active Spotify session. ErrNoSession = errors.New("no active Spotify session") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a go-librespot daemon.
func New ¶
New creates a client for the daemon at base, e.g. "http://localhost:3678".
func (*Client) AddToPlaylist ¶
AddToPlaylist appends uris to the end of a playlist.
func (*Client) AuthCode ¶
func (c *Client) AuthCode(ctx context.Context) (*DeviceAuth, error)
AuthCode returns the pairing code the daemon waits on, or nil when it waits on none.
func (*Client) ContextTracks ¶
ContextTracks lists the tracks of a context. It never blocks on the network on the daemon side; poll until the result is Complete.
func (*Client) CreatePlaylist ¶
CreatePlaylist creates an empty playlist named name at the top of the user's library and returns its URI. ErrLibraryWriteUnavailable means the daemon cannot create playlists; ErrPlaylistChanged that the playlist was created but the library kept changing, so it is not in the library.
func (*Client) LibraryAlbums ¶
func (c *Client) LibraryAlbums(ctx context.Context) ([]LibraryAlbum, error)
LibraryAlbums lists the user's saved albums, most recently saved first.
func (*Client) LibraryArtists ¶
func (c *Client) LibraryArtists(ctx context.Context) ([]LibraryArtist, error)
LibraryArtists lists the artists the user follows, most recent first.
func (*Client) LibraryPlaylists ¶
func (c *Client) LibraryPlaylists(ctx context.Context) ([]LibraryPlaylist, error)
LibraryPlaylists lists all playlists in the user's library, in library order.
func (*Client) PlaylistContains ¶
func (c *Client) PlaylistContains(ctx context.Context, playlistURI string, uris []string) (map[string]bool, error)
PlaylistContains tells for each of uris whether the playlist holds it.
func (*Client) Ready ¶
Ready reports whether the daemon is logged in and ready to play; it is not while it is still logging in to Spotify.
func (*Client) RemoveFromPlaylist ¶
func (c *Client) RemoveFromPlaylist(ctx context.Context, playlistURI, uri string, position int) error
RemoveFromPlaylist removes the entry of uri at position from a playlist.
func (*Client) RemovePlaylist ¶
RemovePlaylist takes a playlist out of the user's library: it deletes a playlist the user owns and unfollows anyone else's. Spotify keeps the playlist itself, for its followers and to be restored.
func (*Client) SetRepeatContext ¶
func (*Client) StreamEvents ¶
func (c *Client) StreamEvents(ctx context.Context, onEvent func(Event), onConn func(connected bool))
StreamEvents connects to the daemon's event WebSocket and calls onEvent for every event. It reconnects with a backoff until ctx is cancelled and reports connection changes through onConn.
type ContextTrackItem ¶
ContextTrackItem is one entry of a context listing.
type ContextTracks ¶
type ContextTracks struct {
URI string `json:"uri"`
Ready bool `json:"ready"`
Length int `json:"length"`
Cached int `json:"cached"`
Tracks []ContextTrackItem `json:"tracks"`
}
ContextTracks is a context's track listing.
func (*ContextTracks) Complete ¶
func (c *ContextTracks) Complete() bool
Complete reports whether the listing is fully enumerated and resolved.
type DeviceAuth ¶
type DeviceAuth struct {
URL string `json:"url"`
Code string `json:"code"`
ExpiresAt time.Time `json:"expires_at"`
}
DeviceAuth is a pairing code the daemon waits on the user to approve.
type Event ¶
type Event struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
Event is a player event pushed over the /events WebSocket.
type LibraryAlbum ¶
type LibraryAlbum struct {
URI string `json:"uri"`
Name string `json:"name"`
ArtistNames []string `json:"artist_names"`
Year int `json:"year"`
ImageURL *string `json:"image_url"`
}
LibraryAlbum is an album saved in the user's library.
type LibraryArtist ¶
type LibraryArtist struct {
URI string `json:"uri"`
Name string `json:"name"`
ImageURL *string `json:"image_url"`
}
LibraryArtist is an artist the user follows.
type LibraryPlaylist ¶
type LibraryPlaylist struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description"`
OwnerUsername string `json:"owner_username"`
Length int `json:"length"`
ImageURL *string `json:"image_url"`
Collaborative bool `json:"collaborative"`
CanEdit bool `json:"can_edit"`
Folder []string `json:"folder"`
}
LibraryPlaylist is a playlist in the user's library.
type Status ¶
type Status struct {
Username string `json:"username"`
DeviceID string `json:"device_id"`
DeviceType string `json:"device_type"`
DeviceName string `json:"device_name"`
PlayOrigin *string `json:"play_origin"`
ContextURI *string `json:"context_uri"`
ContextName *string `json:"context_name"`
Stopped bool `json:"stopped"`
Paused bool `json:"paused"`
Buffering bool `json:"buffering"`
Volume int `json:"volume"`
VolumeSteps int `json:"volume_steps"`
RepeatContext bool `json:"repeat_context"`
RepeatTrack bool `json:"repeat_track"`
ShuffleContext bool `json:"shuffle_context"`
Track *Track `json:"track"`
NextTrack *Track `json:"next_track"`
}
Status is the player status.
type Track ¶
type Track struct {
URI string `json:"uri"`
Name string `json:"name"`
ArtistNames []string `json:"artist_names"`
ArtistURIs []string `json:"artist_uris"`
AlbumName string `json:"album_name"`
AlbumURI string `json:"album_uri"`
AlbumCoverURL *string `json:"album_cover_url"`
Position int64 `json:"position"`
Duration int64 `json:"duration"`
ReleaseDate string `json:"release_date"`
TrackNumber int `json:"track_number"`
DiscNumber int `json:"disc_number"`
Format string `json:"format"`
Codec string `json:"codec"`
Bitrate *int `json:"bitrate"`
SampleRate *int `json:"sample_rate"`
BitDepth *int `json:"bit_depth"`
}
Track is a track or podcast episode.