mpd

package module
v0.0.0-...-1dc7852 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2016 License: GPL-3.0 Imports: 18 Imported by: 2

README

A Go package to implement an MPD server (this is not a working server by itself).

Documentation

Index

Constants

View Source
const (
	StateStop = iota
	StatePlay
	StatePause
)
View Source
const (
	MpdNotListErrorCode        = 1
	MpdArgErrorCode            = 2
	MpdPasswordErrorCode       = 3
	MpdPermissionErrorCode     = 4
	MpdUnknownCommandErrorCode = 5
	MpdNoExistErrorCode        = 50
	MpdPlaylistMaxErrorCode    = 51
	MpdSystemErrorCode         = 52
	MpdPlaylistLoadErrorCode   = 53
	MpdUpdateAlreadyErrorCode  = 54
	MpdPlayerSyncErrorCode     = 55
	MpdExistErrorCode          = 56
)

Standard MPD error codes.

Variables

View Source
var (

	// Common errors.
	ErrBadArgs           = &MpdError{Code: MpdArgErrorCode, Message: "bad arguments"}
	ErrNoCommandGiven    = &MpdError{Code: MpdUnknownCommandErrorCode, Message: "No command given"}
	ErrUnsupportedScheme = &MpdError{Code: MpdNoExistErrorCode, Message: "unsupported URL scheme"}
)

Functions

func Decode

func Decode(src io.ReadCloser, format string) (io.ReadCloser, error)

Decode an io.Reader using avconv/ffmpeg.

func NewPortAudioPlayer

func NewPortAudioPlayer(provider SongProvider, notifier SongPlayNotifier) *portAudioPlayer

Types

type CommandFunc

type CommandFunc func(w io.Writer, args []string) error

CommandFunc turns a function into a Handler.

func (CommandFunc) ServeMPD

func (f CommandFunc) ServeMPD(w io.Writer, args []string) error

type Database

type Database interface {
	// Find an exact match for the query.
	Find(args []string) ([]Song, error)

	// Search the database with the given query.
	Search(args []string) ([]Song, error)
}

Database is used to search for songs. Queries are encoded according to the MPD protocol, consisting of paired tag/query fields, and must be decoded by the implementation.

type Handler

type Handler interface {
	ServeMPD(w io.Writer, args []string) error
}

Objects implementing the Handler interface can be registered with a Mux to handle a particular MPD command. The command should do its own argument parsing (returning ErrBadArgs in case of errors), and write its output to the specified io.Writer.

type MPD

type MPD struct {
	*Server

	// Tag types. Currently not used.
	TagTypes []string
	// contains filtered or unexported fields
}

MPD server. Implements most of the commands of a real server, but it is oriented towards searching rather than browsing (that is to say, browsing is currently unimplemented).

func NewMPD

func NewMPD(db Database, notifier SongPlayNotifier) *MPD

func (*MPD) HandleURL

func (m *MPD) HandleURL(schema string, h URLHandler)

HandleURL installs a new URLHandler.

type MpdError

type MpdError struct {
	Code    int
	CmdNum  int
	Cmd     string
	Message string
}

An MPD error, with command details. Its Error method will return the error formatted according to the MPD protocol (an ACK reply).

func (*MpdError) Error

func (e *MpdError) Error() string

type Mux

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

Mux is a multiplexer for MPD commands. Handlers can be registered to deal with specific commands.

func NewMux

func NewMux() *Mux

func (*Mux) Handle

func (m *Mux) Handle(name string, c Handler)

Handle installs a new command handler.

func (*Mux) HandleFunc

func (m *Mux) HandleFunc(name string, f func(io.Writer, []string) error)

HandleFunc installs a new command handler (saving a cast to CommandFunc).

func (*Mux) ServeMPD

func (m *Mux) ServeMPD(w io.Writer, args []string) error

type Output

type Output struct {
	Name    string
	ID      int
	Enabled bool
}

Audio device.

type PlayerState

type PlayerState int

func (PlayerState) String

func (s PlayerState) String() string

type Playlist

type Playlist struct {
	Version int
	// contains filtered or unexported fields
}

A Playlist contains an ordered list of songs, and a cursor.

func NewPlaylist

func NewPlaylist() *Playlist

func (*Playlist) Add

func (p *Playlist) Add(s Song, before int) int

Add adds a new song to the playlist, returns the song ID.

func (*Playlist) ChangesPosID

func (p *Playlist) ChangesPosID(w io.Writer, oldver int)

ChangesPosID prints to w the difference between the specified playlist version and the current one, encoded in the differential format specified by the MPD protocol. At the moment, since playlist history is not supported, this function pretends that the playlist changed completely.

func (*Playlist) Clear

func (p *Playlist) Clear()

Clear the playlist.

func (*Playlist) Delete

func (p *Playlist) Delete(r Range)

Delete a range of songs from the playlist.

func (*Playlist) DeleteID

func (p *Playlist) DeleteID(id int)

DeleteID removes a specific song from the playlist.

func (*Playlist) Find

func (p *Playlist) Find(w io.Writer, tag, needle string)

Find runs a literal query on the current playlist.

func (*Playlist) Info

func (p *Playlist) Info(w io.Writer)

Info dumps information about all the songs in the playlist to w.

func (*Playlist) InfoID

func (p *Playlist) InfoID(w io.Writer, id int)

InfoID dumps information about a song to w.

func (*Playlist) InfoRange

func (p *Playlist) InfoRange(w io.Writer, r Range)

Info dumps information about the songs in the specified range.

func (*Playlist) Len

func (p *Playlist) Len() int

Len returns the number of songs currently in the playlist.

func (*Playlist) Move

func (p *Playlist) Move(from Range, to int)

Move the song at position from to position to.

func (*Playlist) MoveID

func (p *Playlist) MoveID(id, to int)

Move the specified song to position to.

func (*Playlist) Next

func (p *Playlist) Next() SongFromPlaylist

Next advances the cursor to the next song and returns it.

func (*Playlist) PeekNext

func (p *Playlist) PeekNext() SongFromPlaylist

PeekNext looks at the next iteration of the cursor, but does not advance it.

func (*Playlist) Prev

func (p *Playlist) Prev() SongFromPlaylist

Prev moves the cursor back to the previous song and returns it.

func (*Playlist) Random

func (p *Playlist) Random() bool

Random returns the current state of the playlist random mode.

func (*Playlist) Repeat

func (p *Playlist) Repeat() bool

Repeat returns the current state of the playlist repeat mode.

func (*Playlist) SetCursor

func (p *Playlist) SetCursor(idx int) SongFromPlaylist

SetCursor moves the cursor to point at the specified song, and returns it.

func (*Playlist) SetCursorID

func (p *Playlist) SetCursorID(id int) SongFromPlaylist

SetCursorID moves the cursor to point at the specified song (using its ID), and returns it.

func (*Playlist) SetRandom

func (p *Playlist) SetRandom(state bool)

SetRandom sets the playlist random mode on or off.

func (*Playlist) SetRepeat

func (p *Playlist) SetRepeat(state bool)

SetRepeat toggles the playlist repeat mode.

func (*Playlist) Swap

func (p *Playlist) Swap(from, to int)

Swap the position of two songs.

func (*Playlist) SwapID

func (p *Playlist) SwapID(id, to int)

SwapID changes the position of two songs (the first song is specified with its ID).

type Range

type Range struct {
	Start, End int
}

Range represents a range of song indexes. The END item is not included in the range.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses a START:END integer range according to the MPD protocol spec. Note that in the MPD specification, the END element is included in the range.

func (*Range) Bound

func (r *Range) Bound(slicelen int)

Bound the range to match a given slice (if it extends beyond it, it will be limited).

func (Range) Contains

func (r Range) Contains(i int) bool

func (Range) Len

func (r Range) Len() int

Len returns the total size of the range.

type Server

type Server struct {
	*Mux
	// contains filtered or unexported fields
}

A server that speaks the MPD protocol.

func NewServer

func NewServer() *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the MPD server on the specified TCP address and runs our Mux to handle incoming commands.

func (*Server) Trigger

func (s *Server) Trigger(tag string)

Trigger sends a notification about 'tag' to all available subscribers (clients in idle mode).

type Song

type Song interface {
	// URL returns a unique identifier for this song.
	URL() string

	// Info returns a string with the song metadata formatted
	// according to the MPD protocol.
	Info() string

	// Open the audio file and return it (in the original format,
	// which will be decoded by the player). The caller must call
	// Close() on the result.
	Open() (io.ReadCloser, error)

	Channels() int
	SampleRate() float64
	Duration() int
}

A song, with associated metadata and audio resource.

type SongCallbackFunc

type SongCallbackFunc func() SongFromPlaylist

A function that returns the next song to be played.

type SongFromPlaylist

type SongFromPlaylist interface {
	Song

	// ID returns the song id in the playlist.
	ID() int

	// Index of this song in the playlist.
	Index() int

	// Song returns the wrapped Song.
	GetSong() Song
}

A song, with associated playlist information.

type SongPlayNotifier

type SongPlayNotifier interface {
	Notify(Song)
}

type SongPlayedCallbackFunc

type SongPlayedCallbackFunc func(Song)

Callback called when a song has been successfully played in its entirety.

type SongProvider

type SongProvider interface {
	Next() SongFromPlaylist
}

type URLHandler

type URLHandler interface {
	// GetSong returns the Song identified by the given url.
	GetSong(songURL *url.URL) (Song, error)
}

A URLHandler is associated with a specific URL scheme, and it is used to retrieve songs (possibly from a database).

Jump to

Keyboard shortcuts

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