Documentation ¶
Overview ¶
Package mpd provides a higher-level implementation of some features of the lower-level `github.com/fhs/gompd/v2/mpd` package.
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) CurrentSong() (Song, error)
- func (c *Client) FileFromAttrs(attr mpd.Attrs) (s File, err error)
- func (c *Client) Find(args ...string) ([]File, error)
- func (c *Client) ItemFromAttrs(attr mpd.Attrs) (Item, error)
- func (c *Client) Keepalive(ctx context.Context)
- func (c *Client) ListAllInfo(uri string) ([]Item, error)
- func (c *Client) ListInfo(uri string) ([]Item, error)
- func (c *Client) ListPlaylists() ([]PlaylistFile, error)
- func (c *Client) PlaylistContents(name string) ([]File, error)
- func (c *Client) PlaylistInfo(start, end int) ([]File, error)
- func (c *Client) SongFromAttrs(attr mpd.Attrs) (s Song, err error)
- func (c *Client) Stats() (Stats, error)
- func (c *Client) Status() (Status, error)
- type Directory
- type File
- type Item
- type PlaylistFile
- type Song
- type Stats
- type Status
- type Watcher
Constants ¶
const KeepaliveTimeoutDefault = 25 * time.Second
KeepaliveTimeout is the time between pings to keep the connection alive. As MPD recommends a 30 second timeout for connection (https://mpd.readthedocs.io/en/latest/client.html#environment-variables), we keep something similar here. However, if we detect `MPD_TIMEOUT`, we set the corresponding timeout.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { *mpd.Client *Watcher Address string MusicDirectory string // contains filtered or unexported fields }
Client represents a MPD client. Some of the methods are overriden from the `mpd.Client` struct to provide typings safety.
func Dial ¶
Dial connects to MPD listening on address addr (e.g. "127.0.0.1:6600") on network network (e.g. "tcp").
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) CurrentSong ¶
CurrentSong returns information about the current song in the playlist.
func (*Client) FileFromAttrs ¶ added in v0.3.0
FileFromAttrs returns a File from the attributes map.
func (*Client) Find ¶
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) ItemFromAttrs ¶ added in v0.3.0
ItemFromAttrs returns an Item from the given Attr struct.
func (*Client) Keepalive ¶ added in v0.4.1
Keepalive keeps the client alive with pings until `ctx` is done.
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) ListPlaylists ¶
func (c *Client) ListPlaylists() ([]PlaylistFile, error)
ListPlaylists lists all stored playlists.
func (*Client) PlaylistContents ¶
PlaylistContents returns a list of attributes for songs in the specified stored 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) SongFromAttrs ¶ added in v0.3.0
SongFromAttrs returns a song from the attributes map.
type File ¶
type File struct { Title string Artist string Genre string Date string // Has non-standard time format Album string AlbumArtist string Track int Duration time.Duration Filepath string // The file:// URL Attrs mpd.Attrs // Other attributes }
File represents a music file.
type Item ¶
type Item interface { // The path to the item, relative to the library's root. Path() string }
Item represents an item in the file system. It could either be a File, a Directory or a PlaylistFile.
type PlaylistFile ¶
PlaylistFile represents a Playlist in the library. No metadata about the playlist is stored here, only the file's information.
func (PlaylistFile) Path ¶
func (p PlaylistFile) Path() string
Path returns the path to the directory.
type Song ¶
type Song struct { File ID int // The song's ID (within the playlist) // contains filtered or unexported fields }
Song represents a music file with metadata.
func (Song) AlbumArtURI ¶ added in v0.3.0
AlbumArtURI returns the URI to the album art, if it is available.
type Stats ¶
type Stats struct { Uptime time.Duration PlayTime time.Duration Artists int Albums int Songs int Attrs mpd.Attrs }
Stats stores statistics of the mpd instance.
type Status ¶
type Status struct { Volume int Repeat bool Random bool Single bool Consume bool PlaylistLength time.Duration State string Song int Seek time.Duration NextSong int Attrs mpd.Attrs Seekable bool // Whether we can seek the current song }
Status represents mpd's current status.
type Watcher ¶ added in v0.4.1
Watcher is our implementation of the watcher. It automatically subscribes to MPRIS-related events and `Poll` can be used to wait for any event.
func NewWatcher ¶ added in v0.4.1
NewWatcher creates a new watcher with the given parameters.