mpris

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 5 Imported by: 1

README

go-mpris

Go GoDoc Go Report Card codecov

go-mpris is an implementation of the mpris dbus interface written in go (golang). Implemented and tested against version 2.2. See: https://specifications.freedesktop.org/mpris-spec/2.2.

Example

Example cli has been implemented.

git clone git@github.com:leberKleber/go-mpris.git

go build examples/cli.go

./cli-client

Features:

Player

https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html

Methods
method library path implemented
Next mpris.Player.Next()
Previous mpris.Player.Previous()
Pause mpris.Player.Pause()
PlayPause mpris.Player.PlayPause()
Stop mpris.Player.Stop()
Seek mpris.Player.SeekTo(<offset> int64)¹
SetPosition mpris.Player.SetPosition(<trackID> dbus.ObjectPath, <position> int64)
OpenUri mpris.Player.OpenUri(<uri> string)

¹ Could not be named Seek, it's a reserved function name.

Properties
property library path implemented
PlaybackStatus mpris.Player.PlaybackStatus() (mpris.PlaybackStatus, error)
LoopStatus mpris.Player.LoopStatus() (mpris.LoopStatus, error)
LoopStatus mpris.Player.SetLoopStatus(<loopStatus> mpris.LoopStatus) error
Rate mpris.Player.Rate() (float64, error)
Rate mpris.Player.SetRate(<rate> float64) error
Shuffle mpris.Player.Shuffle() (bool, error)
Shuffle mpris.Player.SetShuffle(<shuffle> bool) error
Metadata mpris.Player.Metadata() (mpris.Metadata, error)
Volume mpris.Player.Volume() (float64, error)
Volume mpris.Player.SetVolume(<volume> float64) (error)
Position mpris.Player.Position() (int64, error)
Position mpris.Player.SetPosition(<trackID> dbus.ObjectPath, <position> int64)
MinimumRate mpris.Player.MinimumRate() (float64, error)
MaximumRate mpris.Player.MaximumRate() (float64, error)
CanGoNext mpris.Player.CanGoNext() (bool, error)
CanGoPrevious mpris.Player.CanGoPrevious() (bool, error)
CanPlay mpris.Player.CanPlay() (bool, error)
CanPause mpris.Player.CanPause() (bool, error)
CanSeek mpris.Player.CanSeek() (bool, error)
CanControl mpris.Player.CanControl(bool, error)
Signals
signal library path implemented
Seeked mpris.Player.Seeked(<ctx> context.Context) (<-chan int, error)

Development

Versioning

This library follows the semantic versioning concept.

Commits

Commits should follow the conventional commit rules.
See: https://conventionalcommits.org.

Mocks

Mocks will be generated with github.com/matryer/moq. It can be installed with go install github.com/matryer/moq@latest. Generation can be triggered with go generate ./....

Go Docs

Read the docs at https://pkg.go.dev/github.com/leberKleber/go-mpris

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTypeNotParsable = errors.New("the given type is not as expected")

Functions

This section is empty.

Types

type LoopStatus

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

type Metadata

type Metadata map[string]dbus.Variant

Metadata represents the mpris-metadata see: https://www.freedesktop.org/wiki/Specifications/mpris-spec/metadata/

func (Metadata) Find

func (md Metadata) Find(key string) (dbus.Variant, bool)

Find returns a generic representation of the requested value when present

func (Metadata) MPRISArtURL

func (md Metadata) MPRISArtURL() (string, error)

MPRISArtURL returns the location of an image representing the track or album. Clients should not assume this will continue to exist when the media player stops giving out the URL.

func (Metadata) MPRISLength

func (md Metadata) MPRISLength() (int64, error)

MPRISLength returns the duration of the track in microseconds.

func (Metadata) MPRISTrackID

func (md Metadata) MPRISTrackID() (dbus.ObjectPath, error)

MPRISTrackID returns a unique identity for this track within the context of an MPRIS object (eg: tracklist).

func (Metadata) XESAMAlbum

func (md Metadata) XESAMAlbum() (string, error)

XESAMAlbum returns the album name.

func (Metadata) XESAMAlbumArtist

func (md Metadata) XESAMAlbumArtist() ([]string, error)

XESAMAlbumArtist returns the album artist(s)

func (Metadata) XESAMArtist

func (md Metadata) XESAMArtist() ([]string, error)

XESAMArtist returns the track artist(s).

func (Metadata) XESAMAsText

func (md Metadata) XESAMAsText() (string, error)

XESAMAsText returns the track lyrics.

func (Metadata) XESAMAudioBPM

func (md Metadata) XESAMAudioBPM() (int, error)

XESAMAudioBPM returns the speed of the music, in beats per minute.

func (Metadata) XESAMAutoRating

func (md Metadata) XESAMAutoRating() (float64, error)

XESAMAutoRating returns an automatically-generated rating, based on things such as how often it has been played. This should be in the range 0.0 to 1.0.

func (Metadata) XESAMComment

func (md Metadata) XESAMComment() ([]string, error)

XESAMComment returns a (list of) freeform comment(s).

func (Metadata) XESAMComposer

func (md Metadata) XESAMComposer() ([]string, error)

XESAMComposer returns the composer(s) of the track.

func (Metadata) XESAMContentCreated

func (md Metadata) XESAMContentCreated() (time.Time, error)

XESAMContentCreated returns when the track was created. Usually only the year component will be useful.

func (Metadata) XESAMDiscNumber

func (md Metadata) XESAMDiscNumber() (int, error)

XESAMDiscNumber returns the disc number on the album that this track is from.

func (Metadata) XESAMFirstUsed

func (md Metadata) XESAMFirstUsed() (time.Time, error)

XESAMFirstUsed returns when the track was first played.

func (Metadata) XESAMGenre

func (md Metadata) XESAMGenre() ([]string, error)

XESAMGenre returns the genre(s) of the track.

func (Metadata) XESAMLastUsed

func (md Metadata) XESAMLastUsed() (time.Time, error)

XESAMLastUsed returns when the track was last played.

func (Metadata) XESAMLyricist

func (md Metadata) XESAMLyricist() ([]string, error)

XESAMLyricist returns the lyricist(s) of the track.

func (Metadata) XESAMTitle

func (md Metadata) XESAMTitle() (string, error)

XESAMTitle returns the track title.

func (Metadata) XESAMTrackNumber

func (md Metadata) XESAMTrackNumber() (int, error)

XESAMTrackNumber returns the track number on the album disc.

func (Metadata) XESAMURL

func (md Metadata) XESAMURL() (string, error)

XESAMURL returns the location of the media file.

func (Metadata) XESAMUseCount

func (md Metadata) XESAMUseCount() (int, error)

XESAMUseCount returns hte number of times the track has been played.

func (Metadata) XESAMUserRating

func (md Metadata) XESAMUserRating() (float64, error)

XESAMUserRating returns a user-specified rating. This should be in the range 0.0 to 1.0.

type PlaybackStatus

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

type Player

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

Player is a implementation of dbus org.mpris.MediaPlayer2.Player. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html Use NewPlayer to create a new instance with a connected session-bus via dbus.SessionBus. Use NewPlayerWithConnection when you want to use a self-configured dbus.Conn

func NewPlayer

func NewPlayer(name string) (Player, error)

NewPlayer returns a new Player which is already connected to session-bus via dbus.SessionBus. Don't forget to Player.Close() the player after use.

func NewPlayerWithConnection

func NewPlayerWithConnection(name string, connection *dbus.Conn) Player

NewPlayerWithConnection returns a new Player with the given name and connection. Deprecated: NewPlayerWithConnection will be removed in future (v2.X.X). Plain Struct initialization should be used instead. Private fields will be public.

func (Player) CanControl

func (p Player) CanControl() (bool, error)

CanControl is true whether the media player may be controlled over this interface. This property is not expected to change, as it describes an intrinsic capability of the implementation. If this is false, clients should assume that all properties on this interface are read-only (and will raise errors if writing to them is attempted), no methods are implemented and all other properties starting with "Can" are also false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanControl

func (Player) CanGoNext

func (p Player) CanGoNext() (bool, error)

CanGoNext returns true whether the client can call the Next method on this interface and expect the current track to change. If it is unknown whether a call to Next will be successful (for example, when streaming tracks), this property should be set to true. If CanControl is false, this property should also be false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanGoNext

func (Player) CanGoPrevious

func (p Player) CanGoPrevious() (bool, error)

CanGoPrevious returns true whether the client can call the Previous method on this interface and expect the current track to change. If it is unknown whether a call to Previous will be successful (for example, when streaming tracks), this property should be set to true. If CanControl is false, this property should also be false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanGoPrevious

func (Player) CanPause

func (p Player) CanPause() (bool, error)

CanPause returns true whether playback can be paused using Pause or PlayPause. Note that this is an intrinsic property of the current track: its value should not depend on whether the track is currently paused or playing. In fact, if playback is currently paused (and CanControl is true), this should be true. If CanControl is false, this property should also be false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanPause

func (Player) CanPlay

func (p Player) CanPlay() (bool, error)

CanPlay returns true whether playback can be started using Play or PlayPause. Note that this is related to whether there is a "current track": the value should not depend on whether the track is currently paused or playing. In fact, if a track is currently playing (and CanControl is true), this should be true. If CanControl is false, this property should also be false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanPlay

func (Player) CanSeek

func (p Player) CanSeek() (bool, error)

CanSeek returns true whether the client can control the playback position using Seek and SetPosition. This may be different for different tracks. If CanControl is false, this property should also be false. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:CanSeek

func (Player) Close added in v0.1.0

func (p Player) Close() error

Close closes the dbus connection.

func (Player) LoopStatus

func (p Player) LoopStatus() (LoopStatus, error)

LoopStatus returns the current loop / repeat status May be: "None" as LoopStatusNone if the playback will stop when there are no more tracks to play "Track" as LoopStatusTrack if the current track will start again from the beginning once it has finished playing "Playlist" as LoopStatusPlaylist if the playback loops through a list of tracks If CanControl is false, attempting to set this property (SetLoopStatus) should have no effect and raise an error. https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:LoopStatus

func (Player) MaximumRate

func (p Player) MaximumRate() (float64, error)

MaximumRate returns the maximum value which the Rate property can take. Clients should not attempt to set the Rate property above this value. This value should always be 1.0 or greater. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:MaximumRate

func (Player) Metadata

func (p Player) Metadata() (Metadata, error)

Metadata of the current element. If there is a current track, this must have a "mpris:trackid" entry (of D-Bus type "o") at the very least, which contains a D-Bus path that uniquely identifies this track. See the type documentation for more details. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Metadata

func (Player) MinimumRate

func (p Player) MinimumRate() (float64, error)

MinimumRate returns the minimum value which the Rate property can take. Clients should not attempt to set the Rate property below this value. Note that even if this value is 0.0 or negative, clients should not attempt to set the Rate property to 0.0. This value should always be 1.0 or less. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:MinimumRate

func (Player) Next

func (p Player) Next()

Next skips to the next track in the tracklist. If there is no next track (and endless playback and track repeat are both off), stop playback. If playback is paused or stopped, it remains that way. If CanGoNext is false, attempting to call this method should have no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Next

func (Player) OpenURI

func (p Player) OpenURI(uri string)

OpenURI opens the Uri given as an argument Parameters: - uri (Uri of the track to load. Its uri scheme should be an element of the org.mpris.MediaPlayer2.SupportedUriSchemes property and the mime-type should match one of the elements of the org.mpris.MediaPlayer2.SupportedMimeTypes.) If the playback is stopped, starts playing If the uri scheme or the mime-type of the uri to open is not supported, this method does nothing and may raise an error. In particular, if the list of available uri schemes is empty, this method may not be implemented. Clients should not assume that the Uri has been opened as soon as this method returns. They should wait until the mpris:trackid field in the Metadata property changes. If the media player implements the TrackList interface, then the opened track should be made part of the tracklist, the org.mpris.MediaPlayer2.TrackList.TrackAdded or org.mpris.MediaPlayer2.TrackList.TrackListReplaced signal should be fired, as well as the org.freedesktop.DBus.Properties.PropertiesChanged signal on the tracklist interface. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:OpenUri

func (Player) Pause

func (p Player) Pause()

Pause pauses playback. If playback is already paused, this has no effect. Calling Play after this should cause playback to start again from the same position. If CanPause is false, attempting to call this method should have no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Pause

func (Player) Play

func (p Player) Play()

Play starts or resumes playback. If already playing, this has no effect. If paused, playback resumes from the current position. If there is no track to play, this has no effect. If CanPlay is false, attempting to call this method should have no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Play

func (Player) PlayPause

func (p Player) PlayPause()

PlayPause pauses playback. If playback is already paused, resumes playback. If playback is stopped, starts playback. If CanPause is false, attempting to call this method should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:PlayPause

func (Player) PlaybackStatus

func (p Player) PlaybackStatus() (PlaybackStatus, error)

PlaybackStatus returns the current playback status. May be "Playing" as PlaybackStatusPlaying, "Paused" as PlaybackStatusPaused or "Stopped" as PlaybackStatusStopped. https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:PlaybackStatus

func (Player) Position

func (p Player) Position() (int64, error)

Position returns current track position in microseconds, between 0 and the 'mpris:length' metadata entry (see Metadata). Note: If the media player allows it, the current playback position can be changed either the SetPosition method or the Seek method on this interface. If this is not the case, the CanSeek property is false, and setting this property has no effect and can raise an error. If the playback progresses in a way that is inconsistent with the Rate property, the Seeked signal is emitted. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Position

func (Player) Previous

func (p Player) Previous()

Previous skips to the previous track in the tracklist. If there is no previous track (and endless playback and track repeat are both off), stop playback. If playback is paused or stopped, it remains that way. If CanGoPrevious is false, attempting to call this method should have no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Previous

func (Player) Rate

func (p Player) Rate() (float64, error)

Rate return the current playback rate. The value must fall in the range described by MinimumRate and MaximumRate, and must not be 0.0. If playback is paused, the PlaybackStatus property should be used to indicate this. A value of 0.0 should not be set by the client. If it is, the media player should act as though Pause was called. If the media player has no ability to play at speeds other than the normal playback rate, this must still be implemented, and must return 1.0. The MinimumRate and MaximumRate properties must also be set to 1.0. Not all values may be accepted by the media player. It is left to media player implementations to decide how to deal with values they cannot use; they may either ignore them or pick a "best fit" value. Clients are recommended to only use sensible fractions or multiples of 1 (eg: 0.5, 0.25, 1.5, 2.0, etc). see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Rate

func (Player) SeekTo

func (p Player) SeekTo(offset int64)

SeekTo seeks forward in the current track by the specified number of microseconds. Parameters: - offset (The number of microseconds to seek forward.) A negative value seeks back. If this would mean seeking back further than the start of the track, the position is set to 0. If the value passed in would mean seeking beyond the end of the track, acts like a call to Next. If the CanSeek property is false, this has no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Seek

func (Player) Seeked added in v0.1.0

func (p Player) Seeked(ctx context.Context) (<-chan int, error)

Seeked indicates that the track position has changed in a way that is inconsistant with the current playing state. When this signal is not received, clients should assume that: - When playing, the position progresses according to the rate property. - When paused, it remains constant. This signal does not need to be emitted when playback starts or when the track changes, unless the track is starting at an unexpected position. An expected position would be the last known one when going from Paused to Playing, and 0 when going from Stopped to Playing. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Signal:Seeked

func (Player) SetLoopStatus

func (p Player) SetLoopStatus(status LoopStatus) error

SetLoopStatus sets the current loop / repeat status May be: "None" as LoopStatusNone if the playback will stop when there are no more tracks to play "Track" as LoopStatusTrack if the current track will start again from the beginning once it has finished playing "Playlist" as LoopStatusPlaylist if the playback loops through a list of tracks If CanControl is false, attempting to set this property (SetLoopStatus) should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:LoopStatus

func (Player) SetPosition

func (p Player) SetPosition(trackID dbus.ObjectPath, position int64)

SetPosition Sets the current track position in microseconds. Parameters: - trackID (The currently playing track's identifier. If this does not match the id of the currently-playing track, the call is ignored as "stale".) - position (Track position in microseconds. This must be between 0 and <track_length>.) If this does not match the id of the currently-playing track, the call is ignored as "stale". If the Position argument is less than 0, do nothing. If the Position argument is greater than the track length, do nothing. If the CanSeek property is false, this has no effect. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:SetPosition

func (Player) SetRate

func (p Player) SetRate(rate float64) error

SetRate sets the current playback rate. The value must fall in the range described by MinimumRate and MaximumRate, and must not be 0.0. If playback is paused, the PlaybackStatus property should be used to indicate this. A value of 0.0 should not be set by the client. If it is, the media player should act as though Pause was called. If the media player has no ability to play at speeds other than the normal playback rate, this must still be implemented, and must return 1.0. The MinimumRate and MaximumRate properties must also be set to 1.0. Not all values may be accepted by the media player. It is left to media player implementations to decide how to deal with values they cannot use; they may either ignore them or pick a "best fit" value. Clients are recommended to only use sensible fractions or multiples of 1 (eg: 0.5, 0.25, 1.5, 2.0, etc). see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Rate

func (Player) SetShuffle

func (p Player) SetShuffle(shuffle bool) error

SetShuffle set a value of false indicates that playback is progressing linearly through a playlist, while true means playback is progressing through a playlist in some other order. If CanControl is false, attempting to set this property should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Shuffle

func (Player) SetVolume

func (p Player) SetVolume(volume float64) error

SetVolume sets the volume level. When setting, if a negative value is passed, the volume should be set to 0.0. If CanControl is false, attempting to set this property should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Volume

func (Player) Shuffle

func (p Player) Shuffle() (bool, error)

Shuffle returns a value of false indicates that playback is progressing linearly through a playlist, while true means playback is progressing through a playlist in some other order. If CanControl is false, attempting to set this property should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Shuffle

func (Player) Stop

func (p Player) Stop()

Stop stops playback. If playback is already stopped, this has no effect. Calling Play after this should cause playback to start again from the beginning of the track. If CanControl is false, attempting to call this method should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Method:Stop

func (Player) Volume

func (p Player) Volume() (float64, error)

Volume returns the volume level. When setting, if a negative value is passed, the volume should be set to 0.0. If CanControl is false, attempting to set this property should have no effect and raise an error. see: https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Volume

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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