Skip to main content

A persistent i3blocks blocklet for the MPRIS D-Bus interface

Project description

i3blocks-mpris

A persistent i3blocks blocklet for the MPRIS D-Bus interface.

screenshot

Click the image above to watch a screencast.

This project was previously known as i3blocks-spotify-persist.

Features

  • near-immediate updates thanks to the event-driven model: the blocket is a constantly running process receiving D-Bus signals
  • configurable output
  • configurable mouse click actions (i3blocks version 1.5 or later is required)

Installation

Python version 3.6 or later is required.

The blocket can be installed from PyPI using pip:

python3 -m pip install [--user] i3blocks-mpris

Once the package is installed, there will be a blocket script named i3blocks-mpris somewhere depending on the presence of a --user pip flag (e.g., /usr/local/bin/i3blocks-mpris or ~/.local/bin/i3blocks-mpris).

To avoid dependecy hell, pipx can be used:

pipx install i3blocks-mpris

In this case the blocket script will be placed in ~/.local/bin directory.

Dependencies

Required (installed automatically):

Optional (installed manually):

Usage

Add the following lines to your i3blocks config:

[mpris]
command=/path/to/bin/i3blocks-mpris -c /path/to/config.json
interval=persist

Configuration

The blocket can be configured using a JSON config file and/or command line arguments. The only required parameter is player. It must be specified using either the config or the command line argument. Other config parameters and the config itself are optional.

Config parameters

player

Type: string

Default value: no default value, must be specified

A name of the player, either a full bus name — org.mpris.MediaPlayer2.<player>[.<instance>] — or its <player>[.<instance>] part.

Examples:

  • org.mpris.MediaPlayer2.spotify
  • org.mpris.MediaPlayer2.vlc.instance7389
  • spotify
  • vlc.instance7389

format

Type: string

Default value: {status}: {artist} – {title}

A template string with placeholders. Placeholder formats are {field} and {field:filter}.

Supported fields:

  • status, one of enum values: Playing, Paused, Stopped
  • artist
  • title

Supported fitlers:

  • upper — converts a string to uppercase
  • lower — converts a string to lowercase
  • capitalize — converts the first character of a string to uppercase and the rest to lowercase
  • icon — for status field only: converts a textual status to an icon (see the status_icons option below)

markup_escape

Type: boolean

Default value: false

This option specifies whether to escape special characters (such as <, >, &) using corresponding XML entities. Set to true if Pango markup is used (markup=pango in your i3blocks config), false otherwise.

status_icons

Type: object

Default value: {"Playing": "\uf04b", "Paused": "\uf04c", "Stopped": "\uf04d"}

This option provides a mapping for the icon filter (see above). The default value uses icons from Font Awesome.

mouse_buttons

Type: object

Default value: {"1": "PlayPause"}

This option provides a mapping of X11 mouse buttons numbers to MPRIS methods. You can use the xev program to determine button numbers.

dedupe

Type: boolean

Default value: true

For some reason, the Spotify app emits several identical signals for one action/event (e.g., it produces four PropertiesChanged signals when a track is played or paused). If this option is set true, the blocklet will compare the updated message with the previous one and print it only if it has changed. There is no reason to turn off deduplication except for debugging.

Config example

{
    "player": "spotify",
    "format": "<span font_family='monospace' color='#ffa651' weight='bold'>{status:icon} {status:upper}</span> <span color='#72bf44' weight='bold'>{artist}</span><span color='#ffa651'>᛫</span><span color='#b2d235'>{title}</span>",
    "markup_escape": true,
    "status_icons": {
        "Playing": "|>",
        "Paused": "||",
        "Stopped": "[]"
    },
    "mouse_buttons": {
        "1": "PlayPause",
        "9": "Previous",
        "8": "Next"
    }
}

Command line arguments

  • -h, --help — show all command line arguments and exit
  • -c, --config — a path to the config file (see above)

The following arguments override corresponding config options or defaults (that is, command line arguments have the highest precedence):

  • -p, --player
  • --format
  • --markup-escape / --no-markup-escape
  • --dedupe / --no-dedupe

Changelog

See CHANGELOG.md.

License

The MIT License.

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

i3blocks-mpris-2.0.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

i3blocks_mpris-2.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file i3blocks-mpris-2.0.0.tar.gz.

File metadata

  • Download URL: i3blocks-mpris-2.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for i3blocks-mpris-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fdeeeb45c83568a8460ab3ccc0db10ca7ad596a7fc160bb6f0694b99d667545a
MD5 a33f3648d90a79605c814c2f05373154
BLAKE2b-256 8759de02bd80d78003d7092fa5c54277a4220c47d30b77fb7aff55a951bdf250

See more details on using hashes here.

File details

Details for the file i3blocks_mpris-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: i3blocks_mpris-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for i3blocks_mpris-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa0d5f1bb9b30c4f9963e7a2248f04e70387f44b970141e3ccf7b5b1d487e3a4
MD5 f9853eb742c96208d2cb1ce8265e7125
BLAKE2b-256 8e0552960a728bc32955aca6f1705b85cf49728c82792c5689c85552ad4a5400

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