mpd

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 11 Imported by: 0

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

View Source
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

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

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

func DialAuthenticated

func DialAuthenticated(network, addr, password string) (*Client, 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) Close added in v0.4.1

func (c *Client) Close() error

Close closes the client.

func (*Client) CurrentSong

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

CurrentSong returns information about the current song in the playlist.

func (*Client) FileFromAttrs added in v0.3.0

func (c *Client) FileFromAttrs(attr mpd.Attrs) (s File, err error)

FileFromAttrs returns a File from the attributes map.

func (*Client) Find

func (c *Client) Find(args ...string) ([]File, 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) ItemFromAttrs added in v0.3.0

func (c *Client) ItemFromAttrs(attr mpd.Attrs) (Item, error)

ItemFromAttrs returns an Item from the given Attr struct.

func (*Client) Keepalive added in v0.4.1

func (c *Client) Keepalive(ctx context.Context)

Keepalive keeps the client alive with pings until `ctx` is done.

func (*Client) ListAllInfo

func (c *Client) ListAllInfo(uri string) ([]Item, 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

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

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

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

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

func (*Client) PlaylistInfo

func (c *Client) PlaylistInfo(start, end int) ([]File, 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) SongFromAttrs added in v0.3.0

func (c *Client) SongFromAttrs(attr mpd.Attrs) (s Song, err error)

SongFromAttrs returns a song from the attributes map.

func (*Client) Stats

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

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

func (*Client) Status

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

Status returns information about the current status of MPD.

type Directory

type Directory struct {
	Attrs mpd.Attrs
}

Directory represents a directory in the library.

func (Directory) Path

func (d Directory) Path() string

Path returns the path to the directory.

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.

func (File) Path

func (f File) Path() string

Path returns the path to the 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

type PlaylistFile struct {
	Attrs mpd.Attrs
}

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

func (s Song) AlbumArtURI() (string, bool)

AlbumArtURI returns the URI to the album art, if it is available.

func (*Song) SameAs added in v0.3.1

func (s *Song) SameAs(other *Song) bool

SameAs checks if both songs are the same.

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.

func StatsFromAttrs

func StatsFromAttrs(attr mpd.Attrs) (s Stats, err error)

StatsFromAttrs returns a Stats struct from the given attrs.

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.

func StatusFromAttrs

func StatusFromAttrs(attr mpd.Attrs) (s Status, err error)

StatusFromAttrs returns a Status struct from the given attrs.

type Watcher added in v0.4.1

type Watcher struct {
	*mpd.Watcher
}

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

func NewWatcher(net, addr, passwd string) (*Watcher, error)

NewWatcher creates a new watcher with the given parameters.

func (*Watcher) Poll added in v0.4.1

func (w *Watcher) Poll(ctx context.Context) error

Poll waits for the next event, or errors out.

Jump to

Keyboard shortcuts

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