Skip to content

Instantly share code, notes, and snippets.

@andete
Created October 19, 2014 12:01
Show Gist options
  • Save andete/d45b03ccadb4c16ed86e to your computer and use it in GitHub Desktop.
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
#!/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