mpd

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT-0 Imports: 8 Imported by: 0

Documentation

Overview

Package mpd provides the client side interface to MPD (Music Player Daemon).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attrs added in v0.7.1

type Attrs map[string]string

Attrs is a set of attributes returned by MPD.

type Client added in v0.7.1

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

Client represents a client connection to a MPD server.

func Dial added in v0.7.1

func Dial(network, addr string) (c *Client, err error)

Dial connects to MPD listening on address addr (e.g. "127.0.0.1:6600") on network network (e.g. "tcp").

func DialAuthenticated added in v0.7.1

func DialAuthenticated(network, addr, password string) (c *Client, err error)

DialAuthenticated connects to MPD listening on address addr (e.g. "127.0.0.1:6600") on network network (e.g. "tcp"). It then authenticates with MPD using the plaintext password password if it's not empty.

func (*Client) Add added in v0.7.1

func (c *Client) Add(uri string) error

Add adds the file/directory uri to playlist. Directories add recursively.

func (*Client) AddID added in v0.7.1

func (c *Client) AddID(uri string, pos int) (int, error)

AddID adds the file/directory uri to playlist and returns the identity id of the song added. If pos is positive, the song is added to position pos.

func (*Client) AlbumArt added in v0.7.1

func (c *Client) AlbumArt(uri string) ([]byte, error)

AlbumArt retrieves an album artwork image for a song with the given URI using MPD's albumart command.

func (*Client) BeginCommandList added in v0.7.1

func (c *Client) BeginCommandList() *CommandList

BeginCommandList creates a new CommandList structure using this connection.

func (*Client) Clear added in v0.7.1

func (c *Client) Clear() error

Clear clears the current playlist.

func (*Client) Close added in v0.7.1

func (c *Client) Close() (err error)

Close terminates the connection with MPD.

func (*Client) Command added in v0.7.1

func (c *Client) Command(format string, args ...interface{}) *Command

Command returns a command that can be sent to MPD sever. It enables low-level access to MPD protocol and should be avoided if the user is not familiar with MPD protocol.

Strings in args are automatically quoted so that spaces are preserved. Pass strings as Quoted type if this is not desired.

func (*Client) Consume added in v0.7.1

func (c *Client) Consume(consume bool) error

Consume enables consume mode, if consume is true, disables it otherwise.

func (*Client) CurrentSong added in v0.7.1

func (c *Client) CurrentSong() (Attrs, error)

CurrentSong returns information about the current song in the playlist.

func (*Client) DelPartition added in v0.7.1

func (c *Client) DelPartition(name string) error

DelPartition deletes partition with the given name.

func (*Client) Delete added in v0.7.1

func (c *Client) Delete(start, end int) error

Delete deletes songs from playlist. If both start and end are positive, it deletes those at positions in range [start, end). If end is negative, it deletes the song at position start.

func (*Client) DeleteID added in v0.7.1

func (c *Client) DeleteID(id int) error

DeleteID deletes the song identified by id.

func (*Client) DisableOutput added in v0.7.1

func (c *Client) DisableOutput(id int) error

DisableOutput disables the audio output with the given id.

func (*Client) EnableOutput added in v0.7.1

func (c *Client) EnableOutput(id int) error

EnableOutput enables the audio output with the given id.

func (*Client) Find added in v0.7.1

func (c *Client) Find(args ...string) ([]Attrs, error)

Find searches the library for songs and returns attributes for each matching song. The args are the raw arguments passed to MPD. For example, to search for songs that belong to a specific artist and album:

Find("artist", "Artist Name", "album", "Album Name")

Searches are case sensitive. Use Search for case insensitive search.

func (*Client) GetFiles added in v0.7.1

func (c *Client) GetFiles() ([]string, error)

GetFiles returns the entire list of files in MPD database.

func (*Client) Idle added in v0.7.1

func (c *Client) Idle(subsystems ...string) ([]string, error)

Idle sends waits for changes in subsystems and returns the ones that changed.

func (*Client) List added in v0.7.1

func (c *Client) List(args ...string) ([]string, error)

List searches the database for your query. You can use something simple like `artist` for your search, or something like `artist album <Album Name>` if you want the artist that has an album with a specified album name.

func (*Client) ListAllInfo added in v0.7.1

func (c *Client) ListAllInfo(uri string) ([]Attrs, error)

ListAllInfo returns attributes for songs in the library. Information about any song that is either inside or matches the passed in uri is returned. To get information about every song in the library, pass in "/".

func (*Client) ListInfo added in v0.7.1

func (c *Client) ListInfo(uri string) ([]Attrs, error)

ListInfo lists the contents of the directory URI using MPD's lsinfo command.

func (*Client) ListOutputs added in v0.7.1

func (c *Client) ListOutputs() ([]Attrs, error)

ListOutputs lists all configured outputs with their name, id & enabled state.

func (*Client) ListPartitions added in v0.7.1

func (c *Client) ListPartitions() ([]Attrs, error)

ListPartitions returns a list of partitions and their information.

func (*Client) ListPlaylists added in v0.7.1

func (c *Client) ListPlaylists() ([]Attrs, error)

ListPlaylists lists all stored playlists.

func (*Client) Move added in v0.7.1

func (c *Client) Move(start, end, position int) error

Move moves the songs between the positions start and end to the new position position. If end is negative, only the song at position start is moved.

func (*Client) MoveID added in v0.7.1

func (c *Client) MoveID(songid, position int) error

MoveID moves songid to position on the plyalist.

func (*Client) MoveOutput added in v0.7.1

func (c *Client) MoveOutput(name string) error

MoveOutput moves an output with the given name to the current partition.

func (*Client) NewPartition added in v0.7.1

func (c *Client) NewPartition(name string) error

NewPartition creates a new partition with the given name.

func (*Client) Next added in v0.7.1

func (c *Client) Next() error

Next plays next song in the playlist.

func (*Client) NoIdle added in v0.7.1

func (c *Client) NoIdle() error

NoIdle cancels the current call to Client.Idle.

func (*Client) Partition added in v0.7.1

func (c *Client) Partition(name string) error

Partition switches the client to a different partition.

func (*Client) Pause added in v0.7.1

func (c *Client) Pause(pause bool) error

Pause pauses playback if pause is true; resumes playback otherwise.

func (*Client) Ping added in v0.7.1

func (c *Client) Ping() error

Ping sends a no-op message to MPD. It's useful for keeping the connection alive.

func (*Client) Play added in v0.7.1

func (c *Client) Play(pos int) error

Play starts playing the song at playlist position pos. If pos is negative, start playing at the current position in the playlist.

func (*Client) PlayID added in v0.7.1

func (c *Client) PlayID(id int) error

PlayID plays the song identified by id. If id is negative, start playing at the current position in playlist.

func (*Client) PlaylistAdd added in v0.7.1

func (c *Client) PlaylistAdd(name string, uri string) error

PlaylistAdd adds a song identified by uri to a stored playlist identified by name.

func (*Client) PlaylistClear added in v0.7.1

func (c *Client) PlaylistClear(name string) error

PlaylistClear clears the specified playlist.

func (*Client) PlaylistContents added in v0.7.1

func (c *Client) PlaylistContents(name string) ([]Attrs, error)

PlaylistContents returns a list of attributes for songs in the specified stored playlist.

func (*Client) PlaylistDelete added in v0.7.1

func (c *Client) PlaylistDelete(name string, pos int) error

PlaylistDelete deletes the song at position pos from the specified playlist.

func (*Client) PlaylistInfo added in v0.7.1

func (c *Client) PlaylistInfo(start, end int) ([]Attrs, error)

PlaylistInfo returns attributes for songs in the current playlist. If both start and end are negative, it does this for all songs in playlist. If end is negative but start is positive, it does it for the song at position start. If both start and end are positive, it does it for positions in range [start, end).

func (*Client) PlaylistLoad added in v0.7.1

func (c *Client) PlaylistLoad(name string, start, end int) error

PlaylistLoad loads the specfied playlist into the current queue. If start and end are non-negative, only songs in this range are loaded.

func (*Client) PlaylistMove added in v0.7.1

func (c *Client) PlaylistMove(name string, id, pos int) error

PlaylistMove moves a song identified by id in a playlist identified by name to the position pos.

func (*Client) PlaylistRemove added in v0.7.1

func (c *Client) PlaylistRemove(name string) error

PlaylistRemove removes the playlist identified by name from the playlist directory.

func (*Client) PlaylistRename added in v0.7.1

func (c *Client) PlaylistRename(name, newName string) error

PlaylistRename renames the playlist identified by name to newName.

func (*Client) PlaylistSave added in v0.7.1

func (c *Client) PlaylistSave(name string) error

PlaylistSave saves the current playlist as name in the playlist directory.

func (*Client) Previous added in v0.7.1

func (c *Client) Previous() error

Previous plays previous song in the playlist.

func (*Client) Random added in v0.7.1

func (c *Client) Random(random bool) error

Random enables random playback, if random is true, disables it otherwise.

func (*Client) ReadComments added in v0.7.1

func (c *Client) ReadComments(uri string) (Attrs, error)

ReadComments reads "comments" (audio metadata) from the song URI using MPD's readcomments command.

func (*Client) ReadPicture added in v0.7.1

func (c *Client) ReadPicture(uri string) ([]byte, error)

ReadPicture retrieves the embedded album artwork image for a song with the given URI using MPD's readpicture command.

func (*Client) Repeat added in v0.7.1

func (c *Client) Repeat(repeat bool) error

Repeat enables repeat mode, if repeat is true, disables it otherwise.

func (*Client) Rescan added in v0.7.1

func (c *Client) Rescan(uri string) (jobID int, err error)

Rescan updates MPD's database like Update, but it also rescans unmodified files. uri is a particular directory or file to update. If it is an empty string, everything is updated.

The returned jobID identifies the update job, enqueued by MPD.

func (*Client) Search added in v0.7.1

func (c *Client) Search(args ...string) ([]Attrs, error)

Search behaves exactly the same as Find, but the searches are not case sensitive.

func (*Client) Seek added in v0.7.1

func (c *Client) Seek(pos, time int) error

Seek seeks to the position time (in seconds) of the song at playlist position pos. Deprecated: Use SeekPos instead.

func (*Client) SeekCur added in v0.7.1

func (c *Client) SeekCur(d time.Duration, relative bool) error

SeekCur seeks to the position d within the current song. If relative is true, then the time is relative to the current playing position.

func (*Client) SeekID added in v0.7.1

func (c *Client) SeekID(id, time int) error

SeekID is identical to Seek except the song is identified by it's id (not position in playlist). Deprecated: Use SeekSongID instead.

func (*Client) SeekPos added in v0.7.1

func (c *Client) SeekPos(pos int, d time.Duration) error

SeekPos seeks to the position d of the song at playlist position pos.

func (*Client) SeekSongID added in v0.7.1

func (c *Client) SeekSongID(id int, d time.Duration) error

SeekSongID seeks to the position d of the song identified by id.

func (*Client) SetPriority added in v0.7.1

func (c *Client) SetPriority(priority, start, end int) error

SetPriority set the priority of the specified songs. If end is negative but start is non-negative, it does it for the song at position start. If both start and end are non-negative, it does it for positions in range [start, end).

func (*Client) SetPriorityID added in v0.7.1

func (c *Client) SetPriorityID(priority, id int) error

SetPriorityID sets the prio of the song with the given id.

func (*Client) SetVolume added in v0.7.1

func (c *Client) SetVolume(volume int) error

SetVolume sets the volume to volume. The range of volume is 0-100.

func (*Client) Shuffle added in v0.7.1

func (c *Client) Shuffle(start, end int) error

Shuffle shuffles the tracks from position start to position end in the current playlist. If start or end is negative, the whole playlist is shuffled.

func (*Client) Single added in v0.7.1

func (c *Client) Single(single bool) error

Single enables single song mode, if single is true, disables it otherwise.

func (*Client) Stats added in v0.7.1

func (c *Client) Stats() (Attrs, error)

Stats displays statistics (number of artists, songs, playtime, etc)

func (*Client) Status added in v0.7.1

func (c *Client) Status() (Attrs, error)

Status returns information about the current status of MPD.

func (*Client) StickerDelete added in v0.7.1

func (c *Client) StickerDelete(uri string, name string) error

StickerDelete deletes sticker for the song with given URI.

func (*Client) StickerFind added in v0.7.1

func (c *Client) StickerFind(uri string, name string) ([]string, []Sticker, error)

StickerFind finds songs inside directory with URI which have a sticker with given name. It returns a slice of URIs of matching songs and a slice of corresponding stickers.

func (*Client) StickerGet added in v0.7.1

func (c *Client) StickerGet(uri string, name string) (*Sticker, error)

StickerGet gets sticker value for the song with given URI.

func (*Client) StickerList added in v0.7.1

func (c *Client) StickerList(uri string) ([]Sticker, error)

StickerList returns a slice of stickers for the song with given URI.

func (*Client) StickerSet added in v0.7.1

func (c *Client) StickerSet(uri string, name string, value string) error

StickerSet sets sticker value for the song with given URI.

func (*Client) Stop added in v0.7.1

func (c *Client) Stop() error

Stop stops playback.

func (*Client) Update added in v0.7.1

func (c *Client) Update(uri string) (jobID int, err error)

Update updates MPD's database: find new files, remove deleted files, update modified files. uri is a particular directory or file to update. If it is an empty string, everything is updated.

The returned jobID identifies the update job, enqueued by MPD.

func (*Client) Version added in v0.7.1

func (c *Client) Version() string

Version returns the protocol version used as provided during the handshake.

type Command added in v0.7.1

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

A Command represents a MPD command.

func (*Command) Attrs added in v0.7.1

func (cmd *Command) Attrs() (Attrs, error)

Attrs sends command to server and reads attributes returned in response.

func (*Command) AttrsList added in v0.7.1

func (cmd *Command) AttrsList(startKey string) ([]Attrs, error)

AttrsList sends command to server and reads a list of attributes returned in response. Each attribute group starts with key startKey.

func (*Command) Binary added in v0.7.1

func (cmd *Command) Binary() ([]byte, int, error)

Binary sends command to server and reads its binary response, returning the data and its total size (which can be greater than the returned chunk).

func (*Command) OK added in v0.7.1

func (cmd *Command) OK() error

OK sends command to server and checks for error.

func (*Command) String added in v0.7.1

func (cmd *Command) String() string

String returns the encoded command.

func (*Command) Strings added in v0.7.1

func (cmd *Command) Strings(key string) ([]string, error)

Strings sends command to server and reads a list of strings returned in response. Each string have the key key.

type CommandList added in v0.7.1

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

CommandList is for batch/mass MPD commands. See http://www.musicpd.org/doc/protocol/command_lists.html for more details.

func (*CommandList) Add added in v0.7.1

func (cl *CommandList) Add(uri string)

Add adds the file/directory uri to playlist. Directories add recursively.

func (*CommandList) AddID added in v0.7.1

func (cl *CommandList) AddID(uri string, pos int) *PromisedID

AddID adds the file/directory uri to playlist and returns the identity id of the song added. If pos is positive, the song is added to position pos.

func (*CommandList) Clear added in v0.7.1

func (cl *CommandList) Clear()

Clear clears the current playlist.

func (*CommandList) Consume added in v0.7.1

func (cl *CommandList) Consume(consume bool)

Consume enables consume mode, if consume is true, disables it otherwise.

func (*CommandList) CurrentSong added in v0.7.1

func (cl *CommandList) CurrentSong() *PromisedAttrs

CurrentSong returns information about the current song in the playlist.

func (*CommandList) Delete added in v0.7.1

func (cl *CommandList) Delete(start, end int) error

Delete deletes songs from playlist. If both start and end are positive, it deletes those at positions in range [start, end). If end is negative, it deletes the song at position start.

func (*CommandList) DeleteID added in v0.7.1

func (cl *CommandList) DeleteID(id int)

DeleteID deletes the song identified by id.

func (*CommandList) End added in v0.7.1

func (cl *CommandList) End() error

End executes the command list.

func (*CommandList) Move added in v0.7.1

func (cl *CommandList) Move(start, end, position int) error

Move moves the songs between the positions start and end to the new position position. If end is negative, only the song at position start is moved.

func (*CommandList) MoveID added in v0.7.1

func (cl *CommandList) MoveID(songid, position int)

MoveID moves songid to position on the playlist.

func (*CommandList) Next added in v0.7.1

func (cl *CommandList) Next()

Next plays next song in the playlist.

func (*CommandList) Pause added in v0.7.1

func (cl *CommandList) Pause(pause bool)

Pause pauses playback if pause is true; resumes playback otherwise.

func (*CommandList) Ping added in v0.7.1

func (cl *CommandList) Ping()

Ping sends a no-op message to MPD. It's useful for keeping the connection alive.

func (*CommandList) Play added in v0.7.1

func (cl *CommandList) Play(pos int)

Play starts playing the song at playlist position pos. If pos is negative, start playing at the current position in the playlist.

func (*CommandList) PlayID added in v0.7.1

func (cl *CommandList) PlayID(id int)

PlayID plays the song identified by id. If id is negative, start playing at the currect position in playlist.

func (*CommandList) PlaylistAdd added in v0.7.1

func (cl *CommandList) PlaylistAdd(name string, uri string)

PlaylistAdd adds a song identified by uri to a stored playlist identified by name.

func (*CommandList) PlaylistClear added in v0.7.1

func (cl *CommandList) PlaylistClear(name string)

PlaylistClear clears the specified playlist.

func (*CommandList) PlaylistDelete added in v0.7.1

func (cl *CommandList) PlaylistDelete(name string, pos int)

PlaylistDelete deletes the song at position pos from the specified playlist.

func (*CommandList) PlaylistLoad added in v0.7.1

func (cl *CommandList) PlaylistLoad(name string, start, end int)

PlaylistLoad loads the specfied playlist into the current queue. If start and end are non-negative, only songs in this range are loaded.

func (*CommandList) PlaylistMove added in v0.7.1

func (cl *CommandList) PlaylistMove(name string, id, pos int)

PlaylistMove moves a song identified by id in a playlist identified by name to the position pos.

func (*CommandList) PlaylistRemove added in v0.7.1

func (cl *CommandList) PlaylistRemove(name string)

PlaylistRemove removes the playlist identified by name from the playlist directory.

func (*CommandList) PlaylistRename added in v0.7.1

func (cl *CommandList) PlaylistRename(name, newName string)

PlaylistRename renames the playlist identified by name to newName.

func (*CommandList) PlaylistSave added in v0.7.1

func (cl *CommandList) PlaylistSave(name string)

PlaylistSave saves the current playlist as name in the playlist directory.

func (*CommandList) Previous added in v0.7.1

func (cl *CommandList) Previous()

Previous plays previous song in the playlist.

func (*CommandList) Random added in v0.7.1

func (cl *CommandList) Random(random bool)

Random enables random playback, if random is true, disables it otherwise.

func (*CommandList) Repeat added in v0.7.1

func (cl *CommandList) Repeat(repeat bool)

Repeat enables repeat mode, if repeat is true, disables it otherwise.

func (*CommandList) Seek added in v0.7.1

func (cl *CommandList) Seek(pos, time int)

Seek seeks to the position time (in seconds) of the song at playlist position pos.

func (*CommandList) SeekID added in v0.7.1

func (cl *CommandList) SeekID(id, time int)

SeekID is identical to Seek except the song is identified by it's id (not position in playlist).

func (*CommandList) SetPriority added in v0.7.1

func (cl *CommandList) SetPriority(priority, start, end int) error

SetPriority sets the priority for songs in the playlist. If both start and end are non-negative, it updates those at positions in range [start, end). If end is negative, it updates the song at position start.

func (*CommandList) SetPriorityID added in v0.7.1

func (cl *CommandList) SetPriorityID(priority, id int)

SetPriorityID sets the priority for the song identified by id.

func (*CommandList) SetVolume added in v0.7.1

func (cl *CommandList) SetVolume(volume int)

SetVolume sets the MPD volume level.

func (*CommandList) Shuffle added in v0.7.1

func (cl *CommandList) Shuffle(start, end int)

Shuffle shuffles the tracks from position start to position end in the current playlist. If start or end is negative, the whole playlist is shuffled.

func (*CommandList) Single added in v0.7.1

func (cl *CommandList) Single(single bool)

Single enables single song mode, if single is true, disables it otherwise.

func (*CommandList) Status added in v0.7.1

func (cl *CommandList) Status() *PromisedAttrs

Status returns information about the current status of MPD.

func (*CommandList) Stop added in v0.7.1

func (cl *CommandList) Stop()

Stop stops playback.

func (*CommandList) Update added in v0.7.1

func (cl *CommandList) Update(uri string) *PromisedAttrs

Update updates MPD's database: find new files, remove deleted files, update modified files. uri is a particular directory or file to update. If it is an empty string, everything is updated.

type Error added in v0.7.1

type Error struct {
	Code             ErrorCode
	CommandListIndex int
	CommandName      string
	Message          string
}

Error represents an error returned by the MPD server. It contains the error number, the index of the causing command in the command list, the name of the command in the command list and the error message.

func (Error) Error added in v0.7.1

func (e Error) Error() string

type ErrorCode added in v0.7.1

type ErrorCode int

ErrorCode is the error code of a Error.

const (
	ErrorNotList       ErrorCode = 1
	ErrorArg           ErrorCode = 2
	ErrorPassword      ErrorCode = 3
	ErrorPermission    ErrorCode = 4
	ErrorUnknown       ErrorCode = 5
	ErrorNoExist       ErrorCode = 50
	ErrorPlaylistMax   ErrorCode = 51
	ErrorSystem        ErrorCode = 52
	ErrorPlaylistLoad  ErrorCode = 53
	ErrorUpdateAlready ErrorCode = 54
	ErrorPlayerSync    ErrorCode = 55
	ErrorExist         ErrorCode = 56
)

ErrorCodes as defined in MPD source (https://www.musicpd.org/doc/api/html/Ack_8hxx_source.html) version 0.21.

type PromisedAttrs added in v0.7.1

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

PromisedAttrs is a set of promised attributes (to be) returned by MPD.

func (*PromisedAttrs) Value added in v0.7.1

func (pa *PromisedAttrs) Value() (Attrs, error)

Value returns the Attrs that were computed when CommandList.End was called. Returns an error if CommandList.End has not yet been called.

type PromisedID added in v0.7.1

type PromisedID int

PromisedID is a promised identifier (to be) returned by MPD.

func (*PromisedID) Value added in v0.7.1

func (pi *PromisedID) Value() (int, error)

Value returns the ID that was computed when CommandList.End was called. Returns an error if CommandList.End has not yet been called.

type Quoted added in v0.7.1

type Quoted string

Quoted is a string that do no need to be quoted.

type Sticker added in v0.7.1

type Sticker struct {
	Name, Value string
}

A Sticker represents a name/value pair associated to a song. Stickers are managed and shared by MPD clients, and MPD server does not assume any special meaning in them.

type Watcher added in v0.7.1

type Watcher struct {
	Event chan string // event channel
	Error chan error  // error channel
	// contains filtered or unexported fields
}

Watcher represents a MPD client connection that can be watched for events.

func NewWatcher added in v0.7.1

func NewWatcher(net, addr, passwd string, names ...string) (w *Watcher, err error)

NewWatcher connects to MPD server and watches for changes in subsystems names. If no subsystem is specified, all changes are reported.

See http://www.musicpd.org/doc/protocol/command_reference.html#command_idle for valid subsystem names.

func (*Watcher) Close added in v0.7.1

func (w *Watcher) Close() error

Close closes Event and Error channels, and the connection to MPD server.

func (*Watcher) Subsystems added in v0.7.1

func (w *Watcher) Subsystems(names ...string)

Subsystems interrupts watching current subsystems, consumes all outstanding values from Event and Error channels, and then changes the subsystems to watch for to names.

Jump to

Keyboard shortcuts

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