mmpd

package module
v0.0.0-...-b8f44a5 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 11 Imported by: 0

README

:toc: macro

image:https://goreportcard.com/badge/github.com/mkke/mmpd["Go Report Card", link="https://goreportcard.com/report/mkke/mmpd"]
image:https://godoc.org/github.com/mkke/mmpd?status.svg["GoDoc", link="https://godoc.org/github.com/mkke/mmpd"]

## Music Player Daemon (mpd) client enhancements

This module contains some enhancements meant to be used with github.com/fhs/gompd/v2.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConnected = errors.New("not connected")

Functions

func Ping

func Ping(client *ReconnectingClient) error

func RefreshCache

func RefreshCache(client *ReconnectingClient) error

func StringsForSubsystems

func StringsForSubsystems(subsystems []Subsystem) (strings []string)

Types

type ClientCache

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

func NewClientCache

func NewClientCache() *ClientCache

func (*ClientCache) GetOrCreate

func (cc *ClientCache) GetOrCreate(network, addr string, options ...ClientOption) (*ClientCacheEntry, error)

func (*ClientCache) Shutdown

func (cc *ClientCache) Shutdown()

type ClientCacheEntry

type ClientCacheEntry struct {
	NetAddr NetAddr
	Options []ClientOption
	*ReconnectingClient
}

type ClientOption

type ClientOption func(*ReconnectingClient)

func WithBlocking

func WithBlocking() ClientOption

func WithKeepalive

func WithKeepalive(keepalive bool) ClientOption

func WithPassword

func WithPassword(password string) ClientOption

func WithPingFunc

func WithPingFunc(pingFunc PingFunc) ClientOption

WithPingFunc sets an alternative function for keepalive testing.

This can e.g. be used to replace the ping with a status check.

func WithWatchSubsystems

func WithWatchSubsystems(subsystems ...Subsystem) ClientOption

type Connected

type Connected func(client *ReconnectingClient)

type ConnectedListener

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

func NewConnectedListener

func NewConnectedListener(fn func(client *ReconnectingClient)) *ConnectedListener

func (*ConnectedListener) Connected

func (l *ConnectedListener) Connected(client *ReconnectingClient)

type CurrentSong

type CurrentSong struct {
	PreviousSong *PlaylistEntry
	CurrentSong  *PlaylistEntry
	NextSong     *PlaylistEntry
}

func NewCurrentSong

func NewCurrentSong(status *Status, playlist *Playlist) *CurrentSong

func (*CurrentSong) Equals

func (cs *CurrentSong) Equals(other *CurrentSong) bool

type CurrentSongChanged

type CurrentSongChanged func(client *ReconnectingClient, currentSong *CurrentSong)

type CurrentSongChangedListener

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

func NewCurrentSongChangedListener

func NewCurrentSongChangedListener(fn func(client *ReconnectingClient, currentSong *CurrentSong)) *CurrentSongChangedListener

func (*CurrentSongChangedListener) CurrentSongChanged

func (l *CurrentSongChangedListener) CurrentSongChanged(client *ReconnectingClient, currentSong *CurrentSong)

type Disconnected

type Disconnected func(client *ReconnectingClient)

type DisconnectedListener

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

func NewDisconnectedListener

func NewDisconnectedListener(fn func(client *ReconnectingClient)) *DisconnectedListener

func (*DisconnectedListener) Disconnected

func (l *DisconnectedListener) Disconnected(client *ReconnectingClient)

type ListenerSet

type ListenerSet[T comparable] struct {
	// contains filtered or unexported fields
}

ListenerSet provides synchronized access to a set of listeners

func NewListenerSet

func NewListenerSet[T comparable]() *ListenerSet[T]

func (*ListenerSet[T]) Add

func (l *ListenerSet[T]) Add(e T)

func (*ListenerSet[T]) Notify

func (l *ListenerSet[T]) Notify(notifyFn func(l T))

func (*ListenerSet[T]) Remove

func (l *ListenerSet[T]) Remove(e T)

type NetAddr

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

type OffOnOneshot

type OffOnOneshot string
const Off OffOnOneshot = "0"
const On OffOnOneshot = "1"
const Oneshot OffOnOneshot = "oneshot"

func ParseOffOnOneshot

func ParseOffOnOneshot(s string) OffOnOneshot

type PingFunc

type PingFunc func(client *ReconnectingClient) error

type PlayerState

type PlayerState string

PlayerState represents the current player state.

const (
	Play  PlayerState = "play"
	Stop  PlayerState = "stop"
	Pause PlayerState = "pause"
)

type Playlist

type Playlist struct {
	Entries []*PlaylistEntry
}

func NewPlaylist

func NewPlaylist(attrsList []mpd.Attrs) *Playlist

type PlaylistChanged

type PlaylistChanged func(client *ReconnectingClient, playlist *Playlist)

type PlaylistChangedListener

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

func NewPlaylistChangedListener

func NewPlaylistChangedListener(fn func(client *ReconnectingClient, playlist *Playlist)) *PlaylistChangedListener

func (*PlaylistChangedListener) PlaylistChanged

func (l *PlaylistChangedListener) PlaylistChanged(client *ReconnectingClient, playlist *Playlist)

type PlaylistEntry

type PlaylistEntry struct {
	// the artist name. Its meaning is not well-defined; see “composer” and “performer” for more specific tags.
	Artist string

	// same as artist, but for sorting. This usually omits prefixes such as “The”.
	ArtistSort string

	// the album name.
	Album string

	// same as album, but for sorting.
	AlbumSort string

	// on multi-artist albums, this is the artist name which shall be used for the whole album. The exact meaning of this tag is not well-defined.
	AlbumArtist string

	// same as albumartist, but for sorting.
	AlbumArtistSort string

	// the song title.
	Title string

	// same as title, but for sorting.
	TitleSort string

	// the decimal track number within the album.
	Track int

	// a name for this song. This is not the song title. The exact meaning of this tag is not well-defined. It is often used by badly configured internet radio stations with broken tags to squeeze both the artist name and the song title in one tag.
	Name string

	// the music genre.
	Genre string

	// the mood of the audio with a few keywords.
	Mood string

	// the song’s release date. This is usually a 4-digit year.
	Date string

	// the song’s original release date.
	OriginalDate string

	// the artist who composed the song.
	Composer string

	// same as composer, but for sorting.
	ComposerSort string

	// the artist who performed the song.
	Performer string

	// the conductor who conducted the song.
	Conductor string

	// a work is a distinct intellectual or artistic creation, which can be expressed in the form of one or more audio recordings
	Work string

	// the ensemble performing this song, e.g. “Wiener Philharmoniker”.
	Ensemble string

	// name of the movement, e.g. “Andante con moto”.
	Movement string

	// movement number, e.g. “2” or “II”.
	MovementNumber string

	// location of the recording, e.g. “Royal Albert Hall”.
	Location string

	// "used if the sound belongs to a larger category of sounds/music" (from the IDv2.4.0 TIT1 description).
	Grouping string

	// a human-readable comment about this song. The exact meaning of this tag is not well-defined.
	Comment string

	// the decimal disc number in a multi-disc album.
	Disc int

	// the name of the label or publisher.
	Label string

	// the artist id in the MusicBrainz database.
	MusicbrainzArtistId string

	// the album id in the MusicBrainz database.
	MusicbrainzAlbumId string

	// the album artist id in the MusicBrainz database.
	MusicbrainzAlbumArtistId string

	// the track id in the MusicBrainz database.
	MusicbrainzTrackId string

	// the release group id in the MusicBrainz database.
	MusicbrainzReleaseGroupId string

	// the release track id in the MusicBrainz database.
	MusicbrainzReleaseTrackId string

	// the work id in the MusicBrainz database.
	MusicbrainzWorkId string

	// the duration of the song in seconds; may contain a fractional part.
	Duration float32

	// like duration, but as integer value. This is deprecated and is only here for compatibility with older clients. Do not use.
	Time int

	// if this is a queue item referring only to a portion of the song file, then this attribute contains the time range in the form START-END or START- (open ended); both START and END are time stamps within the song in seconds (may contain a fractional part). Example: 60-120 plays only the second minute; “180 skips the first three minutes.
	Range string

	// the audio format of the song (or an approximation to a format supported by MPD and the decoder plugin being used). When playing this file, the audio value in the status response should be the same.
	Format string

	// the time stamp of the last modification of the underlying file in ISO 8601 format. Example: “2008-09-28T20:04:57Z”
	LastModified string

	// the time stamp when the file was added in ISO 8601. A negative value means that this is unknown/unavailable. Example: “2023-11-25T13:25:07Z”
	Added string
}

PlaylistEntry represents song attributes of a playlist entry.

func ParsePlaylistEntryAttrs

func ParsePlaylistEntryAttrs(attrs mpd.Attrs) *PlaylistEntry

func (*PlaylistEntry) Equals

func (pe *PlaylistEntry) Equals(other *PlaylistEntry) bool

type ReconnectingClient

type ReconnectingClient struct {
	*mpd.Client

	PlaylistCache               atomic.Pointer[Playlist]
	StatusCache                 atomic.Pointer[Status]
	CurrentSongCache            atomic.Pointer[CurrentSong]
	ConnectedListeners          *ListenerSet[*ConnectedListener]
	DisconnectedListeners       *ListenerSet[*DisconnectedListener]
	SubsystemsChangedListeners  *ListenerSet[*SubsystemsChangedListener]
	StatusChangedListeners      *ListenerSet[*StatusChangedListener]
	PlaylistChangedListeners    *ListenerSet[*PlaylistChangedListener]
	CurrentSongChangedListeners *ListenerSet[*CurrentSongChangedListener]
	// contains filtered or unexported fields
}

func NewReconnectingClient

func NewReconnectingClient(network, addr string, options ...ClientOption) (*ReconnectingClient, error)

func (*ReconnectingClient) Close

func (c *ReconnectingClient) Close() error

func (*ReconnectingClient) Connect

func (c *ReconnectingClient) Connect() error

func (*ReconnectingClient) Do

func (c *ReconnectingClient) Do(fn func(client *ReconnectingClient) error) error

Do runs a client command.

All commands must be run via Do() so they are protected by the connectLock and obey correct idle behavior.

func (*ReconnectingClient) IsConnected

func (c *ReconnectingClient) IsConnected() bool

func (*ReconnectingClient) ReloadStatus

func (c *ReconnectingClient) ReloadStatus() error

type Status

type Status struct {
	// the name of the current partition (see Partition commands)
	Partition string

	// 0-100 (deprecated: -1 if the volume cannot be determined)
	Volume int

	// 0 or 1
	Repeat bool

	// 0 or 1
	Random bool

	// 0, 1, or oneshot
	Single OffOnOneshot

	// 0, 1 or oneshot 13
	Consume OffOnOneshot

	// 31-bit unsigned integer, the playlist version number
	Playlist uint32

	// integer, the length of the playlist
	PlaylistLength int

	// play, stop, or pause
	State PlayerState

	// playlist song number of the current song stopped on or playing
	Song int

	// playlist songid of the current song stopped on or playing
	SongId int

	// playlist song number of the next song to be played
	NextSong int

	// playlist songid of the next song to be played
	NextSongId int

	// total time elapsed (of current playing/paused song) in seconds (deprecated, use elapsed instead)
	Time int

	// Total time elapsed within the current song in seconds, but with higher resolution.
	Elapsed float32

	// Duration of the current song in seconds.
	Duration int

	// instantaneous bitrate in kbps
	Bitrate int

	// crossfade in seconds (see Cross-Fading)
	CrossFade int

	// mixramp threshold in dB
	MixRampDB int

	// mixrampdelay in seconds
	MixRampDelay int

	// The format emitted by the decoder plugin during playback, format: samplerate:bits:channels. See Global Audio Format for a detailed explanation.
	Audio string

	// Job id
	UpdatingDB string

	// if there is an error, returns message here
	Error string
}

Status represents the current player status.

func ParseStatusAttrs

func ParseStatusAttrs(attrs mpd.Attrs) *Status

func (*Status) Equals

func (s *Status) Equals(other *Status) bool

type StatusChanged

type StatusChanged func(client *ReconnectingClient, status *Status)

type StatusChangedListener

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

func NewStatusChangedListener

func NewStatusChangedListener(fn func(client *ReconnectingClient, status *Status)) *StatusChangedListener

func (*StatusChangedListener) StatusChanged

func (l *StatusChangedListener) StatusChanged(client *ReconnectingClient, status *Status)

type Subsystem

type Subsystem string
const (
	// the song database has been modified after update.
	SubsystemDatabase Subsystem = "database"

	// a database update has started or finished. If the database was modified during the update, the database event is also emitted.
	SubsystemUpdate Subsystem = "update"

	// a stored playlist has been modified, renamed, created or deleted
	SubsystemStoredPlaylist Subsystem = "stored_playlist"

	// the queue (i.e. the current playlist) has been modified
	SubsystemPlaylist Subsystem = "playlist"

	// the player has been started, stopped or seeked or tags of the currently playing song have changed (e.g. received from stream)
	SubsystemPlayer Subsystem = "player"

	// the volume has been changed
	SubsystemMixer Subsystem = "mixer"

	// an audio output has been added, removed or modified (e.g. renamed, enabled or disabled)
	SubsystemOutput Subsystem = "output"

	// options like repeat, random, crossfade, replay gain
	SubsystemOptions Subsystem = "options"

	// a partition was added, removed or changed
	SubsystemPartition Subsystem = "partition"

	// the sticker database has been modified.
	SubsystemSticker Subsystem = "sticker"

	// a client has subscribed or unsubscribed to a channel
	SubsystemSubscription Subsystem = "subscription"

	// a message was received on a channel this client is subscribed to; this event is only emitted when the client’s message queue is empty
	SubsystemMessage Subsystem = "message"

	// a neighbor was found or lost
	SubsystemNeighbour Subsystem = "neighbour"

	// the mount list has changed
	SubsystemMount Subsystem = "mount"
)

func SubsystemsForStrings

func SubsystemsForStrings(strs []string) (subsystems []Subsystem)

type SubsystemsChanged

type SubsystemsChanged func(client *ReconnectingClient, subsystems []Subsystem)

type SubsystemsChangedListener

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

func NewSubsystemsChangedListener

func NewSubsystemsChangedListener(fn func(client *ReconnectingClient, subsystems []Subsystem)) *SubsystemsChangedListener

func (*SubsystemsChangedListener) SubsystemsChanged

func (l *SubsystemsChangedListener) SubsystemsChanged(client *ReconnectingClient, subsystems []Subsystem)

Jump to

Keyboard shortcuts

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