#!/usr/bin/env python3 # -*- coding: utf-8 -*- import logging import re import sys import subprocess LOG = logging.getLogger(__name__) # pip3 install spotify-cli-linux dbus-python def get_spotify_status(): artist_song = None status = None try: output = subprocess.check_output( "spotifycli --status 2> /dev/null", shell=True ) parse = re.findall(r"^(.*) - (.*)", output.decode('utf-8')) LOG.debug(parse) artist_song = parse[0] output = subprocess.check_output( "spotifycli --playbackstatus 2> /dev/null", shell=True ).decode('utf-8').strip() if output == u"▮▮": status = 'pause' elif output == u"▶": status = 'play' else: status = None except Exception as e: LOG.exception(e) LOG.info("Spotify is not running") return artist_song, status def read_line(): """ Interrupted respecting reader for stdin. """ # try reading a line, removing any extra whitespace try: line = sys.stdin.readline().strip() # i3status sends EOF, or an empty line if not line: sys.exit(3) return line # exit on ctrl-c except KeyboardInterrupt: sys.exit() def print_line(message): """ Non-buffered printing to stdout. """ sys.stdout.write(message + '\n') sys.stdout.flush() if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) spotify_status, status = get_spotify_status() LOG.debug("spotify: {}, status: {}".format(spotify_status, status)) if spotify_status: artist = spotify_status[0] song = spotify_status[1] color = '#9ec600' if status == 'pause': color = '#676767' # long # short # color print(' %s - %s' % (artist, song)) print(' %s - %s' % (artist, song)) print(color)