Last active
March 11, 2018 13:57
-
-
Save nsbgn/c8ca2c9ed08dfc6740aa4b165a6ccef6 to your computer and use it in GitHub Desktop.
Revisions
-
slakkenhuis revised this gist
Mar 11, 2018 . No changes.There are no files selected for viewing
-
slakkenhuis created this gist
Mar 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/usr/bin/env python3 # This script continuously outputs the currently playing song and play status. # For use with i3blocks, polybar, yabar etc; to avoid polling # Note that there is an MPRIS plugin to control and monitor MPV through # DBUS, at https://github.com/hoyon/mpv-mpris # See also: # https://github.com/mariusor/mpris-ctl # https://github.com/acrisci/playerctl import sys import gi gi.require_version("Playerctl","1.0") from gi.repository import Playerctl, GLib player = Playerctl.Player(player_name="mpv") def update(player, e=None): m = dict(**player.props.metadata) print("{icon} {title} ({artist} - {album})".format( icon = "" if player.props.status == "Playing" else "" , artist = " and ".join(m.get("xesam:artist", [])) , album = m.get("xesam:album", "Unknown") , title = m.get("xesam:title", "Unknown") ) ) sys.stdout.flush() player.on("play", update) player.on("pause", update) player.on("metadata", update) main = GLib.MainLoop() main.run()