engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package engine runs the go-librespot player inside the spotui process. It plays audio on this machine and shows up as a Spotify Connect device.

The go-librespot daemon normally takes commands over HTTP. Here it gets a channel-based server instead, so commands are plain method calls and events arrive on a Go channel.

Index

Constants

View Source
const LevelTrace = slog.Level(-8)

LevelTrace is below slog's debug level. go-librespot logs every packet at this level.

Variables

View Source
var ErrNotReady = errors.New("player is not ready")

ErrNotReady means the player did not take the request in time, usually because it is still logging in.

Functions

func LikedSongsURI

func LikedSongsURI(username string) string

LikedSongsURI is the context URI of the user's Liked Songs.

func Logout

func Logout(statePath string) error

Logout removes the saved Spotify login from the state file. The next start asks the user to log in again.

func NewLogger

func NewLogger(l *slog.Logger) librespot.Logger

NewLogger returns a go-librespot logger that writes to l.

Types

type AuthCode

type AuthCode struct {
	URL       string
	Code      string
	ExpiresAt time.Time
}

AuthCode asks the user to approve the login. The engine sends it when no saved credentials exist. A nil URL means the login code is no longer needed.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine owns the embedded player.

func New

func New(opts Options) *Engine

New creates an engine. Call Run to start it.

func (*Engine) AdjustVolume

func (e *Engine) AdjustVolume(ctx context.Context, delta int32) error

AdjustVolume changes the volume by delta percent.

func (*Engine) ContextTracks

func (e *Engine) ContextTracks(ctx context.Context, uri string) (*daemon.ApiContextTracks, error)

ContextTracks lists the tracks of a playlist, album, artist, or Liked Songs URI. The list fills in over several calls: call again while Ready is false or Cached is less than Length.

func (*Engine) Events

func (e *Engine) Events() <-chan any

Events returns the channel of engine events: *daemon.ApiEvent, AuthCode, and Stopped values.

func (*Engine) LibraryPlaylists

func (e *Engine) LibraryPlaylists(ctx context.Context) ([]daemon.ApiLibraryPlaylist, error)

LibraryPlaylists returns the playlists in the user's library, including playlists the user follows but does not own.

func (*Engine) Next

func (e *Engine) Next(ctx context.Context) error

Next skips to the next track.

func (*Engine) Play

func (e *Engine) Play(ctx context.Context, uri, skipTo string) error

Play plays a track, album, playlist, or artist URI. If skipTo is set, the context starts at that track.

func (*Engine) PlayPause

func (e *Engine) PlayPause(ctx context.Context) error

PlayPause toggles between playing and paused.

func (*Engine) Prev

func (e *Engine) Prev(ctx context.Context) error

Prev goes to the previous track, or to the start of the current track if it has played for more than a few seconds.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

Run starts the player and blocks until ctx is cancelled. If the player stops because of an error, Run starts it again after a growing delay.

func (*Engine) Seek

func (e *Engine) Seek(ctx context.Context, deltaMs int64) error

Seek moves the playback position by deltaMs milliseconds.

func (*Engine) SetRepeat

func (e *Engine) SetRepeat(ctx context.Context, mode RepeatMode) error

SetRepeat sets the repeat mode.

func (*Engine) SetShuffle

func (e *Engine) SetShuffle(ctx context.Context, on bool) error

SetShuffle turns shuffle on or off for the current context.

func (*Engine) Status

func (e *Engine) Status(ctx context.Context) (*daemon.ApiStatus, error)

Status returns the current playback state.

type Options

type Options struct {
	DeviceName    string
	AudioBackend  string
	AudioDevice   string
	Bitrate       int
	InitialVolume int
	StatePath     string
	Logger        librespot.Logger
}

Options configures the engine.

type RepeatMode

type RepeatMode int

RepeatMode is the repeat setting.

const (
	RepeatOff RepeatMode = iota
	RepeatContext
	RepeatTrack
)

type Stopped

type Stopped struct {
	Err   error
	Retry time.Duration
}

Stopped reports that the player stopped. The engine restarts it after a short wait.

Jump to

Keyboard shortcuts

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