fichtefoll / discordrp-mpris Goto Github PK
View Code? Open in Web Editor NEWDiscord Rich Presence through media players providing the mpris2 dbus interface
License: MIT License
Discord Rich Presence through media players providing the mpris2 dbus interface
License: MIT License
Python verision: 3.8
Exception:
Traceback (most recent call last):
File "/usr/local/bin/discordrp-mpris", line 33, in <module>
sys.exit(load_entry_point('discordrp-mpris==0.3.2', 'console_scripts', 'discordrp-mpris')())
File "/usr/local/bin/discordrp-mpris", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.8/importlib/metadata.py", line 75, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/dist-packages/discordrp_mpris/__main__.py", line 49, in <module>
weigth_map: dict[str, int] = DefaultDict(
TypeError: 'type' object is not subscriptable
Hey man, great utility. But I'm afraid I'm having some issues with it.
When using mps-youtube, which does support mpris2, discordrp-mpris exits with this error:
[nipkow@nipkow-ln ~]$ discordrp-mpris
INFO:discordrp_mpris.main:Connected to Discord client
WARNING:discord_rpc.async:closing connection
Traceback (most recent call last):
File "/usr/bin/discordrp-mpris", line 11, in
load_entry_point('discordrp-mpris==0.1.1', 'console_scripts', 'discordrp-mpris')()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 236, in main
loop.run_until_complete(wait_task)
File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 230, in main
loop.run_until_complete(main_task)
File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
return future.result()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 222, in main_async
await instance.run()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 59, in run
await self.tick()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 69, in tick
player = await self.find_active_player()
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 148, in find_active_player
groups = await self.group_players(players)
File "/usr/lib/python3.6/site-packages/discordrp_mpris/main.py", line 192, in group_players
state = ampris2.PlaybackStatus(await p.player.PlaybackStatus) # type: ignore
AttributeError: 'org.mpris.MediaPlayer2.Player' object has no attribute 'PlaybackStatus'
Not sure if there is anything wrong with mps-youtube's mpris implementation. It seems to work fine with other applications such as Cinnamon's "audio/sound" controller.
Also, would it be possible to "disable" discordrp-mpris automatically when Spotify is running? It breaks Discord's integration with Spotify, preventing me from listening songs with friend and such.
Since discord can accept any valid image URL as the icon for rich presence it would be nice to be able to overwrite that for any player. This is especially useful for new players that don't have an icon built in.
things to consider: how would this interact with #32
Discord actually has 2 slots for icons, so maybe we can put the player icon in the small circle one and the album over in the big one?
I could, theoretically, register multiple apps and reconnect to discord with the respective player id when the active player switches.
I could even hot-swap the ID by direct attribute access after a manual disconnect so I don't have to refactor.
https://github.com/SSStormy/mpd-rich-presence-discord uses this to show "playing" and "paused" in the title, but I'm not really interested in that.
FireFox added mpris2 support some time late last year (2020) and I've been using it with playerctl
to great success, but the interface does not support the "Position" property, apparently.
ERROR:__main__:Unknown DBusError encountered during tick
Traceback (most recent call last):
File "/home/fichte/code/discordrp-mpris/discordrp_mpris/__main__.py", line 71, in run
await self.tick()
File "/home/fichte/code/discordrp-mpris/discordrp_mpris/__main__.py", line 105, in tick
await asyncio.gather(
File "/usr/lib/python3.9/site-packages/ravel.py", line 2951, in get_prop
reply.expect_return_objects("v")[0][1]
File "/usr/lib/python3.9/site-packages/dbussy.py", line 4383, in expect_return_objects
raise DBusError(self.error_name, self.expect_objects("s")[0])
dbussy.DBusError: org.freedesktop.DBus.Error.NotSupported -- /org/mpris/MediaPlayer2.org.mpris.MediaPlayer2.Player Position is not supported
No idea about Chrome since I haven't tested it, but it seems that discord itself offers a player under a 'chromium' suffied bus that defines /org/mpris/MediaPlayer2
but no interfaces (using QDBusViewer). This will need some investigation.
Upon trying to add a configuration for Firefox, I either get an error or no results. This is what I've tried:
[player.Firefox]
[player.Mozilla Firefox] (this throws an error)
[player.MozillaFirefox]
[player.Mozilla-Firefox]
[player.Mozilla_Firefox]
It isn't an issue with my configuration file itself either, as I can add configurations for the global scope and the Strawberry media player.
Might do something with this later.
What is Says on the Tin. I use Pithos (https://github.com/pithos/pithos) To play Pandora on my PC. It's a rather nice little client for it.
Anyways they have an exposed mpris interface and it does work with this little tool. I was hoping have it added to the list of known to work apps and maybe get it's icon added to the list of stuff with icons.
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 287, in main
return loop.run_until_complete(main_task)
File "/usr/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
return future.result()
File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 280, in main_async
return await instance.run()
File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 67, in run
await self.connect_discord()
File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 56, in connect_discord
await self.discord.connect()
File "/usr/lib/python3.10/site-packages/discord_rpc/async_.py", line 63, in connect
await self._connect()
File "/usr/lib/python3.10/site-packages/discord_rpc/async_.py", line 216, in _connect
await asyncio.open_unix_connection(path, loop=self.loop)
File "/usr/lib/python3.10/asyncio/streams.py", line 97, in open_unix_connection
transport, _ = await loop.create_unix_connection(
TypeError: _UnixSelectorEventLoop.create_unix_connection() got an unexpected keyword argument 'loop'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/discordrp-mpris", line 33, in <module>
sys.exit(load_entry_point('discordrp-mpris==0.3.0', 'console_scripts', 'discordrp-mpris')())
File "/usr/lib/python3.10/site-packages/discordrp_mpris/__main__.py", line 290, in main
wait_task = asyncio.wait_for(main_task, 5, loop=loop)
TypeError: wait_for() got an unexpected keyword argument 'loop'
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'
It seems to be impossible to configure players that have a space in their name since toml doesn't allow spaces in kay names. Or am I just missing something. If there is a way then documenting it would be a good idea
As title
I have been picking through the source code, and have located the definitions for everything but the status title itself ("Media (mpris2)"). I was wondering where/how to change this, specifically to say the player name instead.
The dbus protocol provides an observable property change event that we can monitor in case anything in the player (besides playback position) changes. trackma uses this.
We would still provide the poll-based version as a fallback for players that don't properly implement it (and especially considering how it's already implemented), but well-behaving citizens use events where they can.
I don't know how well this works with dbussy's async backend, but I prefer to keep using it.
Instead of showing the player icon, show the embedded album art instead of the default icon. Looks like we can use the Metadata property and get the album art uri and embed that.
So, I don't know if this could even be in your interests..
Still I found your service is like the only one on the whole internet that "takes a standard agnostic format" and converts it to DRPC (rather than just directly hooking into programs and sending it directly to it).
And I was wondering if your fine work couldn't be made a bit more general-purpose (or something at least enough for games I guess).
Unfortunately there isn't really an xdg specification specific to this, still d-bus is extensible enough that I'd hope it shouldn't be too hard to design a simple custom api.
I tried SMPlayer just now and turned out its reported "length" value was a float instead of an int, so it would crash due to this line expecting int but got float.
Here's a nice svg if you want to add the icon: https://en.wikipedia.org/wiki/File:SMPlayer_icon.svg.
* Odd things happened to my mpc-qt installation, which I could not figure out how to solve, so I switched to SMPlayer.
When using GSConnect it is possible to sync what's currently playing on an android phone to mpris. When using the the YouTube Music app on the phone to play music the player name that shows up is YouTube Music
. This would work for other android music players as well. The name on dbus is org.mpris.MediaPlayer2.GSConnect.Pixel7ProYouTubeMusic
in my example.
Hi there, thanks for the great job.
It's been working pretty well with mpv and others, but I'm having some issues with mpc-qt.
First, on any tracks, their "artist" will always be a string instead of a list of strings. So the current code will end up joining every character of the string with &
(e.i. Jack
becomes J & a & c & k
). Adding a little patch, where it will add the value into a list IF its type is a string, fixed the issue for me (on a side note I'm not too familiar with Python so please excuse me if my phrasing sound odd or something).
Second, mpc-qt seem to update its mpris thingy every second even if it's still playing the same track, so the elapsed time status in Discord will always reset back to 00.00 after a few seconds.
I noticed the same behavior with other project (not mine) that would also monitor mpris. Basically it would report that mpc-qt would keep on updating its track position every second, but it wouldn't report anything like that for any other players (including mpv) even when I tried to manually seek other position. Then again I don't really understand this whole mpris thingy either.
I cannot find the config file on Arch (installed via aur). Can you help me?
Do I need to manually create?
Thanks in advance.
Cannot connect to discord after last update.
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-2' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-3' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-4' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-5' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-6' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-7' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-8' not found
DEBUG:discord_rpc.async_:'/run/user/1000/discord-ipc-9' not found
DEBUG:discordrp_mpris.__main__:Failed to connect to Discord client
DEBUG:discordrp_mpris.config:Value for 'global.reconnect_wait': 1
INFO:discordrp_mpris.__main__:Connection to Discord client lost. Reconnecting...
WARNING:asyncio:socket.send() raised exception.
WARNING:asyncio:socket.send() raised exception.
INFO:discordrp_mpris.__main__:Connection to Discord client lost. Reconnecting...
WARNING:asyncio:socket.send() raised exception.
WARNING:asyncio:socket.send() raised exception.
INFO:discordrp_mpris.__main__:Connection to Discord client lost. Reconnecting...
WARNING:asyncio:socket.send() raised exception.
WARNING:asyncio:socket.send() raised exception.
INFO:discordrp_mpris.__main__:Connection to Discord client lost. Reconnecting...
WARNING:asyncio:socket.send() raised exception.
WARNING:asyncio:socket.send() raised exception.
Discord is running fine in the meantime. I am using Ubuntu 18.04.3 LTS
If the title length of a song or movie is too long, then nothing is shown. Essentially it fails with error and outputs nothing. Instead, it should give the user an option to truncate a long title to the maximum length of characters and show that, I think thats better than showing nothing.
ERROR:discordrp_mpris.__main__:Error setting activity: child "activity" fails because [child "details" fails because ["details" length must be less than or equal to 128 characters long]]
Hey there!
I think it may be useful if the README included instruction on how to make Discord connect to drp-mpris when Discord is installed through Flatpak.
Atrate
There is no configuration currently. Things to consider:
The Discord docs point towards their rich presence SDK being deprecated in favor of their GameSDK's ActivityManager. However, from a brief look that seems to rely on games being approved by staff, which is even paused at the moment. Since we're not wrapping a game here, I'd like to investigate what this change of suggestion means for this tool and whether something needs to be changed or whether this is just about the SDK and the underlying protocol remains unchanged.
So I'm using this from an AUR package on Arch Linux, with ArmCord flatpak and arRPC (but this also happened to me back when i was using the normal discord app from base repos). After some time and probably some resource usage, the script just starts doing... this.
I can CTRL-C out of the script (and it floods my terminal with asyncio errors if i do that), launch it again and keep going, but that needs manual intervention. Maybe there should be a way to auto-restart the script if this kind of thing happens? Like, the script does not stop on these exceptions, but it also does not function until a restart.
This is the commit the AUR package is based on.
In the readme, there is a manual installation option, but this link did not work:
https://github.com/FichteFoll/discordrp-mpris
but when i used the zip of the latest release:
https://github.com/FichteFoll/discordrp-mpris/archive/refs/tags/v0.3.2.zip
it worked as intended. I also wonder why systemctl --user enable discordrp-mpris.service --now
does not work when I do it that way. Right now i open a terminal to run the rich presence, but I would like it to be automatic. Should I set up a cron job to do it or is there a better way?
For a few months now, you have had the ability to set a custom status that can even override the title of a rich presence (such as what we use).
I want to investigate if it's possible to override this name from some API and make it configurable to the user (#5) what is displayed there, such as the currently playing song. Would also solve #3.
Now that we have a configuration framework (#2), custom formatting should be added.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.