Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/mpd-mpris/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (

noInstance bool
instance string

isLocal = false
)

func init() {
Expand Down Expand Up @@ -84,11 +86,12 @@ func main() {
env_host := os.Getenv("MPD_HOST")
if len(env_host) == 0 {
addr = "localhost"
isLocal = true
detectLocalSocket()
} else {
// When looking for the password delimiter, ignore the first character.
// An '@' sign at the start of the envvar signifies an "abstract socket" without password.
if strings.Index(env_host[1:], "@") > -1 {
if strings.Contains(env_host[1:], "@") {
addr_pwd := strings.SplitN(env_host, "@", 2)
// allow providing an alternative password on the command line
if len(password) == 0 {
Expand All @@ -101,7 +104,10 @@ func main() {
// Check if addr refers to a path or abstract socket name and change network accordingly.
if strings.HasPrefix(addr, "/") || strings.HasPrefix(addr, "@") {
network = "unix"
isLocal = true
}
// very crude way to find out if we have a local connection
isLocal = isLocal || strings.Contains(env_host, "localhost") || strings.Contains(env_host, "127.0.0.1") || strings.Contains(env_host, "/::1")
}
}

Expand Down Expand Up @@ -130,7 +136,9 @@ func main() {
log.Fatalf("Cannot connect to mpd: %+v", err)
}

opts := []mpris.Option{}
opts := []mpris.Option{
mpris.IsLocal(isLocal),
}
if noInstance && instance != "" {
log.Fatalln("-no-instance cannot be used with -instance-name")
}
Expand Down
4 changes: 4 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Instance struct {
player *Player

name string

displayName string
}

// Close ends the connection.
Expand Down Expand Up @@ -53,6 +55,8 @@ func NewInstance(mpd *mpd.Client, opts ...Option) (ins *Instance, err error) {
mpd: mpd,

name: fmt.Sprintf("org.mpris.MediaPlayer2.mpd.instance%d", os.Getpid()),

displayName: fmt.Sprintf("MPD on %s", mpd.Address),
}
if ins.dbus, err = dbus.SessionBus(); err != nil {
return nil, errors.WithStack(err)
Expand Down
20 changes: 20 additions & 0 deletions introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ func (i *Instance) IntrospectNode() *introspect.Node {
Type: "as",
Access: "read",
},
{
Name: "Fullscreen",
Type: "b",
Access: "read",
},
{
Name: "CanSetFullscreen",
Type: "b",
Access: "read",
},
{
Name: "DesktopEntry",
Type: "s",
Access: "read",
},
},
Methods: []introspect.Method{
introspect.Method{
Expand Down Expand Up @@ -126,6 +141,11 @@ func (i *Instance) IntrospectNode() *introspect.Node {
Type: "b",
Access: "read",
},
{
Name: "CanPause",
Type: "b",
Access: "read",
},
},
Signals: []introspect.Signal{
introspect.Signal{
Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ func InstanceName(name string) Option {
ins.name = fmt.Sprintf("org.mpris.MediaPlayer2.mpd.%s", name)
}
}

func IsLocal(isLocal bool) Option {
return func(ins *Instance) {
if isLocal {
ins.displayName = "MPD"
}
}
}
16 changes: 10 additions & 6 deletions root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mpris

import (
"fmt"

"github.com/godbus/dbus/v5"
"github.com/godbus/dbus/v5/prop"
)
Expand All @@ -15,11 +13,17 @@ type MediaPlayer2 struct {
}

func (m *MediaPlayer2) properties() map[string]*prop.Prop {

return map[string]*prop.Prop{
"CanQuit": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:CanQuit
"CanRaise": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:CanRaise
"HasTrackList": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:HasTrackList
"Identity": newProp(fmt.Sprintf("MPD on %s", m.Instance.mpd.Address), nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:Identity
"CanQuit": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:CanQuit
"CanRaise": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:CanRaise
"HasTrackList": newProp(false, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:HasTrackList
"Identity": newProp(m.displayName, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:Identity
"DesktopEntry": newProp("mpd-mpris", nil), // doesn't actually exist

"Fullscreen": newProp(false, nil),
"CanSetFullscreen": newProp(false, nil),

// Empty because we can't add arbitary files in...
"SupportedUriSchemes": newProp([]string{}, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:SupportedUriSchemes
"SupportedMimeTypes": newProp([]string{}, nil), // https://specifications.freedesktop.org/mpris-spec/latest/Media_Player.html#Property:SupportedMimeTypes
Expand Down