polybar / polybar-scripts

This is a community project. We write and collect scripts for polybar!
The Unlicense
2.48k stars 340 forks source link

player-mpris-tail: intermittent dbus connection problem #194

Closed mxmilkiib closed 4 years ago

mxmilkiib commented 5 years ago

Just trying to set up MPRIS info, using "Output using formatters and Polybar action handlers".

Sometimes when I open mpv (using mpv-mpris (mpris.so)) I get ERROR:dbus.connection:Exception in handler for D-Bus signal: appearing in the bar. Changing the album track in mpv can trigger this and so can clicking on an action handler.

It seems to happen at random sometimes, though watching closely and there is always a dbus error flashing up for a fraction of a second before the song title text etc appears when it does work.

x70b1 commented 5 years ago

Thanks for your bug report. How often does this happen?

@Cybolic Maybe you' ll have some time to look inside someday.

mxmilkiib commented 4 years ago

It happens um about 50% of the time. Sometimes the song title shows, sometimes moving skipping forward and back fixes it, sometimes it didn't. I thought something had changed recently as I wasn't seeing /anything/ for a while, but it went back to the original broken behaviour.

Edit: I just moved to mpv-mpris-git, but get the same issue; a brief flash of the actual song info then the ERROR:dbus etc.

Edit2: I reduced exec = /usr/share/polybar/scripts/player-mpris-tail.py -f '{icon} {:artist:t18:{artist}:}{:artist: - :}{:t20:{title}:} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py previous:} ⏮ %{A} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py play-pause:} {icon-reversed} %{A} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py next:} ⏭ %{A}' to exec = /usr/share/polybar/scripts/player-mpris-tail.py -f '{icon} {:artist:t18:{artist}:}{:artist: - :}{:t20:{title}:}' but the problem remains.

Cybolic commented 4 years ago

Quick update: It's a bit difficult to get rid off as it's not actually coming from player-mpris-tail but from the Python library. I'm still considering how to work around it but I don't have anything yet.

EDIT: Quick thought; have you tried putting a shell wrapper around player-mpris-tail.py where you dump the stderr to /dev/null and calling that wrapper instead?

#!/usr/bin/env bash
/usr/share/polybar/scripts/player-mpris-tail.py -f '{icon} {:artist:t18:{artist}:}{:artist: - :}{:t20:{title}:} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py previous:} ⏮ %{A} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py play-pause:} {icon-reversed} %{A} %{A1:/usr/share/polybar/scripts/player-mpris-tail.py next:} ⏭ %{A}' 2>/dev/null
mxmilkiib commented 4 years ago

That wrapper seems to do the trick, thanks :)

Cybolic commented 4 years ago

No problem, glad you got it working :)

dshoreman commented 4 years ago

I think I've been getting the same error using Rhythmbox, but there are actually two bugs here.

One is a simple uncaught exception which seems to happen only when changing tracks. When the script is first run, everything's fine.

ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/dbus/connection.py", line 234, in maybe_handle_message
    self._handler(*args, **kwargs)
  File "./scripts/nowplaying.py", line 340, in onSeeked
    self.refreshPosition()
  File "./scripts/nowplaying.py", line 349, in refreshPosition
    time_us = self._getProperty('org.mpris.MediaPlayer2.Player', 'Position')
  File "/usr/lib/python3.8/site-packages/dbus/proxies.py", line 72, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python3.8/site-packages/dbus/proxies.py", line 141, in __call__
    return self._connection.call_blocking(self._named_service,
  File "/usr/lib/python3.8/site-packages/dbus/connection.py", line 654, in call_blocking
    reply_message = self.send_message_with_reply_and_block(
dbus.exceptions.DBusException: org.gtk.GDBus.UnmappedGError.Quark._rb_5fshell_5fplayer_5ferror.Code4: Playback position not available

The other seems to have been introduced somewhere in the last 6 commits. The last "good" commit (once I handled the error above) was 0b2311e6e26fbbf4f512bd34cc5ed835fc22fb56. The traceback is a little vague though:

ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/dbus/connection.py", line 234, in maybe_handle_message
    self._handler(*args, **kwargs)
TypeError: onMPRISSignal() missing 2 required positional arguments: 'properties' and 'signature

I'll PR my fix for the first error shortly. Haven't figured out the second one yet, but I'll see if I can replay the commits to track it down later.

dshoreman commented 4 years ago

While I had a hunch, I replayed commits individually to be certain and found the cause of the second issue was introduced in 871e4e06c41456b6e6766cd2fb72f3e187b9b390.

Although the PropertiesChanged signal was sending the properties and signature to the onMPRISSignal callback, it acted as a catch-all trying to handle other signals too. It's those other signals that did not have the arguments, triggering the missing 2 required positional arguments error.


@mxmilkb @Cybolic If you'd like to test, I've pushed an extra commit to #200 so it fixes both errors.