Skip to content

Instantly share code, notes, and snippets.

Created December 25, 2015 03:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Grabs your current track metadata from your MPRIS-enabled media player on Linux and zephyrs it in sipbmp3 format.
#!/usr/bin/env python3
import dbus
import sys
from zwrite import zwrite
# You can find at
import platform, getpass
BUS_PREFIX = "org.mpris.MediaPlayer2"
OBJECT_PATH = "/org/mpris/MediaPlayer2"
DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"
PLAYERS = {"spotify", "vlc", "clementine"}
ZWRITE_DEFAULTS = {"classname": "abcdefgh", # PLEASE SET YOUR CLASS NAME
"instance": "music",
"opcode": "auto",
"unauth": True}
{user} is playing:
USER = "@".join((getpass.getuser(), platform.node()))
def get_player_proxy(player_name, session_bus = dbus.SessionBus()):
return session_bus.get_object(".".join((BUS_PREFIX, player_name)), OBJECT_PATH)
def get_properties_interface(player_proxy):
return dbus.Interface(player_proxy, dbus_interface=DBUS_PROPERTIES)
def get_metadata(properties_interface):
return properties_interface.Get(PLAYER_INTERFACE, "Metadata")
def strip_key_colon(dictionary):
return {k.replace(":", ""): v for k, v in dictionary.items()}
def zwrite_metadata(metadata):
return zwrite(ZWRITE_TEMPLATE.format(user=USER, **metadata), zsig=metadata["xesamurl"], **ZWRITE_DEFAULTS)
def main(interface):
metadata = get_metadata(interface)
metadata["xesam:artist"] = ", ".join(metadata["xesam:artist"])
if metadata["mpris:trackid"]:
if __name__ == "__main__":
if len(sys.argv) > 1:
if sys.argv[1] in PLAYERS:
player = sys.argv[1]
print("Player not currently supported.")
player = "spotify"
proxy = get_player_proxy(player)
interface = get_properties_interface(proxy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment