Skip to content

Instantly share code, notes, and snippets.

@andete
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andete/11031782 to your computer and use it in GitHub Desktop.
Save andete/11031782 to your computer and use it in GitHub Desktop.
show current playing media server song on the minishift display array
#!/usr/bin/env python
import subprocess, time, requests
last_line = ""
while True:
try:
lines = subprocess.check_output(["mocp", "-i"])
lines2 = lines.split('\n')
artist = ""
song = ""
album = ""
for line in lines2:
if line.startswith('Artist: '):
artist = line.split(' ',1)[1].strip()
if line.startswith('Album: '):
album = line.split(' ',1)[1].strip()
if line.startswith('SongTitle: '):
song = line.split(' ',1)[1].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