Documentation ¶
Overview ¶
Package mpd provides the client side interface to MPD (Music Player Daemon). The protocol reference can be found at http://www.musicpd.org/doc/protocol/index.html
Index ¶
- type Attrs
- type Client
- func (c *Client) Add(uri string) error
- func (c *Client) AddId(uri string, pos int) (int, error)
- func (c *Client) BeginCommandList() *CommandList
- func (c *Client) Clear() error
- func (c *Client) Close() (err error)
- func (c *Client) CurrentSong() (Attrs, error)
- func (c *Client) Delete(start, end int) error
- func (c *Client) DeleteId(id int) error
- func (c *Client) DisableOutput(id int) error
- func (c *Client) EnableOutput(id int) error
- func (c *Client) Find(uri string) ([]Attrs, error)
- func (c *Client) GetFiles() ([]string, error)
- func (c *Client) List(uri string) ([]string, error)
- func (c *Client) ListAllInfo(uri string) ([]Attrs, error)
- func (c *Client) ListInfo(uri string) ([]Attrs, error)
- func (c *Client) ListOutputs() ([]Attrs, error)
- func (c *Client) ListPlaylists() ([]Attrs, error)
- func (c *Client) Move(start, end, position int) error
- func (c *Client) MoveId(songid, position int) error
- func (c *Client) Next() error
- func (c *Client) Pause(pause bool) error
- func (c *Client) Ping() error
- func (c *Client) Play(pos int) error
- func (c *Client) PlayId(id int) error
- func (c *Client) PlaylistAdd(name string, uri string) error
- func (c *Client) PlaylistClear(name string) error
- func (c *Client) PlaylistContents(name string) ([]Attrs, error)
- func (c *Client) PlaylistDelete(name string, pos int) error
- func (c *Client) PlaylistInfo(start, end int) ([]Attrs, error)
- func (c *Client) PlaylistLoad(name string, start, end int) error
- func (c *Client) PlaylistMove(name string, id, pos int) error
- func (c *Client) PlaylistRemove(name string) error
- func (c *Client) PlaylistRename(name, newName string) error
- func (c *Client) PlaylistSave(name string) error
- func (c *Client) Previous() error
- func (c *Client) Random(random bool) error
- func (c *Client) Repeat(repeat bool) error
- func (c *Client) Seek(pos, time int) error
- func (c *Client) SeekId(id, time int) error
- func (c *Client) SetVolume(volume int) error
- func (c *Client) Shuffle(start, end int) error
- func (c *Client) Stats() (Attrs, error)
- func (c *Client) Status() (Attrs, error)
- func (c *Client) Stop() error
- func (c *Client) Update(uri string) (jobID int, err error)
- type CommandList
- func (cl *CommandList) Add(uri string)
- func (cl *CommandList) AddId(uri string, pos int) *PromisedId
- func (cl *CommandList) Clear()
- func (cl *CommandList) CurrentSong() *PromisedAttrs
- func (cl *CommandList) Delete(start, end int) error
- func (cl *CommandList) DeleteId(id int)
- func (cl *CommandList) End() error
- func (cl *CommandList) Move(start, end, position int) error
- func (cl *CommandList) MoveId(songid, position int)
- func (cl *CommandList) Next()
- func (cl *CommandList) Pause(pause bool)
- func (cl *CommandList) Ping()
- func (cl *CommandList) Play(pos int)
- func (cl *CommandList) PlayId(id int)
- func (cl *CommandList) PlaylistAdd(name string, uri string)
- func (cl *CommandList) PlaylistClear(name string)
- func (cl *CommandList) PlaylistDelete(name string, pos int)
- func (cl *CommandList) PlaylistLoad(name string, start, end int)
- func (cl *CommandList) PlaylistMove(name string, id, pos int)
- func (cl *CommandList) PlaylistRemove(name string)
- func (cl *CommandList) PlaylistRename(name, newName string)
- func (cl *CommandList) PlaylistSave(name string)
- func (cl *CommandList) Previous()
- func (cl *CommandList) Random(random bool)
- func (cl *CommandList) Repeat(repeat bool)
- func (cl *CommandList) Seek(pos, time int)
- func (cl *CommandList) SeekId(id, time int)
- func (cl *CommandList) SetVolume(volume int)
- func (cl *CommandList) Shuffle(start, end int)
- func (cl *CommandList) Status() *PromisedAttrs
- func (cl *CommandList) Stop()
- func (cl *CommandList) Update(uri string) (attrs *PromisedAttrs)
- type PromisedAttrs
- type PromisedId
- type Watcher
- Bugs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a client connection to a MPD server.
func Dial ¶
Dial connects to MPD listening on address addr (e.g. "127.0.0.1:6600") on network network (e.g. "tcp").
Example ¶
// Connect to MPD server conn, err := Dial("tcp", "localhost:6600") if err != nil { log.Fatalln(err) } defer conn.Close() line := "" line1 := "" // Loop printing the current status of MPD. for { status, err := conn.Status() if err != nil { log.Fatalln(err) } song, err := conn.CurrentSong() if err != nil { log.Fatalln(err) } if status["state"] == "play" { line1 = fmt.Sprintf("%s - %s", song["Artist"], song["Title"]) } else { line1 = fmt.Sprintf("State: %s", status["state"]) } if line != line1 { line = line1 fmt.Println(line) } time.Sleep(1e9) }
Output:
func DialAuthenticated ¶
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) AddId ¶
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) BeginCommandList ¶
func (c *Client) BeginCommandList() *CommandList
BeginCommandList creates a new CommandList structure using this connection.
func (*Client) CurrentSong ¶
CurrentSong returns information about the current song in the playlist.
func (*Client) Delete ¶
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) DisableOutput ¶
DisableOutput disables the audio output with the given id.
func (*Client) EnableOutput ¶
EnableOutput enables the audio output with the given id.
func (*Client) Find ¶
Find returns attributes for songs in the library. You can find songs that belong to an artist and belong to the album by searching: `find artist "<Artist>" album "<Album>"`
func (*Client) List ¶
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 ¶
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 ¶
ListInfo lists the contents of the directory URI using MPD's lsinfo command.
func (*Client) ListOutputs ¶
ListOutputs lists all configured outputs with their name, id & enabled state.
func (*Client) ListPlaylists ¶
ListPlaylists lists all stored playlists.
func (*Client) Move ¶
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) Ping ¶
Ping sends a no-op message to MPD. It's useful for keeping the connection alive.
func (*Client) Play ¶
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 ¶
PlayId plays the song identified by id. If id is negative, start playing at the current position in playlist.
func (*Client) PlaylistAdd ¶
PlaylistAdd adds a song identified by uri to a stored playlist identified by name.
func (*Client) PlaylistClear ¶
PlaylistClear clears the specified playlist.
func (*Client) PlaylistContents ¶
PlaylistContents returns a list of attributes for songs in the specified stored playlist.
func (*Client) PlaylistDelete ¶
PlaylistDelete deletes the song at position pos from the specified playlist.
func (*Client) PlaylistInfo ¶
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 ¶
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 ¶
PlaylistMove moves a song identified by id in a playlist identified by name to the position pos.
func (*Client) PlaylistRemove ¶
PlaylistRemove removes the playlist identified by name from the playlist directory.
func (*Client) PlaylistRename ¶
PlaylistRename renames the playlist identified by name to newName.
func (*Client) PlaylistSave ¶
PlaylistSave saves the current playlist as name in the playlist directory.
func (*Client) Seek ¶
Seek seeks to the position time (in seconds) of the song at playlist position pos.
func (*Client) SeekId ¶
SeekId is identical to Seek except the song is identified by it's id (not position in playlist).
func (*Client) Shuffle ¶
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.
type CommandList ¶
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 ¶
func (cl *CommandList) Add(uri string)
Add adds the file/directory uri to playlist. Directories add recursively.
func (*CommandList) AddId ¶
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) CurrentSong ¶
func (cl *CommandList) CurrentSong() *PromisedAttrs
CurrentSong returns information about the current song in the playlist.
func (*CommandList) Delete ¶
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 ¶
func (cl *CommandList) DeleteId(id int)
DeleteId deletes the song identified by id.
func (*CommandList) Move ¶
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 ¶
func (cl *CommandList) MoveId(songid, position int)
MoveId moves songid to position on the playlist.
func (*CommandList) Pause ¶
func (cl *CommandList) Pause(pause bool)
Pause pauses playback if pause is true; resumes playback otherwise.
func (*CommandList) Ping ¶
func (cl *CommandList) Ping()
Ping sends a no-op message to MPD. It's useful for keeping the connection alive.
func (*CommandList) Play ¶
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 ¶
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 ¶
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 ¶
func (cl *CommandList) PlaylistClear(name string)
PlaylistClear clears the specified playlist.
func (*CommandList) PlaylistDelete ¶
func (cl *CommandList) PlaylistDelete(name string, pos int)
PlaylistDelete deletes the song at position pos from the specified playlist.
func (*CommandList) PlaylistLoad ¶
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 ¶
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 ¶
func (cl *CommandList) PlaylistRemove(name string)
PlaylistRemove removes the playlist identified by name from the playlist directory.
func (*CommandList) PlaylistRename ¶
func (cl *CommandList) PlaylistRename(name, newName string)
PlaylistRename renames the playlist identified by name to newName.
func (*CommandList) PlaylistSave ¶
func (cl *CommandList) PlaylistSave(name string)
PlaylistSave saves the current playlist as name in the playlist directory.
func (*CommandList) Previous ¶
func (cl *CommandList) Previous()
Previous plays previous song in the playlist.
func (*CommandList) Random ¶
func (cl *CommandList) Random(random bool)
Random enables random playback, if random is true, disables it otherwise.
func (*CommandList) Repeat ¶
func (cl *CommandList) Repeat(repeat bool)
Repeat enables reapeat mode, if repeat is true, disables it otherwise.
func (*CommandList) Seek ¶
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 ¶
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) SetVolume ¶
func (cl *CommandList) SetVolume(volume int)
SetVolume sets the MPD volume level.
func (*CommandList) Shuffle ¶
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) Status ¶
func (cl *CommandList) Status() *PromisedAttrs
Status returns information about the current status of MPD.
func (*CommandList) Update ¶
func (cl *CommandList) Update(uri string) (attrs *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 PromisedAttrs ¶
type PromisedAttrs struct {
// contains filtered or unexported fields
}
PromisedAttrs is a set of promised attributes (to be) returned by MPD.
func (*PromisedAttrs) Value ¶
func (pa *PromisedAttrs) Value() (Attrs, error)
Value is a convenience method for ensuring that a promise has been computed, returning the Attrs.
type PromisedId ¶
type PromisedId int
PromisedId is a promised identifier (to be) returned by MPD.
func (*PromisedId) Value ¶
func (pi *PromisedId) Value() (int, error)
Value is a convenience method for ensuring that a promise has been computed, returning the ID.
type Watcher ¶
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 ¶
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.
Example ¶
w, err := NewWatcher("tcp", ":6600", "") if err != nil { log.Fatalln(err) } defer w.Close() // Log errors. go func() { for err := range w.Error { log.Println("Error:", err) } }() // Log events. go func() { for subsystem := range w.Event { log.Println("Changed subsystem:", subsystem) } }() // Do other stuff... time.Sleep(3 * time.Minute)
Output:
func (*Watcher) Subsystems ¶
Subsystems interrupts watching current subsystems, consumes all outstanding values from Event and Error channels, and then changes the subsystems to watch for to names.
Notes ¶
Bugs ¶
Initialism is used for several methods with "ID" in the name (e.g. PlayId should be PlayID).