mpris

package module
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: 12 Imported by: 0

README

mpd-mpris

AUR version AUR version Flake is available Matrix chat

An implementation of the MPRIS protocol for MPD.


Installation

Probably needs Go v1.9 or newer.

go install github.com/natsukagami/mpd-mpris/cmd/mpd-mpris
For Arch Linux users.

Check out the AUR packages mpd-mpris and mpd-mpris-bin for the manually and pre-built versions respectively. A systemd user service file is also provided (enable with systemd --user enable mpd-mpris --now).

For Nix users

The repository provides the mpd-mpris package, overlay and a NixOS/home-manager module (services.mpd-mpris) as a flake.

# nix flake show github:natsukagami/mpd-mpris
github:natsukagami/mpd-mpris
├───devShells
│   ├───aarch64-darwin
│   │   └───default: development environment 'nix-shell'
│   ├───aarch64-linux
│   │   └───default: development environment 'nix-shell'
│   ├───x86_64-darwin
│   │   └───default: development environment 'nix-shell'
│   └───x86_64-linux
│       └───default: development environment 'nix-shell'
├───homeManagerModules:
│   └───default: home-manager module
├───nixosModules
│   └───default: NixOS module
├───overlays
│   └───default: Nixpkgs overlay
└───packages
    ├───aarch64-darwin
    │   └───default: package 'mpd-mpris'
    ├───aarch64-linux
    │   └───default: package 'mpd-mpris'
    ├───x86_64-darwin
    │   └───default: package 'mpd-mpris'
    └───x86_64-linux
        └───default: package 'mpd-mpris'

The mpd-mpris module has the following options:

  • services.mpd-mpris.enable: Enable the service.
  • services.mpd-mpris.package: Overrides the package. Defaults to pkgs.mpd-mpris (which uses the nixpkgs package without the overlay).
  • services.mpd-mpris.enableDefaultInstance: The module has a default instance that listens to the local mpd, enable this.

Per-instance configurations:

  • services.mpd-mpris.instances.{name}.host: The host to connect to. (-host flag)
  • services.mpd-mpris.instances.{name}.network: The network type. (-network flag)
  • services.mpd-mpris.instances.{name}.port: The port to connect to. (-port flag)
  • services.mpd-mpris.instances.{name}.passwordFile: The file containing the password to use. (-pwd-file flag)

Each instance will create a mpd-mpris-{name} service (with the default being mpd-mpris), with the MPRIS instance name org.mpris.MediaPlayer2.mpd.{name} (with the default being just org.mpris.MediaPlayer2.mpd). All per-instance configurations are available without the instances.{name} infix, and will apply to the default instance.

Running

# mpd-mpris --help
Usage of mpd-mpris:
  -host string
        The MPD host (default localhost)
  -instance-name string
        Set the MPRIS's interface as 'org.mpris.MediaPlayer2.mpd.{instance-name}'
  -network string
        The network used to dial to the mpd server. Check https://golang.org/pkg/net/#Dial for available values (most common are "tcp" and "unix") (default "tcp")
  -no-instance
        Set the MPRIS's interface as 'org.mpris.MediaPlayer2.mpd' instead of 'org.mpris.MediaPlayer2.mpd.instance#'
  -port int
        The MPD port. Only works if network is "tcp". If you use anything else, you should put the port inside addr yourself. (default 6600)
  -pwd string
        The MPD connection password. Leave empty for none.
  -pwd-file string
        Path to the file containing the mpd server password.

Will block for requests and log them down so you may want to run and forget.

Questions?

Join our Matrix channel at #mpd-mpris:matrix.org.

Implementation Status

  • Root Running
  • Player control
  • Track list
  • Playlist support

License

MIT

Documentation

Overview

Package mpris implements the `mpris` interface to an instance of `mpd`.

Index

Constants

View Source
const TrackIDFormat = "/org/mpd/Tracks/%d"

TrackIDFormat is the formatter string for a track ID.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

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

Instance is an instance of mpd-mpris. It contains a connection to the MPD server and the DBus connection.

func NewInstance

func NewInstance(mpd *mpd.Client, opts ...Option) (ins *Instance, err error)

NewInstance creates a new instance that takes care of the specified mpd.

func (*Instance) Close

func (ins *Instance) Close() error

Close ends the connection.

func (*Instance) IntrospectNode added in v0.2.0

func (i *Instance) IntrospectNode() *introspect.Node

IntrospectNode returns the root node of the library's introspection output.

func (*Instance) Name added in v0.2.0

func (ins *Instance) Name() string

Name returns the name of the instance.

func (*Instance) Start added in v0.4.1

func (ins *Instance) Start(ctx context.Context) error

Start starts the instance. Blocking, so you should fire and forget ;)

type LoopStatus

type LoopStatus = string

LoopStatus is a repeat / loop status. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Enum:Loop_Status

const (
	LoopStatusNone     LoopStatus = "None"
	LoopStatusTrack    LoopStatus = "Track"
	LoopStatusPlaylist LoopStatus = "Playlist"
)

Defined LoopStatuses

type MediaPlayer2

type MediaPlayer2 struct {
	*Instance
}

MediaPlayer2 is a DBus object satisfying the `org.mpris.MediaPlayer2` interface.

func (*MediaPlayer2) Quit

func (m *MediaPlayer2) Quit() *dbus.Error

Quit causes the media player to stop running. But for MPD, it's not up to the client to end its existence. Hence this function does nothing.

https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Method:Quit

func (*MediaPlayer2) Raise

func (m *MediaPlayer2) Raise() *dbus.Error

Raise brings the media player's user interface to the front using any appropriate mechanism available. But for MPD, there's no User Interface, this function does nothing.

https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Method:Raise

type MetadataMap

type MetadataMap map[string]interface{}

MetadataMap is a mapping from metadata attribute names to values. https://specifications.freedesktop.org/mpris-spec/latest/Track_List_Interface.html#Mapping:Metadata_Map

func MapFromSong

func MapFromSong(s mpd.Song) MetadataMap

MapFromSong returns a MetadataMap from the Song struct in mpd.

type Option added in v0.2.1

type Option func(*Instance)

Option represents a togglable option.

func InstanceName added in v0.4.1

func InstanceName(name string) Option

InstanceName gives a custom name after "mpd" for the MPRIS instance.

func NoInstance added in v0.2.1

func NoInstance() Option

NoInstance registers the instance's name without the instance# part.

type PlaybackStatus

type PlaybackStatus string

PlaybackStatus is a playback state. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Enum:Playback_Status

const (
	PlaybackStatusPlaying PlaybackStatus = "Playing"
	PlaybackStatusPaused  PlaybackStatus = "Paused"
	PlaybackStatusStopped PlaybackStatus = "Stopped"
)

Defined PlaybackStatuses.

func PlaybackStatusFromMPD added in v0.3.1

func PlaybackStatusFromMPD(status string) (PlaybackStatus, error)

type Player

type Player struct {
	*Instance
	// contains filtered or unexported fields
}

Player is a DBus object satisfying the `org.mpris.MediaPlayer2.Player` interface. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html

func (*Player) Next

func (p *Player) Next() *dbus.Error

Next skips to the next track in the tracklist. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Next

func (*Player) OnLoopStatus

func (p *Player) OnLoopStatus(c *prop.Change) *dbus.Error

OnLoopStatus handles LoopStatus change. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Property:LoopStatus

func (*Player) OnShuffle

func (p *Player) OnShuffle(c *prop.Change) *dbus.Error

OnShuffle handles Shuffle change. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Property:Shuffle

func (*Player) OnVolume

func (p *Player) OnVolume(c *prop.Change) *dbus.Error

OnVolume handles volume changes.

func (*Player) Pause

func (p *Player) Pause() *dbus.Error

Pause pauses playback. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Pause

func (*Player) Play

func (p *Player) Play() *dbus.Error

Play starts or resumes playback. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Play

func (*Player) PlayPause

func (p *Player) PlayPause() *dbus.Error

PlayPause toggles playback. If playback is already paused, resumes playback. If playback is stopped, starts playback. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:PlayPause

func (*Player) Previous

func (p *Player) Previous() *dbus.Error

Previous skips to the previous track in the tracklist. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Previous

func (*Player) Seek

func (p *Player) Seek(x TimeInUs) *dbus.Error

Seek seeks forward in the current track by the specified number of microseconds. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Seek

func (*Player) SetPosition

func (p *Player) SetPosition(o TrackID, x TimeInUs) *dbus.Error

SetPosition sets the current track position in microseconds. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:SetPosition

func (*Player) Stop

func (p *Player) Stop() *dbus.Error

Stop stops playback. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Stop

type Status added in v0.3.1

type Status struct {

	// Internal Status part
	PlaybackStatus PlaybackStatus
	LoopStatus     LoopStatus
	Shuffle        bool
	Volume         float64
	CurrentSong    mpd.Song
	// Internal seek
	Seek time.Duration
	// contains filtered or unexported fields
}

Status holds the internal status, as well as the corresponding props of the player's status.

func (*Status) Update added in v0.3.1

func (s *Status) Update(p *Player) *dbus.Error

Update performs an update on the status.

type TimeInUs

type TimeInUs int64

TimeInUs is time in microseconds. https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Simple-Type:Time_In_Us

func UsFromDuration

func UsFromDuration(t time.Duration) TimeInUs

UsFromDuration returns the type from a time.Duration

func (TimeInUs) Duration

func (t TimeInUs) Duration() time.Duration

Duration returns the type in time.Duration

type TrackList

type TrackList struct {
	*Instance
}

TrackList is a DBus object satisfying the `org.mpris.MediaPlayer2.TrackList` interface. https://specifications.freedesktop.org/mpris-spec/latest/TrackList_Interface.html

Directories

Path Synopsis
cmd
Package mpd provides a higher-level implementation of some features of the lower-level `github.com/fhs/gompd/v2/mpd` package.
Package mpd provides a higher-level implementation of some features of the lower-level `github.com/fhs/gompd/v2/mpd` package.

Jump to

Keyboard shortcuts

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