From 463609a9784c134fafdb8dd6db8324bd6ec44981 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 11 Sep 2019 20:17:33 +0200 Subject: [PATCH] Port mpd status from mpc CLI to dbus using mpd-mpris Signed-off-by: Knut Ahlers --- .config/i3blocks/config | 2 +- .config/i3blocks/mpc | 71 ----------------------------------------- 2 files changed, 1 insertion(+), 72 deletions(-) delete mode 100755 .config/i3blocks/mpc diff --git a/.config/i3blocks/config b/.config/i3blocks/config index 9c5072f..8d4cd15 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -29,7 +29,7 @@ separator_block_width=15 markup=pango -[mpc] +[mpd] interval=5 [spotify] diff --git a/.config/i3blocks/mpc b/.config/i3blocks/mpc deleted file mode 100755 index 91d9be7..0000000 --- a/.config/i3blocks/mpc +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 - -import dbus - -from block import * - -ICON = "\uf001" - - -class MPD(Block): - def __init__(self, icon=None, icon_color=None): - super().__init__(icon, icon_color) - - self.bus = dbus.SessionBus() - mpd_obj = self.bus.get_object( - "org.mpris.MediaPlayer2.mpd", - "/org/mpris/MediaPlayer2", - ) - self.mpd_props = dbus.Interface( - mpd_obj, - 'org.freedesktop.DBus.Properties', - ) - self.mpd_player = dbus.Interface( - mpd_obj, - 'org.mpris.MediaPlayer2.Player', - ) - - def execute(self): - if self.button_is(BTN_LEFT): - self.mpd_player.PlayPause() - pass - - if not self.is_playing(): - self.set_icon_color(COLOR_SECONDARY) - return "" - - return self.get_artist_title() - - def is_playing(self): - status = self.mpd_props.Get( - 'org.mpris.MediaPlayer2.Player', - 'PlaybackStatus', - ) - - return status == 'Playing' - - def get_artist_title(self): - meta = self.mpd_props.Get( - 'org.mpris.MediaPlayer2.Player', - 'Metadata', - ) - - if meta.get('xesam:artist')[0] == 'unknown artist' and ' - ' in meta.get('xesam:title'): - return self.safe_text(meta.get('xesam:title')) - - return self.safe_text("{} - {}".format( - meta.get('xesam:artist')[0], - meta.get('xesam:title'), - )) - - -def main(): - try: - block = MPD(ICON) - block.render() - except: - pass - - -if __name__ == '__main__': - main()