FichteFoll / discordrp-mpris

Discord Rich Presence through media players providing the mpris2 dbus interface
MIT License
86 stars 19 forks source link

Crash with Amberol #28

Open Leeo97one opened 2 years ago

Leeo97one commented 2 years ago

When playing audio with Amberol:

2022-05-28 02:12:41,087 | WARNING  | closing connection [discord_rpc.async_]
Traceback (most recent call last):
  File "/usr/bin/discordrp-mpris", line 33, in <module>
    sys.exit(load_entry_point('discordrp-mpris==0.3.2', 'console_scripts', 'discordrp-mpris')())
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 341, in main
    loop.run_until_complete(wait_task)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/usr/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 336, in main
    return loop.run_until_complete(main_task)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 329, in main_async
    return await instance.run()
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 91, in run
    await self.tick()
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 141, in tick
    replacements = self.build_replacements(player, metadata, position, length, state)
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 262, in build_replacements
    replacements['length'] = cls.format_timestamp(length)
  File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 288, in format_timestamp
    secs = microsecs // int(1e6)
TypeError: unsupported operand type(s) for //: 'str' and 'int'
ravener commented 2 months ago

This is due to the fact that Amberol reports the microseconds duration as a string, you just need to handle the case that the length is a string and try to convert it to a number.

Edit: Technically that breaks the spec, I found the root of the issue and so I've reported this upstream: https://gitlab.gnome.org/World/amberol/-/issues/380

FichteFoll commented 2 months ago

Thanks for creating the report. smplayer had a similar issue in that it violated the protocol by transmitting a float instead of an int for the position field (see #7).

We can deploy a similar workaround here, but fixing this upstream is of course preferred and I'd rather spend time on migrating to jeepney as the dbus library instead of dbussy because I found its API to be much cleaner. (That said, since I personally don't use this tool anymore, it has dropped a bit in priority for me.)