api

package
v0.0.0-...-c967b71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api is a small client for the go-librespot daemon HTTP API.

Index

Constants

View Source
const MaxLikedQuery = 50

MaxLikedQuery is how many URIs one Liked query may carry.

Variables

View Source
var (
	// ErrContextTracksUnavailable is returned when the daemon does not serve
	// /context/tracks (older version or metadata.enabled is false).
	ErrContextTracksUnavailable = errors.New("context track listing unavailable")
	// ErrLibraryUnavailable is returned when the daemon does not serve
	// /library/playlists.
	ErrLibraryUnavailable = errors.New("library listing unavailable")
	// ErrLibraryWriteUnavailable is returned when the daemon cannot write to
	// Liked Songs or playlists.
	ErrLibraryWriteUnavailable = errors.New("daemon cannot write to the library")
	// ErrLikedUnavailable is returned when the daemon cannot tell which
	// tracks are liked.
	ErrLikedUnavailable = errors.New("liked state unavailable")
	// ErrContainsUnavailable is returned when the daemon cannot tell whether
	// 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

func New(base string) *Client

New creates a client for the daemon at base, e.g. "http://localhost:3678".

func (*Client) AddToPlaylist

func (c *Client) AddToPlaylist(ctx context.Context, playlistURI string, uris []string) error

AddToPlaylist appends uris to the end of a playlist.

func (*Client) AddToQueue

func (c *Client) AddToQueue(ctx context.Context, uri string) error

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) Base

func (c *Client) Base() string

Base returns the daemon base URL.

func (*Client) ContextTracks

func (c *Client) ContextTracks(ctx context.Context, uri string) (*ContextTracks, error)

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

func (c *Client) CreatePlaylist(ctx context.Context, name string) (string, error)

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) Liked

func (c *Client) Liked(ctx context.Context, uris []string) (map[string]bool, error)

Liked tells for each of uris whether it is in Liked Songs.

func (*Client) Next

func (c *Client) Next(ctx context.Context) error

func (*Client) Play

func (c *Client) Play(ctx context.Context, uri, skipTo string) error

Play starts playing uri; skipTo optionally selects a track within a context.

func (*Client) PlayPause

func (c *Client) PlayPause(ctx context.Context) error

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) Prev

func (c *Client) Prev(ctx context.Context) error

func (*Client) Ready

func (c *Client) Ready(ctx context.Context) (bool, error)

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

func (c *Client) RemovePlaylist(ctx context.Context, playlistURI string) error

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) Seek

func (c *Client) Seek(ctx context.Context, posMs int64, relative bool) error

func (*Client) SetLiked

func (c *Client) SetLiked(ctx context.Context, uris []string, liked bool) error

SetLiked saves uris to, or removes them from, Liked Songs.

func (*Client) SetRepeatContext

func (c *Client) SetRepeatContext(ctx context.Context, on bool) error

func (*Client) SetRepeatTrack

func (c *Client) SetRepeatTrack(ctx context.Context, on bool) error

func (*Client) SetShuffle

func (c *Client) SetShuffle(ctx context.Context, on bool) error

func (*Client) SetVolume

func (c *Client) SetVolume(ctx context.Context, vol int, relative bool) error

func (*Client) Status

func (c *Client) Status(ctx context.Context) (*Status, error)

Status returns the player status, or nil when there is no active session.

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

type ContextTrackItem struct {
	URI   string `json:"uri"`
	Track *Track `json:"track"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL