Skip to main content

TUI MPRIS2 Control

Project description

pympristui (TUI MPRIS2 Control)

This is a tiny little Python script to act as a TUI (Terminal User Interface) to an MPRIS2-enabled media player. MPRIS is a D-Bus-based interface which many Linux-based media players support, which allows external applications to control some aspects of media playback. This is most often used to provide little audio applets for desktop environments, or to allow web-based control of a media player. This app is intended to provide some basic controls when (for instance) SSHed in to a machine that's running an MPRIS-compatible media player.

App Screenshot

This app has been tested in Python 3.9+, and requires:

It attempts to connect to the Audacious Media Player by default; to connect to another app instead, you'll have to specify a commandline arg.

Installation

I'd recommend using a virtual environment to run the app. Change to a directory where you want to store your venv, and create/activate it with:

$ python -m venv mpris2
$ . mpris2/bin/activate

You should have an (mpris2) prefix on your shell prompt to indicate the venv is active. Obviously feel free to name it whatever you like.

pip Installation

At this point, you can just install using:

$ pip install pympristui

A pympristui.py script should now be available on your $PATH.

Manual Installation

Otherwise, check out the project from git, or download and uncompress an archive from github. Then, switch over to this project's dir and install dependencies, either through:

$ pip install -r requirements.txt

or by hand:

$ pip install dbus-python mpris2 urwid

Then run it direct from the CLI (or copy the script anywhere you like):

$ ./pympristui.py

Usage

It's a very basic app. By default it tries to find an MPRIS interface for the media player Audacious. If that's not found (or if that's not what you want to use), you can use the -p/--program arg to specify another string to search for. The string matching here is extremely basic; it'll just pick the first advertised interface name which matches the string you specify. If the specified string isn't found (or if Audacious isn't running, when no -p has been specified), you'll get a list of all available MPRIS interfaces found on your system, on the commandline, with output like:

Available Player URIs:
 - org.mpris.MediaPlayer2.firefox.instance319681
 - org.mpris.MediaPlayer2.audacious

To use that -p/--program argument to connect to that Firefox instance, for instance:

$ ./pympristui.py -p firefox
$ ./pympristui.py --program firefox

Using instance319681 or even 319681 would also match that Firefox instance.

Once it's started, the app just provides the simple controls pause/play/stop, next/previous track, and seeking, along with the basic information about what's being played currently. It only accepts keyboard input, with the following keybinds:

  • space - play/pause
  • n - next track
  • p - previous track
  • < - Seek 10 seconds back
  • > - Seek 10 seconds forward
  • s - stop
  • q - quit

Note that the "quit" key only quits the control app itself; the actual app playing audio will continue to run as usual.

Limitations/TODO

  • I'd originally intended to provide support for MPRIS2's TrackList interface, but it turns out the Audacious doesn't provide that, so I didn't look into it any further. As such, control in the app is limited to play/pause/stop, next, and prev. There's no tracklist visibility, or ability to hop around with any control other than next/prev.
  • I didn't implement volume control.
  • The onscreen text just updates every second, so there'll often be a noticeable (though brief) lag between hitting a command and having the info update onscreen. The commands should be executed immediately, though.
  • This has only been tested against Audacious. If other MPRIS servers behave differently (like maybe not including a total track time or something), this might have problems.

License

All code in this project is licensed under the zlib/libpng license. A copy is provided in COPYING.txt.

Changelog

v1.0.6 - March 9, 2022

  • More user-friendly messages when no MPRIS players can be found
  • More user-friendly message when DBus error is encountered
  • Added -V/--version argument

v1.0.5 - June 15, 2021

  • Bah, one more case where missing MPRIS tags would crash the app

v1.0.4 - June 9, 2021

  • Fixed a couple more cases where missing MPRIS tags would crash the app

v1.0.3 - May 7, 2021

  • Fixed handling of cases where some tags (such as album) aren't present

v1.0.2 - March 3, 2021

  • Added forward/reverse seeking

v1.0.1 - February 26, 2021

  • Use blue coloration for Paused notification
  • Include version number in app header
  • Fix up --help output a bit

v1.0.0 - February 24, 2021

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pympristui-1.0.6.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

pympristui-1.0.6-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file pympristui-1.0.6.tar.gz.

File metadata

  • Download URL: pympristui-1.0.6.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2

File hashes

Hashes for pympristui-1.0.6.tar.gz
Algorithm Hash digest
SHA256 d688daae26b2106ebfc38426707d6c7b8c8142aab439da290e5bdca0108f111e
MD5 4c445c9ed0adfb2add708f3e67892cc6
BLAKE2b-256 39b843b08329366754bdf6ad11e7310ca94a8b017f8f10d1fff7329ab55335eb

See more details on using hashes here.

File details

Details for the file pympristui-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: pympristui-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.10.2

File hashes

Hashes for pympristui-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d03f5e3ae9be036ede2a6bcc504f5df8eca012ac74c745a3791df6e9df8854f9
MD5 a626240ba0e213ff7cbf4542324d4be1
BLAKE2b-256 f608ee3fad3b7066f342884e59d5b94064200b5c3e5c16b7b732101e900993ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page