Created
October 19, 2014 12:01
-
-
Save andete/d45b03ccadb4c16ed86e to your computer and use it in GitHub Desktop.
checks current playing song on mpd server with mpc client and displays it on minishift
This file contains 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 characters
#!/usr/bin/env python | |
import subprocess, time, requests, sys | |
last_line = "" | |
while True: | |
try: | |
lines = subprocess.check_output(["mpc", "current", "-f", "%artist%_%album%_%title%"]) | |
artist = "" | |
song = "" | |
album = "" | |
splits = lines.split('_') | |
artist = splits[0].strip() | |
song = splits[1].strip() | |
song = splits[2].strip() | |
#print "|%s|%s|%s|" % (artist, album, song) | |
if artist == '' and album == '': | |
line2 = song.split('-', 1) | |
artist = line2[0].strip() | |
song = line2[1].strip() | |
if artist == '': | |
line = "%s - %s " % (album, song) | |
elif album == '': | |
line = "%s - %s " % (artist, song) | |
else: | |
line = "%s - %s - %s " % (artist, album, song) | |
if line != last_line: | |
print line | |
subprocess.call(['curl', '-G', 'http://doriath:8000/set', '--data-urlencode', 'text=%s ' % (line), '-d', 'interval=0.0005', '-d', 'times=0']) | |
last_line = line | |
except subprocess.CalledProcessError: | |
pass | |
except IndexError: | |
pass | |
time.sleep(1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment