polybar/polybar-scripts

Issue with mpris-tail and ncspot before playback starts

oncomouse opened this issue · 2 comments

I'm using mpris-tail with ncspot. When the player first opens, but before playback starts, the script produces the following error:

Traceback (most recent call last):
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 502, in <module>
    PlayerManager(blacklist = args.blacklist)
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 32, in __init__
    self.refreshPlayerList()
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 86, in refreshPlayerList
    self.addPlayer(player_bus_name)
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 92, in addPlayer
    player = Player(self._session_bus, bus_name, owner = owne
r, connect = self._connect, _print = self.print)
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 198, in __init__
    self.refreshMetadata()
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 248, in refreshMetadata
    self._parseMetadata()
  File "/home/andrew/dotfiles/scripts/polybar/mpris-tail", li
ne 284, in _parseMetadata
    self.metadata['artist']     = re.sub(SAFE_TAG_REGEX, """\
1\1""", _firstIfList(_artist))
  File "/usr/lib/python3.9/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

It's happening because at L284 _artist is set to [] by ncspot and _firstIfList, because that method checks the length of any list passed, returns [], which doesn't work.

Changing L284 to self.metadata['artist'] = re.sub(SAFE_TAG_REGEX, """\1\1""", _firstIfList('' if _artist == [] else _artist)) makes the script work again, but this feels like a hack (otherwise I'd submit a PR).

I'm assuming this error is happening because something isn't working in ncspot, but I wanted to post it here, in case this is a broader issue, also there is a problem that firstIfList can still return a list in certain cases.

Hi there,

The _firstIfList thingy is actually my fault. The only thing it fixes is a single case where a non-conforming player (in my case it's cmus) is sending a string to a metadata that should give an array of string per MPRIS spec like artist, album artist, and composer. I did not consider when empty array of string is sent at that time so I tried to fix that via #297. If you have any suggestions you can comment on that PR.

x70b1 commented

Fix in #297.