A Python script that sets your Matrix presence and status based on native OS-level media sessions (MPRIS). It monitors what you are listening to or watching via D-Bus and instantly pushes it to your Matrix account.
- Linux OS with D-Bus and MPRIS support
playerctlinstalled (e.g.sudo apt install playerctlorsudo pacman -S playerctl)- Python 3.7+
- A Matrix account and homeserver
If you want to run this constantly in the background as a Linux service, independent of your cloned repository folder:
Clone the repository:
git clone https://github.com/user/matrix-premid cd matrix-premidConfigure your credentials locally (or edit later):
cp .env.example .env nano .env
(Note: If you populate the ``.env`` file locally before installing, the installer will automatically copy and use it for the background service.)
Install the script, systemd service, and dependencies globally to
/opt:make install
This creates the directory
/opt/matrix-premid, copies the script and.envthere, sets up an isolated Python virtual environment exclusively for the service, and symlinks the script to/usr/local/bin/matrix_premid. The systemd service is placed in/etc/systemd/system/.(Optional) Edit credentials after installation:
sudo nano /opt/matrix-premid/.env sudo systemctl restart matrix-premid.service
Start and enable the background service:
sudo systemctl daemon-reload sudo systemctl enable --now matrix-premid.service
If you want to run the script locally from the folder (for testing or development) without installing it system-wide:
Clone the repository and configure your environment:
git clone https://github.com/user/matrix-premid cd matrix-premid cp .env.example .envEdit the
.envfile and fill in your Matrix credentials. Make sure to export them to your shell (e.g., usingdirenv allowor sourcing the file) because the script reads directly fromos.environ.Install development dependencies:
make deps
Run the script directly:
make run
The script will listen to Linux MPRIS events natively. As long as the script is running, when you play media in a browser or application (like Spotify, VLC, Firefox), your standard Matrix presence and your custom Element status will be instantly updated. When media is stopped or paused, the status will return to Idle and clear the custom text.
You can format the code using Black:
make formatYou can lint the code using Flake8:
make lintTo clean up the virtual environment and cache files:
make clean