From e5a2527f813b242fad35e168ed2d686a6117967f Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Wed, 23 Nov 2022 17:55:35 +0100 Subject: [PATCH] [Newm] New method for displaying currently playing media --- .config/newm/config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.config/newm/config.py b/.config/newm/config.py index c53e465..eafaf0a 100644 --- a/.config/newm/config.py +++ b/.config/newm/config.py @@ -279,6 +279,21 @@ def get_bluetooth_devices() -> str: return f" {counter}" +def get_currently_playing(): + bus = dbus.SessionBus() + service_name = "org.mpris.MediaPlayer2.playerctld" + service_props = "org.mpris.MediaPlayer2.Player" + proxy = bus.get_object(service_name, "/org/mpris/MediaPlayer2") + props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties") + metadata = props.Get(service_props, "Metadata") + status = str(props.Get(service_props, "PlaybackStatus")) + if status != "Playing": + return "" + artist = ", ".join(metadata.get("xesam:artist")) + title = metadata.get("xesam:title") + return f" {artist} — {title}" + + def display_docker() -> str: containers = docker_client.containers.list(sparse=True) return f" {len(containers)}"