Files
playerctl/example.py
Tony Crisci bf5db994b5 Add methods to print metadata
Adds methods to the player to easily print artist, title, album, and
arbitrary properties of the metadata object.
2014-04-18 20:05:30 -04:00

31 lines
730 B
Python
Executable File

#!/usr/bin/env python3
from gi.repository import Playerctl, GLib
player = Playerctl.Player()
def on_metadata(player, e):
if 'xesam:artist' in e.keys() and 'xesam:title' in e.keys():
print('Now playing:')
print('{artist} - {title}'.format(artist=e['xesam:artist'][0], title=e['xesam:title']))
def on_play(player):
print('Playing at volume {}'.format(player.props.volume))
def on_pause(player):
print('Paused the song: {}'.format(player.get_title()))
player.on('play', on_play)
player.on('pause', on_pause)
player.on('metadata', on_metadata)
# start playing some music
player.play()
if player.get_artist() == 'Lana Del Rey':
player.next()
# wait for events
main = GLib.MainLoop()
main.run()