Skip to main content

MPRIS2 D-Bus for a (remote) Mopidy instance

Project description

mopidris

MPRIS2 D-Bus for a (remote) Mopidy instance.

Background

Many desktop environments can control a media player through the D-Bus via the Media Player Remote Interfacing Specification (MPRIS) interface. To control a locally running instance of Mopidy, there exists the Mopidy-MPRIS package:

For this to work, Mopidy has to run on the same computer as the the D-Bus. If Mopidy runs on a remote server, up to now there was only the following solution available:

  1. Install and enable the MPD interface for Mopidy:
  2. Install mpDris2.
  3. Start mpDris2, whenever you log into your desktop environment.

The mopidris introduced here, connects directly to a local or remote Mopidy without the detour through the mpd interface.

There is an additional (and probably controversial) feature implemented: Internet radio streams do often send artist and title as one metatag. If those two fields are separated by " - ", it is split and presented as artist and title to the D-Bus. (This is the default behaviour and can be switched off with the --no-mangle command line parameter.)

Installation

pip install mopidris

This installs these additional packages:

Optional packages

You can install the following optional packages. mopidris makes use of them, if it can find them, but it also works well without them:

  1. aiorun: If the event loop is terminated with CTRL-C, sometimes the port is not released and 'mopidris' cannot be restarted. 'aiorun' can help here (but it can still happen, that the DBUS hangs ...)
  2. colored_traceback: Shows coloured tracebacks, to help debugging exceptions.
  3. colorlog: Colour the log to make it easier to read.

Usage

Command line

The program is started with

python3 /path/to/mopidris

e.g. if mopidris is installed into the directory /usr/local/lib/python3.8/dist-packages/mopidris/, call it with

python3 /usr/local/lib/python3.8/dist-packages/mopidris

The most important options are undeniably the (optional) positional parameter specifying the host and possibly --retries and --can-quit. For the full list, see the section "Command line options" near the end.

Configuration file

Instead of giving the parameters all the time when calling mopidris, it is possible to write them into a configuration file. The default location can be found by calling python3 mopidris --help (look for the --config option).

A possible configuration file can look like this:

# Remote host ip
host = 192.168.0.1

# Retry forever
reconnect_attempts = -1

# Wait 60s between retries
reconnect_timeout = 60

.desktop file

If this mopidy.desktop is installed (e.g. into /usr/local/share/applications or to ${HOME}/.local/share/applications, it is probably possible to start mopidris on a Linux system from the sound applet. For this to work, the file has to be named mopidris.desktop and the program at least started once manually!

Do not forget to update the path in the file to your installation directory!

Start automatically

There exists two possible ways to start mopidris automatically, whenever a user logs in:

Startup Applications

Put python3 /path/to/mopidris with the required command line options (or a configuration file) into your Startup Applications.

If you have installed the mopidy.desktop file as described above, this file can be used in the Startup Applications.

systemd service

NB: This is not tested, so please feel free to open an issue and post a correction to the procedure!

It is also possible to start it via a systemd service.

Copy the mopidris.service file to /usr/lib/systemd/user (or the user's equivalent) and activate it with:

systemctl --user enable mopidris.service
systemctl --user start mopidris.service

Command line options

To see the command line options, call

python3 mopidris --help
usage: mopidris [-h] [-p PORT] [-r ATTEMPTS] [-t TIMEOUT] [-q] [-m] [-c FILE]
                [-i {tracklist,playlists}]
                [-d {debug,info,warning,error,critical}]
                [--debug-mopidy {debug,info,warning,error,critical}]
                [--debug-dbus {debug,info,warning,error,critical}]
                [--debug-websockets {debug,info,warning,error,critical}]
                [--debug-aiorun {debug,info,warning,error,critical}]
                [--debug-interfaces.base {debug,info,warning,error,critical}]
                [--debug-interfaces.root {debug,info,warning,error,critical}]
                [--debug-interfaces.player {debug,info,warning,error,critical}]
                [--debug-interfaces.tracklist {debug,info,warning,error,critical}]
                [--debug-interfaces.playlist {debug,info,warning,error,critical}]
                [HOST]

Connect a (remote) Mopidy instance to the local DBus.

positional arguments:
  HOST                  the remote host name or ip address
                        (default: localhost,
                         configfile key: host)

optional arguments:
  -h, --help            show this help message and exit
  -p PORT, --port PORT  the port number Mopidy is listening on
                        (default: 6680,
                         configfile key: port)
  -r ATTEMPTS, --retries ATTEMPTS
                        how often to retry to connect to Mopidy; if -1, retry
                        forever
                        (default: 5,
                         configfile key: reconnect_attempts)
  -t TIMEOUT, --timeout TIMEOUT
                        how long to wait between reconnection attempts
                        (default: 20,
                         configfile key: reconnect_timeout)
  -q, --can-quit        it is possible to quit this program from an
                        application; note, that the (remote) will keep running
                        (default: False,
                         configfile key: can_quit)
  -m, --no-mangle       do not split the Internet radio stream title at " - "
                        (default: True,
                         configfile key: mangle)
  -c FILE, --config FILE
                        read values from the configuration file
                        (default: <operating system dependend>,
                         a configfile key is not supported)

DBus Interfaces:
  -i {tracklist,playlists}, --interface {tracklist,playlists}
                        activate additional 'org.mpris.MediaPlayer2' DBus
                        interfaces (the 'org.mpris.MediaPlayer2' and
                        'org.mpris.MediaPlayer2.Player' interfaces are always
                        active)
                        (configfile key: interfaces - use one line for each
                        interface)

Debugging:
  -d {debug,info,warning,error,critical}, --debug {debug,info,warning,error,critical}
                        the general loglevel
                        (default: warning,
                         configfile key: debug)
  --debug-mopidy {debug,info,warning,error,critical}
                        the loglevel for the 'mopidy_asyncio_client' module
                        (default: follows --debug argument,
                         configfile key: debug_mopidy_asyncio_client)
  --debug-dbus {debug,info,warning,error,critical}
                        the loglevel for the 'dbus_next' module
                        (default: follows --debug argument,
                         configfile key: debug_dbus_next)
  --debug-websockets {debug,info,warning,error,critical}
                        the loglevel for the 'websockets' module
                        (default: follows --debug argument,
                         configfile key: debug_websockets)
  --debug-aiorun {debug,info,warning,error,critical}
                        the loglevel for the 'aiorun' module
                        (default: follows --debug argument,
                         configfile key: debug_aiorun)
  --debug-interfaces.base {debug,info,warning,error,critical}
                        the loglevel for the 'interfaces.base' module
                        (default: follows --debug argument,
                         configfile key: debug_interfaces.base)
  --debug-interfaces.root {debug,info,warning,error,critical}
                        the loglevel for the 'interfaces.root' module
                        (default: follows --debug argument,
                         configfile key: debug_interfaces.root)
  --debug-interfaces.player {debug,info,warning,error,critical}
                        the loglevel for the 'interfaces.player' module
                        (default: follows --debug argument,
                         configfile key: debug_interfaces.player)
  --debug-interfaces.tracklist {debug,info,warning,error,critical}
                        the loglevel for the 'interfaces.tracklist' module
                        (default: follows --debug argument,
                         configfile key: debug_interfaces.tracklist)
  --debug-interfaces.playlist {debug,info,warning,error,critical}
                        the loglevel for the 'interfaces.playlist' module
                        (default: follows --debug argument,
                         configfile key: debug_interfaces.playlist)

Configuration file:
Each line in the configuration file is a 'key = value' pair. The key is given
in the description of each parameter and the value can be any valid value.
Comments start with '#' and everything after is discarded.

Copyright (C) 2021, licensed under GPL 3.0 or later.

Copyright of this file

Copyright (C) 2021 Stephan Helma

This file is part of mopidris.

mopidris is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

mopidris is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with mopidris. If not, see https://www.gnu.org/licenses/.

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

mopidris-0.9.1.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

mopidris-0.9.1-py3-none-any.whl (50.3 kB view details)

Uploaded Python 3

File details

Details for the file mopidris-0.9.1.tar.gz.

File metadata

  • Download URL: mopidris-0.9.1.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mopidris-0.9.1.tar.gz
Algorithm Hash digest
SHA256 574fa2bbf6ffac4c5325fbf5d6bce9fba680ebc2b755fb87bd9ee4338dd74316
MD5 7f24edbc8d6f20bff154e831affdfcf7
BLAKE2b-256 9447d66778f457512e37c5331e0bebfa4ce8b07e468e1ae048a7dc374cc50f3c

See more details on using hashes here.

File details

Details for the file mopidris-0.9.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for mopidris-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd7c79fd11bf1354707cf97a376d48508b8b454bf3bd9e72aa52c2e9a48faefb
MD5 8bfecffe92d42bf656043a8f657e13a5
BLAKE2b-256 173e59074a05780c1b9d4ba24fe4f5ddf1f2d9167a645474a17715b2a0662924

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