Last active
August 29, 2015 14:00
-
-
Save andete/11031782 to your computer and use it in GitHub Desktop.
show current playing media server song on the minishift display array
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 | |
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