1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

#!/usr/bin/env python3
"""Control Clementine from the command line using dbus."""
import dbus
CLEM_NAME = "org.mpris.MediaPlayer2.clementine"
CLEM_PATH = "/org/mpris/MediaPlayer2"
CLEM_PLAYER_NAME = "org.mpris.MediaPlayer2.Player"
PROPS_NAME = "org.mpris.MediaPlayer2.Player"
def main():
bus = dbus.SessionBus()
hour, minutes, seconds = get_position(bus)
timestamp = f"{minutes:02}:{seconds:02}"
if hour:
timestamp = f"{hour}:{timestamp}"
print(timestamp)
def get_clementine_object(bus):
clem_object = bus.get_object(CLEM_NAME, CLEM_PATH)
return clem_object
def get_position(bus):
clem_object = get_clementine_object(bus)
position = clem_object.Get(CLEM_PLAYER_NAME, "Position")
timestamp_ns = int(position)
timestamp_sec = timestamp_ns // 1_000_000
timestamp_h = timestamp_sec // 3600
timestamp_min = (timestamp_sec // 60) % 60
timestamp_sec = timestamp_sec % 60
return (timestamp_h, timestamp_min, timestamp_sec)
if __name__ == "__main__":
main()