Spotifyd / spotifyd

A spotify daemon
https://spotifyd.rs
GNU General Public License v3.0
9.68k stars 444 forks source link

Spotifyd appends *.instanceXXX to the D-Bus service name #1261

Open itsdeyan opened 5 months ago

itsdeyan commented 5 months ago

Description The D-Bus service name for Spotifyd always has a random number at the end, for example org.mpris.MediaPlayer2.spotifyd.instance378 This way I can't control it with playerctl on my machine.

To Reproduce Run spotifyd with the use_mrpis = true and dbus_type = system options.

Expected behavior Spotifyd to register as org.mpris.MediaPlayer2.spotifyd and not have the .instanceXXX at the end

Compilation flags

Versions (please complete the following information):

eladyn commented 5 months ago

Thank you for the issue. That is actually an intentional feature that has been added some time ago and should be in line with the MPRIS specification.

The reason, why you cannot use playerctl to control your spotifyd application is that playerctl only supports the session bus, while you want to run spotifyd on the system bus. So there are two possible fixes for this:

itsdeyan commented 5 months ago

The reason, why you cannot use playerctl to control your spotifyd application is that playerctl only supports the session bus, while you want to run spotifyd on the system bus.

I was actually able to control spotifyd with playerctl. Things got complicated when I also ran shairport-sync. When both daemons are running, only shairport-sync responds to playerctl (even while it's paused and spotifyd's playing).

I can temporary make it work by addressing both players by their names, for example: $ playerctl play-pause -p ShairportSync, spotifyd.instance32214 But that'd only work for a while, and then the .instanceXXXX part changes. That's why I'd help in my case if there was an option to turn off the random numbers at the end....

eladyn commented 5 months ago

Oh, that's interesting and good to hear. IIRC, playerctl also accepts -p spotifyd and then it should look for the relevant bus name.

If not, you can also get the number dynamically, since it's always the PID of spotifyd. So you should be able to add -p spotifyd.instance$(pidof spotifyd) or something. (untested)

klemensn commented 5 months ago

The reason, why you cannot use playerctl to control your spotifyd application is that playerctl only supports the session bus, while you want to run spotifyd on the system bus. So there are two possible fixes for this:

playerctl(1) works just fine against the system bus, at least on OpenBSD where the audio/spotifyd package's rc.d(8) daemon script runs spotifyd on the system bus.

dbus-monitor --system run as root confirms that playerctl run as my local user comunicates just with with spotifyd running as unprivileged _spotifyd user (given a proper D-Bus service policy, of course).

klemensn commented 5 months ago

Oh, that's interesting and good to hear. IIRC, playerctl also accepts -p spotifyd and then it should look for the relevant bus name.

FWIW, that is enough to pick, e.g. spotifyd.instance68391 amongst multiple players, i.e. no need for me to specify the full name as playerctl seems clever enough to do that.

klemensn commented 5 months ago

The reason, why you cannot use playerctl to control your spotifyd application is that playerctl only supports the session bus, while you want to run spotifyd on the system bus.

I was actually able to control spotifyd with playerctl. Things got complicated when I also ran shairport-sync. When both daemons are running, only shairport-sync responds to playerctl (even while it's paused and spotifyd's playing).

I also use both daemons, but I think it depends on the order of startup and/or which daemon is currently playing.

I can temporary make it work by addressing both players by their names, for example: $ playerctl play-pause -p ShairportSync, spotifyd.instance32214 But that'd only work for a while, and then the .instanceXXXX part changes. That's why I'd help in my case if there was an option to turn off the random numbers at the end....

Either way, instead of forcing spotifyd under its dynamic name, have you tried ignoring shairport-sync?

     -i NAME, --ignore-player NAME
             Ignore the specific player NAME.  Multiple players can be
             specified in a comma-separated list.